diff --git a/packages/google-cloud-sql/.eslintignore b/packages/google-cloud-sql/.eslintignore new file mode 100644 index 000000000000..cfc348ec4d11 --- /dev/null +++ b/packages/google-cloud-sql/.eslintignore @@ -0,0 +1,7 @@ +**/node_modules +**/.coverage +build/ +docs/ +protos/ +system-test/ +samples/generated/ diff --git a/packages/google-cloud-sql/.eslintrc.json b/packages/google-cloud-sql/.eslintrc.json new file mode 100644 index 000000000000..3e8d97ccb390 --- /dev/null +++ b/packages/google-cloud-sql/.eslintrc.json @@ -0,0 +1,4 @@ +{ + "extends": "./node_modules/gts", + "root": true +} diff --git a/packages/google-cloud-sql/README.md b/packages/google-cloud-sql/README.md index 41814fd9b839..497b95b405f9 100644 --- a/packages/google-cloud-sql/README.md +++ b/packages/google-cloud-sql/README.md @@ -241,7 +241,7 @@ More Information: [Google Cloud Platform Launch Stages][launch_stages] ## Contributing -Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-sql/CONTRIBUTING.md). +Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/google-cloud-node/blob/main/CONTRIBUTING.md). Please note that this `README.md` and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) @@ -251,7 +251,7 @@ are generated from a central template. Apache Version 2.0 -See [LICENSE](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-sql/LICENSE) +See [LICENSE](https://github.com/googleapis/google-cloud-node/blob/main/LICENSE) [shell_img]: https://gstatic.com/cloudssh/images/open-btn.png [projects]: https://console.cloud.google.com/project diff --git a/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_instances.proto b/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_instances.proto index bd71bd065f22..b07e2fa0b118 100644 --- a/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_instances.proto +++ b/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_instances.proto @@ -481,7 +481,7 @@ message SqlInstancesCloneRequest { // not include the project ID. string instance = 1 [(google.api.field_behavior) = REQUIRED]; - // Required. Project ID of the source as well as the clone Cloud SQL instance. + // Required. Project ID of the source Cloud SQL instance. string project = 2 [(google.api.field_behavior) = REQUIRED]; InstancesCloneRequest body = 100 [(google.api.field_behavior) = REQUIRED]; @@ -1366,6 +1366,20 @@ message PointInTimeRestoreContext { // instance. This value cannot be the same as the preferred_zone field. optional string preferred_secondary_zone = 9 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Specifies the instance settings that will be overridden from the + // source instance. This field is only applicable for cross project PITRs. + DatabaseInstance target_instance_settings = 11 + [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Specifies the instance settings that will be cleared from the + // source instance. This field is only applicable for cross project PITRs. + repeated string target_instance_clear_settings_field_names = 12 + [(google.api.field_behavior) = OPTIONAL]; + + // Optional. The region of the target instance where the datasource will be + // restored. For example: "us-central1". + optional string region = 13 [(google.api.field_behavior) = OPTIONAL]; } // Binary log coordinates. @@ -2313,7 +2327,7 @@ message ExecuteSqlPayload { // Credentials for the database connection. oneof user_password { - // Optional. When set to true, the API caller identity associated with the + // Optional. When set to `true`, the API caller identity associated with the // request is used for database authentication. The API caller must be an // IAM user in the database. bool auto_iam_authn = 11 [(google.api.field_behavior) = OPTIONAL]; @@ -2510,4 +2524,7 @@ enum SqlSuspensionReason { // The KMS key used by the instance is either revoked or denied access to KMS_KEY_ISSUE = 5; + + // The project is suspended due to abuse detected by Ares. + PROJECT_ABUSE = 8; } diff --git a/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_resources.proto b/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_resources.proto index 78da0b646400..4f2fa0a5fc9e 100644 --- a/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_resources.proto +++ b/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_resources.proto @@ -929,6 +929,24 @@ message PscConfig { // authorized to connect via PSC interface. // format: projects/PROJECT/regions/REGION/networkAttachments/ID string network_attachment_uri = 4 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Indicates whether PSC DNS automation is enabled for this + // instance. When enabled, Cloud SQL provisions a universal DNS record across + // all networks configured with Private Service Connect (PSC) + // auto-connections. This will default to true for new instances when Private + // Service Connect is enabled. + optional bool psc_auto_dns_enabled = 5 + [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Indicates whether PSC write endpoint DNS automation is enabled + // for this instance. When enabled, Cloud SQL provisions a universal global + // DNS record across all networks configured with Private Service Connect + // (PSC) auto-connections that always points to the cluster primary instance. + // This feature is only supported for Enterprise Plus edition. + // This will default to true for new Enterprise Plus instances when + // `psc_auto_dns_enabled` is enabled. + optional bool psc_write_endpoint_dns_enabled = 6 + [(google.api.field_behavior) = OPTIONAL]; } // Settings for an automatically-setup Private Service Connect consumer endpoint @@ -937,7 +955,7 @@ message PscAutoConnectionConfig { // Optional. This is the project ID of consumer service project of this // consumer endpoint. // - // Optional. This is only applicable if consumer_network is a shared vpc + // This is only applicable if `consumer_network` is a shared VPC // network. string consumer_project = 1 [(google.api.field_behavior) = OPTIONAL]; @@ -1340,6 +1358,9 @@ message Operation { // Creates a Cloud SQL read pool instance. CREATE_READ_POOL = 53; + + // Pre-checks the major version upgrade operation. + PRE_CHECK_MAJOR_VERSION_UPGRADE = 54; } // The status of an operation. @@ -1769,6 +1790,11 @@ message Settings { optional ReadPoolAutoScaleConfig read_pool_auto_scale_config = 48 [(google.api.field_behavior) = OPTIONAL]; + // Optional. Whether the replica is in accelerated mode. This feature is in + // private preview and requires allowlisting to take effect. + google.protobuf.BoolValue accelerated_replica_mode = 49 + [(google.api.field_behavior) = OPTIONAL]; + // Optional. Cloud SQL for MySQL auto-upgrade configuration. When this // parameter is set to true, auto-upgrade is enabled for MySQL 8.0 minor // versions. The MySQL version must be 8.0.35 or higher. @@ -1789,31 +1815,32 @@ message Settings { [(google.api.field_behavior) = OPTIONAL]; } -// Performance Capture configuration. +// Performance capture configuration. message PerformanceCaptureConfig { - // Optional. Enable or disable the Performance Capture feature. + // Optional. Enables or disables the performance capture feature. optional bool enabled = 1 [(google.api.field_behavior) = OPTIONAL]; - // Optional. The time interval in seconds between any two probes. + // Optional. Specifies the interval in seconds between consecutive probes that + // check if any trigger condition thresholds have been reached. optional int32 probing_interval_seconds = 2 [(google.api.field_behavior) = OPTIONAL]; - // Optional. The minimum number of consecutive readings above threshold that - // triggers instance state capture. + // Optional. Specifies the minimum number of consecutive probe threshold that + // triggers performance capture. optional int32 probe_threshold = 3 [(google.api.field_behavior) = OPTIONAL]; - // Optional. The minimum number of server threads running to trigger the - // capture on primary. + // Optional. Specifies the minimum number of MySQL `Threads_running` to + // trigger the performance capture on the primary instance. optional int32 running_threads_threshold = 4 [(google.api.field_behavior) = OPTIONAL]; - // Optional. The minimum number of seconds replica must be lagging behind - // primary to trigger capture on replica. + // Optional. Specifies the minimum number of seconds replica must be lagging + // behind primary instance to trigger the performance capture on replica. optional int32 seconds_behind_source_threshold = 5 [(google.api.field_behavior) = OPTIONAL]; - // Optional. The amount of time in seconds that a transaction needs to have - // been open before the watcher starts recording it. + // Optional. Specifies the amount of time in seconds that a transaction needs + // to have been open before the watcher starts recording it. optional int32 transaction_duration_threshold = 8 [(google.api.field_behavior) = OPTIONAL]; } @@ -2167,6 +2194,9 @@ enum SqlDatabaseVersion { // The database version is PostgreSQL 18. POSTGRES_18 = 557; + // The database version is PostgreSQL 19. + POSTGRES_19 = 684; + // The database version is SQL Server 2019 Standard. SQLSERVER_2019_STANDARD = 26; @@ -2190,6 +2220,15 @@ enum SqlDatabaseVersion { // The database version is SQL Server 2022 Web. SQLSERVER_2022_WEB = 202; + + // The database version is SQL Server 2025 Standard. + SQLSERVER_2025_STANDARD = 549; + + // The database version is SQL Server 2025 Enterprise. + SQLSERVER_2025_ENTERPRISE = 550; + + // The database version is SQL Server 2025 Express. + SQLSERVER_2025_EXPRESS = 551; } // The pricing plan for this instance. diff --git a/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_users.proto b/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_users.proto index 6a4011084e19..b74de3516d5b 100644 --- a/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_users.proto +++ b/packages/google-cloud-sql/protos/google/cloud/sql/v1/cloud_sql_users.proto @@ -19,6 +19,7 @@ package google.cloud.sql.v1; import "google/api/annotations.proto"; import "google/api/client.proto"; import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; import "google/cloud/sql/v1/cloud_sql_resources.proto"; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; diff --git a/packages/google-cloud-sql/protos/protos.d.ts b/packages/google-cloud-sql/protos/protos.d.ts index 550fe4464ffc..fa584fd39e4e 100644 --- a/packages/google-cloud-sql/protos/protos.d.ts +++ b/packages/google-cloud-sql/protos/protos.d.ts @@ -4715,6 +4715,12 @@ export namespace google { /** PscConfig networkAttachmentUri */ networkAttachmentUri?: (string|null); + + /** PscConfig pscAutoDnsEnabled */ + pscAutoDnsEnabled?: (boolean|null); + + /** PscConfig pscWriteEndpointDnsEnabled */ + pscWriteEndpointDnsEnabled?: (boolean|null); } /** Represents a PscConfig. */ @@ -4738,6 +4744,12 @@ export namespace google { /** PscConfig networkAttachmentUri. */ public networkAttachmentUri: string; + /** PscConfig pscAutoDnsEnabled. */ + public pscAutoDnsEnabled?: (boolean|null); + + /** PscConfig pscWriteEndpointDnsEnabled. */ + public pscWriteEndpointDnsEnabled?: (boolean|null); + /** * Creates a new PscConfig instance using the specified properties. * @param [properties] Properties to set @@ -6250,7 +6262,8 @@ export namespace google { MANAGE_BACKUP = 50, ENHANCED_BACKUP = 51, REPAIR_READ_POOL = 52, - CREATE_READ_POOL = 53 + CREATE_READ_POOL = 53, + PRE_CHECK_MAJOR_VERSION_UPGRADE = 54 } /** SqlOperationStatus enum. */ @@ -6942,6 +6955,9 @@ export namespace google { /** Settings readPoolAutoScaleConfig */ readPoolAutoScaleConfig?: (google.cloud.sql.v1.IReadPoolAutoScaleConfig|null); + /** Settings acceleratedReplicaMode */ + acceleratedReplicaMode?: (google.protobuf.IBoolValue|null); + /** Settings autoUpgradeEnabled */ autoUpgradeEnabled?: (boolean|null); @@ -7087,6 +7103,9 @@ export namespace google { /** Settings readPoolAutoScaleConfig. */ public readPoolAutoScaleConfig?: (google.cloud.sql.v1.IReadPoolAutoScaleConfig|null); + /** Settings acceleratedReplicaMode. */ + public acceleratedReplicaMode?: (google.protobuf.IBoolValue|null); + /** Settings autoUpgradeEnabled. */ public autoUpgradeEnabled?: (boolean|null); @@ -8556,6 +8575,7 @@ export namespace google { POSTGRES_16 = 272, POSTGRES_17 = 408, POSTGRES_18 = 557, + POSTGRES_19 = 684, SQLSERVER_2019_STANDARD = 26, SQLSERVER_2019_ENTERPRISE = 27, SQLSERVER_2019_EXPRESS = 28, @@ -8563,7 +8583,10 @@ export namespace google { SQLSERVER_2022_STANDARD = 199, SQLSERVER_2022_ENTERPRISE = 200, SQLSERVER_2022_EXPRESS = 201, - SQLSERVER_2022_WEB = 202 + SQLSERVER_2022_WEB = 202, + SQLSERVER_2025_STANDARD = 549, + SQLSERVER_2025_ENTERPRISE = 550, + SQLSERVER_2025_EXPRESS = 551 } /** SqlPricingPlan enum. */ @@ -17756,6 +17779,15 @@ export namespace google { /** PointInTimeRestoreContext preferredSecondaryZone */ preferredSecondaryZone?: (string|null); + + /** PointInTimeRestoreContext targetInstanceSettings */ + targetInstanceSettings?: (google.cloud.sql.v1.IDatabaseInstance|null); + + /** PointInTimeRestoreContext targetInstanceClearSettingsFieldNames */ + targetInstanceClearSettingsFieldNames?: (string[]|null); + + /** PointInTimeRestoreContext region */ + region?: (string|null); } /** Represents a PointInTimeRestoreContext. */ @@ -17788,6 +17820,15 @@ export namespace google { /** PointInTimeRestoreContext preferredSecondaryZone. */ public preferredSecondaryZone?: (string|null); + /** PointInTimeRestoreContext targetInstanceSettings. */ + public targetInstanceSettings?: (google.cloud.sql.v1.IDatabaseInstance|null); + + /** PointInTimeRestoreContext targetInstanceClearSettingsFieldNames. */ + public targetInstanceClearSettingsFieldNames: string[]; + + /** PointInTimeRestoreContext region. */ + public region?: (string|null); + /** * Creates a new PointInTimeRestoreContext instance using the specified properties. * @param [properties] Properties to set @@ -22351,7 +22392,8 @@ export namespace google { BILLING_ISSUE = 2, LEGAL_ISSUE = 3, OPERATIONAL_ISSUE = 4, - KMS_KEY_ISSUE = 5 + KMS_KEY_ISSUE = 5, + PROJECT_ABUSE = 8 } /** Represents a SqlConnectService */ @@ -55223,6 +55265,9 @@ export namespace google { /** CommonLanguageSettings destinations */ destinations?: (google.api.ClientLibraryDestination[]|null); + + /** CommonLanguageSettings selectiveGapicGeneration */ + selectiveGapicGeneration?: (google.api.ISelectiveGapicGeneration|null); } /** Represents a CommonLanguageSettings. */ @@ -55240,6 +55285,9 @@ export namespace google { /** CommonLanguageSettings destinations. */ public destinations: google.api.ClientLibraryDestination[]; + /** CommonLanguageSettings selectiveGapicGeneration. */ + public selectiveGapicGeneration?: (google.api.ISelectiveGapicGeneration|null); + /** * Creates a new CommonLanguageSettings instance using the specified properties. * @param [properties] Properties to set @@ -55940,6 +55988,9 @@ export namespace google { /** PythonSettings common */ common?: (google.api.ICommonLanguageSettings|null); + + /** PythonSettings experimentalFeatures */ + experimentalFeatures?: (google.api.PythonSettings.IExperimentalFeatures|null); } /** Represents a PythonSettings. */ @@ -55954,6 +56005,9 @@ export namespace google { /** PythonSettings common. */ public common?: (google.api.ICommonLanguageSettings|null); + /** PythonSettings experimentalFeatures. */ + public experimentalFeatures?: (google.api.PythonSettings.IExperimentalFeatures|null); + /** * Creates a new PythonSettings instance using the specified properties. * @param [properties] Properties to set @@ -56032,6 +56086,118 @@ export namespace google { public static getTypeUrl(typeUrlPrefix?: string): string; } + namespace PythonSettings { + + /** Properties of an ExperimentalFeatures. */ + interface IExperimentalFeatures { + + /** ExperimentalFeatures restAsyncIoEnabled */ + restAsyncIoEnabled?: (boolean|null); + + /** ExperimentalFeatures protobufPythonicTypesEnabled */ + protobufPythonicTypesEnabled?: (boolean|null); + + /** ExperimentalFeatures unversionedPackageDisabled */ + unversionedPackageDisabled?: (boolean|null); + } + + /** Represents an ExperimentalFeatures. */ + class ExperimentalFeatures implements IExperimentalFeatures { + + /** + * Constructs a new ExperimentalFeatures. + * @param [properties] Properties to set + */ + constructor(properties?: google.api.PythonSettings.IExperimentalFeatures); + + /** ExperimentalFeatures restAsyncIoEnabled. */ + public restAsyncIoEnabled: boolean; + + /** ExperimentalFeatures protobufPythonicTypesEnabled. */ + public protobufPythonicTypesEnabled: boolean; + + /** ExperimentalFeatures unversionedPackageDisabled. */ + public unversionedPackageDisabled: boolean; + + /** + * Creates a new ExperimentalFeatures instance using the specified properties. + * @param [properties] Properties to set + * @returns ExperimentalFeatures instance + */ + public static create(properties?: google.api.PythonSettings.IExperimentalFeatures): google.api.PythonSettings.ExperimentalFeatures; + + /** + * Encodes the specified ExperimentalFeatures message. Does not implicitly {@link google.api.PythonSettings.ExperimentalFeatures.verify|verify} messages. + * @param message ExperimentalFeatures message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.api.PythonSettings.IExperimentalFeatures, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified ExperimentalFeatures message, length delimited. Does not implicitly {@link google.api.PythonSettings.ExperimentalFeatures.verify|verify} messages. + * @param message ExperimentalFeatures message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.api.PythonSettings.IExperimentalFeatures, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an ExperimentalFeatures message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns ExperimentalFeatures + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.api.PythonSettings.ExperimentalFeatures; + + /** + * Decodes an ExperimentalFeatures message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns ExperimentalFeatures + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.api.PythonSettings.ExperimentalFeatures; + + /** + * Verifies an ExperimentalFeatures message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates an ExperimentalFeatures message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns ExperimentalFeatures + */ + public static fromObject(object: { [k: string]: any }): google.api.PythonSettings.ExperimentalFeatures; + + /** + * Creates a plain object from an ExperimentalFeatures message. Also converts values to other types if specified. + * @param message ExperimentalFeatures + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.api.PythonSettings.ExperimentalFeatures, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ExperimentalFeatures to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for ExperimentalFeatures + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + } + /** Properties of a NodeSettings. */ interface INodeSettings { @@ -56358,6 +56524,9 @@ export namespace google { /** GoSettings common */ common?: (google.api.ICommonLanguageSettings|null); + + /** GoSettings renamedServices */ + renamedServices?: ({ [k: string]: string }|null); } /** Represents a GoSettings. */ @@ -56372,6 +56541,9 @@ export namespace google { /** GoSettings common. */ public common?: (google.api.ICommonLanguageSettings|null); + /** GoSettings renamedServices. */ + public renamedServices: { [k: string]: string }; + /** * Creates a new GoSettings instance using the specified properties. * @param [properties] Properties to set @@ -56696,6 +56868,109 @@ export namespace google { PACKAGE_MANAGER = 20 } + /** Properties of a SelectiveGapicGeneration. */ + interface ISelectiveGapicGeneration { + + /** SelectiveGapicGeneration methods */ + methods?: (string[]|null); + + /** SelectiveGapicGeneration generateOmittedAsInternal */ + generateOmittedAsInternal?: (boolean|null); + } + + /** Represents a SelectiveGapicGeneration. */ + class SelectiveGapicGeneration implements ISelectiveGapicGeneration { + + /** + * Constructs a new SelectiveGapicGeneration. + * @param [properties] Properties to set + */ + constructor(properties?: google.api.ISelectiveGapicGeneration); + + /** SelectiveGapicGeneration methods. */ + public methods: string[]; + + /** SelectiveGapicGeneration generateOmittedAsInternal. */ + public generateOmittedAsInternal: boolean; + + /** + * Creates a new SelectiveGapicGeneration instance using the specified properties. + * @param [properties] Properties to set + * @returns SelectiveGapicGeneration instance + */ + public static create(properties?: google.api.ISelectiveGapicGeneration): google.api.SelectiveGapicGeneration; + + /** + * Encodes the specified SelectiveGapicGeneration message. Does not implicitly {@link google.api.SelectiveGapicGeneration.verify|verify} messages. + * @param message SelectiveGapicGeneration message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.api.ISelectiveGapicGeneration, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified SelectiveGapicGeneration message, length delimited. Does not implicitly {@link google.api.SelectiveGapicGeneration.verify|verify} messages. + * @param message SelectiveGapicGeneration message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.api.ISelectiveGapicGeneration, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a SelectiveGapicGeneration message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns SelectiveGapicGeneration + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.api.SelectiveGapicGeneration; + + /** + * Decodes a SelectiveGapicGeneration message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns SelectiveGapicGeneration + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.api.SelectiveGapicGeneration; + + /** + * Verifies a SelectiveGapicGeneration message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a SelectiveGapicGeneration message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns SelectiveGapicGeneration + */ + public static fromObject(object: { [k: string]: any }): google.api.SelectiveGapicGeneration; + + /** + * Creates a plain object from a SelectiveGapicGeneration message. Also converts values to other types if specified. + * @param message SelectiveGapicGeneration + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.api.SelectiveGapicGeneration, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this SelectiveGapicGeneration to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for SelectiveGapicGeneration + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + /** LaunchStage enum. */ enum LaunchStage { LAUNCH_STAGE_UNSPECIFIED = 0, @@ -56978,6 +57253,9 @@ export namespace google { /** FieldInfo format */ format?: (google.api.FieldInfo.Format|keyof typeof google.api.FieldInfo.Format|null); + + /** FieldInfo referencedTypes */ + referencedTypes?: (google.api.ITypeReference[]|null); } /** Represents a FieldInfo. */ @@ -56992,6 +57270,9 @@ export namespace google { /** FieldInfo format. */ public format: (google.api.FieldInfo.Format|keyof typeof google.api.FieldInfo.Format); + /** FieldInfo referencedTypes. */ + public referencedTypes: google.api.ITypeReference[]; + /** * Creates a new FieldInfo instance using the specified properties. * @param [properties] Properties to set @@ -57081,6 +57362,103 @@ export namespace google { IPV4_OR_IPV6 = 4 } } + + /** Properties of a TypeReference. */ + interface ITypeReference { + + /** TypeReference typeName */ + typeName?: (string|null); + } + + /** Represents a TypeReference. */ + class TypeReference implements ITypeReference { + + /** + * Constructs a new TypeReference. + * @param [properties] Properties to set + */ + constructor(properties?: google.api.ITypeReference); + + /** TypeReference typeName. */ + public typeName: string; + + /** + * Creates a new TypeReference instance using the specified properties. + * @param [properties] Properties to set + * @returns TypeReference instance + */ + public static create(properties?: google.api.ITypeReference): google.api.TypeReference; + + /** + * Encodes the specified TypeReference message. Does not implicitly {@link google.api.TypeReference.verify|verify} messages. + * @param message TypeReference message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.api.ITypeReference, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified TypeReference message, length delimited. Does not implicitly {@link google.api.TypeReference.verify|verify} messages. + * @param message TypeReference message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.api.ITypeReference, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a TypeReference message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns TypeReference + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.api.TypeReference; + + /** + * Decodes a TypeReference message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns TypeReference + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.api.TypeReference; + + /** + * Verifies a TypeReference message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a TypeReference message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns TypeReference + */ + public static fromObject(object: { [k: string]: any }): google.api.TypeReference; + + /** + * Creates a plain object from a TypeReference message. Also converts values to other types if specified. + * @param message TypeReference + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.api.TypeReference, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this TypeReference to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for TypeReference + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } } /** Namespace protobuf. */ @@ -57186,6 +57564,7 @@ export namespace google { /** Edition enum. */ enum Edition { EDITION_UNKNOWN = 0, + EDITION_LEGACY = 900, EDITION_PROTO2 = 998, EDITION_PROTO3 = 999, EDITION_2023 = 1000, @@ -57216,6 +57595,9 @@ export namespace google { /** FileDescriptorProto weakDependency */ weakDependency?: (number[]|null); + /** FileDescriptorProto optionDependency */ + optionDependency?: (string[]|null); + /** FileDescriptorProto messageType */ messageType?: (google.protobuf.IDescriptorProto[]|null); @@ -57265,6 +57647,9 @@ export namespace google { /** FileDescriptorProto weakDependency. */ public weakDependency: number[]; + /** FileDescriptorProto optionDependency. */ + public optionDependency: string[]; + /** FileDescriptorProto messageType. */ public messageType: google.protobuf.IDescriptorProto[]; @@ -57399,6 +57784,9 @@ export namespace google { /** DescriptorProto reservedName */ reservedName?: (string[]|null); + + /** DescriptorProto visibility */ + visibility?: (google.protobuf.SymbolVisibility|keyof typeof google.protobuf.SymbolVisibility|null); } /** Represents a DescriptorProto. */ @@ -57440,6 +57828,9 @@ export namespace google { /** DescriptorProto reservedName. */ public reservedName: string[]; + /** DescriptorProto visibility. */ + public visibility: (google.protobuf.SymbolVisibility|keyof typeof google.protobuf.SymbolVisibility); + /** * Creates a new DescriptorProto instance using the specified properties. * @param [properties] Properties to set @@ -58287,6 +58678,9 @@ export namespace google { /** EnumDescriptorProto reservedName */ reservedName?: (string[]|null); + + /** EnumDescriptorProto visibility */ + visibility?: (google.protobuf.SymbolVisibility|keyof typeof google.protobuf.SymbolVisibility|null); } /** Represents an EnumDescriptorProto. */ @@ -58313,6 +58707,9 @@ export namespace google { /** EnumDescriptorProto reservedName. */ public reservedName: string[]; + /** EnumDescriptorProto visibility. */ + public visibility: (google.protobuf.SymbolVisibility|keyof typeof google.protobuf.SymbolVisibility); + /** * Creates a new EnumDescriptorProto instance using the specified properties. * @param [properties] Properties to set @@ -59247,6 +59644,9 @@ export namespace google { /** FieldOptions features */ features?: (google.protobuf.IFeatureSet|null); + /** FieldOptions featureSupport */ + featureSupport?: (google.protobuf.FieldOptions.IFeatureSupport|null); + /** FieldOptions uninterpretedOption */ uninterpretedOption?: (google.protobuf.IUninterpretedOption[]|null); @@ -59305,6 +59705,9 @@ export namespace google { /** FieldOptions features. */ public features?: (google.protobuf.IFeatureSet|null); + /** FieldOptions featureSupport. */ + public featureSupport?: (google.protobuf.FieldOptions.IFeatureSupport|null); + /** FieldOptions uninterpretedOption. */ public uninterpretedOption: google.protobuf.IUninterpretedOption[]; @@ -59525,6 +59928,121 @@ export namespace google { */ public static getTypeUrl(typeUrlPrefix?: string): string; } + + /** Properties of a FeatureSupport. */ + interface IFeatureSupport { + + /** FeatureSupport editionIntroduced */ + editionIntroduced?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); + + /** FeatureSupport editionDeprecated */ + editionDeprecated?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); + + /** FeatureSupport deprecationWarning */ + deprecationWarning?: (string|null); + + /** FeatureSupport editionRemoved */ + editionRemoved?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); + } + + /** Represents a FeatureSupport. */ + class FeatureSupport implements IFeatureSupport { + + /** + * Constructs a new FeatureSupport. + * @param [properties] Properties to set + */ + constructor(properties?: google.protobuf.FieldOptions.IFeatureSupport); + + /** FeatureSupport editionIntroduced. */ + public editionIntroduced: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); + + /** FeatureSupport editionDeprecated. */ + public editionDeprecated: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); + + /** FeatureSupport deprecationWarning. */ + public deprecationWarning: string; + + /** FeatureSupport editionRemoved. */ + public editionRemoved: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); + + /** + * Creates a new FeatureSupport instance using the specified properties. + * @param [properties] Properties to set + * @returns FeatureSupport instance + */ + public static create(properties?: google.protobuf.FieldOptions.IFeatureSupport): google.protobuf.FieldOptions.FeatureSupport; + + /** + * Encodes the specified FeatureSupport message. Does not implicitly {@link google.protobuf.FieldOptions.FeatureSupport.verify|verify} messages. + * @param message FeatureSupport message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.protobuf.FieldOptions.IFeatureSupport, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified FeatureSupport message, length delimited. Does not implicitly {@link google.protobuf.FieldOptions.FeatureSupport.verify|verify} messages. + * @param message FeatureSupport message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.protobuf.FieldOptions.IFeatureSupport, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a FeatureSupport message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns FeatureSupport + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FieldOptions.FeatureSupport; + + /** + * Decodes a FeatureSupport message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns FeatureSupport + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.FieldOptions.FeatureSupport; + + /** + * Verifies a FeatureSupport message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a FeatureSupport message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FeatureSupport + */ + public static fromObject(object: { [k: string]: any }): google.protobuf.FieldOptions.FeatureSupport; + + /** + * Creates a plain object from a FeatureSupport message. Also converts values to other types if specified. + * @param message FeatureSupport + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.protobuf.FieldOptions.FeatureSupport, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FeatureSupport to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for FeatureSupport + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } } /** Properties of an OneofOptions. */ @@ -59763,6 +60281,9 @@ export namespace google { /** EnumValueOptions debugRedact */ debugRedact?: (boolean|null); + /** EnumValueOptions featureSupport */ + featureSupport?: (google.protobuf.FieldOptions.IFeatureSupport|null); + /** EnumValueOptions uninterpretedOption */ uninterpretedOption?: (google.protobuf.IUninterpretedOption[]|null); } @@ -59785,6 +60306,9 @@ export namespace google { /** EnumValueOptions debugRedact. */ public debugRedact: boolean; + /** EnumValueOptions featureSupport. */ + public featureSupport?: (google.protobuf.FieldOptions.IFeatureSupport|null); + /** EnumValueOptions uninterpretedOption. */ public uninterpretedOption: google.protobuf.IUninterpretedOption[]; @@ -60374,6 +60898,12 @@ export namespace google { /** FeatureSet jsonFormat */ jsonFormat?: (google.protobuf.FeatureSet.JsonFormat|keyof typeof google.protobuf.FeatureSet.JsonFormat|null); + + /** FeatureSet enforceNamingStyle */ + enforceNamingStyle?: (google.protobuf.FeatureSet.EnforceNamingStyle|keyof typeof google.protobuf.FeatureSet.EnforceNamingStyle|null); + + /** FeatureSet defaultSymbolVisibility */ + defaultSymbolVisibility?: (google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility|keyof typeof google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility|null); } /** Represents a FeatureSet. */ @@ -60403,6 +60933,12 @@ export namespace google { /** FeatureSet jsonFormat. */ public jsonFormat: (google.protobuf.FeatureSet.JsonFormat|keyof typeof google.protobuf.FeatureSet.JsonFormat); + /** FeatureSet enforceNamingStyle. */ + public enforceNamingStyle: (google.protobuf.FeatureSet.EnforceNamingStyle|keyof typeof google.protobuf.FeatureSet.EnforceNamingStyle); + + /** FeatureSet defaultSymbolVisibility. */ + public defaultSymbolVisibility: (google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility|keyof typeof google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility); + /** * Creates a new FeatureSet instance using the specified properties. * @param [properties] Properties to set @@ -60525,6 +61061,116 @@ export namespace google { ALLOW = 1, LEGACY_BEST_EFFORT = 2 } + + /** EnforceNamingStyle enum. */ + enum EnforceNamingStyle { + ENFORCE_NAMING_STYLE_UNKNOWN = 0, + STYLE2024 = 1, + STYLE_LEGACY = 2 + } + + /** Properties of a VisibilityFeature. */ + interface IVisibilityFeature { + } + + /** Represents a VisibilityFeature. */ + class VisibilityFeature implements IVisibilityFeature { + + /** + * Constructs a new VisibilityFeature. + * @param [properties] Properties to set + */ + constructor(properties?: google.protobuf.FeatureSet.IVisibilityFeature); + + /** + * Creates a new VisibilityFeature instance using the specified properties. + * @param [properties] Properties to set + * @returns VisibilityFeature instance + */ + public static create(properties?: google.protobuf.FeatureSet.IVisibilityFeature): google.protobuf.FeatureSet.VisibilityFeature; + + /** + * Encodes the specified VisibilityFeature message. Does not implicitly {@link google.protobuf.FeatureSet.VisibilityFeature.verify|verify} messages. + * @param message VisibilityFeature message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.protobuf.FeatureSet.IVisibilityFeature, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified VisibilityFeature message, length delimited. Does not implicitly {@link google.protobuf.FeatureSet.VisibilityFeature.verify|verify} messages. + * @param message VisibilityFeature message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.protobuf.FeatureSet.IVisibilityFeature, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a VisibilityFeature message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns VisibilityFeature + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FeatureSet.VisibilityFeature; + + /** + * Decodes a VisibilityFeature message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns VisibilityFeature + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.protobuf.FeatureSet.VisibilityFeature; + + /** + * Verifies a VisibilityFeature message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a VisibilityFeature message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns VisibilityFeature + */ + public static fromObject(object: { [k: string]: any }): google.protobuf.FeatureSet.VisibilityFeature; + + /** + * Creates a plain object from a VisibilityFeature message. Also converts values to other types if specified. + * @param message VisibilityFeature + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.protobuf.FeatureSet.VisibilityFeature, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this VisibilityFeature to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for VisibilityFeature + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace VisibilityFeature { + + /** DefaultSymbolVisibility enum. */ + enum DefaultSymbolVisibility { + DEFAULT_SYMBOL_VISIBILITY_UNKNOWN = 0, + EXPORT_ALL = 1, + EXPORT_TOP_LEVEL = 2, + LOCAL_ALL = 3, + STRICT = 4 + } + } } /** Properties of a FeatureSetDefaults. */ @@ -60644,8 +61290,11 @@ export namespace google { /** FeatureSetEditionDefault edition */ edition?: (google.protobuf.Edition|keyof typeof google.protobuf.Edition|null); - /** FeatureSetEditionDefault features */ - features?: (google.protobuf.IFeatureSet|null); + /** FeatureSetEditionDefault overridableFeatures */ + overridableFeatures?: (google.protobuf.IFeatureSet|null); + + /** FeatureSetEditionDefault fixedFeatures */ + fixedFeatures?: (google.protobuf.IFeatureSet|null); } /** Represents a FeatureSetEditionDefault. */ @@ -60660,8 +61309,11 @@ export namespace google { /** FeatureSetEditionDefault edition. */ public edition: (google.protobuf.Edition|keyof typeof google.protobuf.Edition); - /** FeatureSetEditionDefault features. */ - public features?: (google.protobuf.IFeatureSet|null); + /** FeatureSetEditionDefault overridableFeatures. */ + public overridableFeatures?: (google.protobuf.IFeatureSet|null); + + /** FeatureSetEditionDefault fixedFeatures. */ + public fixedFeatures?: (google.protobuf.IFeatureSet|null); /** * Creates a new FeatureSetEditionDefault instance using the specified properties. @@ -61194,6 +61846,13 @@ export namespace google { } } + /** SymbolVisibility enum. */ + enum SymbolVisibility { + VISIBILITY_UNSET = 0, + VISIBILITY_LOCAL = 1, + VISIBILITY_EXPORT = 2 + } + /** Properties of a Duration. */ interface IDuration { diff --git a/packages/google-cloud-sql/protos/protos.js b/packages/google-cloud-sql/protos/protos.js index e2514df66382..654b059265f6 100644 --- a/packages/google-cloud-sql/protos/protos.js +++ b/packages/google-cloud-sql/protos/protos.js @@ -1860,6 +1860,7 @@ case 272: case 408: case 557: + case 684: case 26: case 27: case 28: @@ -1868,6 +1869,9 @@ case 200: case 201: case 202: + case 549: + case 550: + case 551: break; } if (message.diskEncryptionConfiguration != null && message.hasOwnProperty("diskEncryptionConfiguration")) { @@ -2203,6 +2207,10 @@ case 557: message.databaseVersion = 557; break; + case "POSTGRES_19": + case 684: + message.databaseVersion = 684; + break; case "SQLSERVER_2019_STANDARD": case 26: message.databaseVersion = 26; @@ -2235,6 +2243,18 @@ case 202: message.databaseVersion = 202; break; + case "SQLSERVER_2025_STANDARD": + case 549: + message.databaseVersion = 549; + break; + case "SQLSERVER_2025_ENTERPRISE": + case 550: + message.databaseVersion = 550; + break; + case "SQLSERVER_2025_EXPRESS": + case 551: + message.databaseVersion = 551; + break; } if (object.diskEncryptionConfiguration != null) { if (typeof object.diskEncryptionConfiguration !== "object") @@ -4947,6 +4967,7 @@ case 272: case 408: case 557: + case 684: case 26: case 27: case 28: @@ -4955,6 +4976,9 @@ case 200: case 201: case 202: + case 549: + case 550: + case 551: break; } if (message.preCheckResponse != null && message.hasOwnProperty("preCheckResponse")) { @@ -5163,6 +5187,10 @@ case 557: message.targetDatabaseVersion = 557; break; + case "POSTGRES_19": + case 684: + message.targetDatabaseVersion = 684; + break; case "SQLSERVER_2019_STANDARD": case 26: message.targetDatabaseVersion = 26; @@ -5195,6 +5223,18 @@ case 202: message.targetDatabaseVersion = 202; break; + case "SQLSERVER_2025_STANDARD": + case 549: + message.targetDatabaseVersion = 549; + break; + case "SQLSERVER_2025_ENTERPRISE": + case 550: + message.targetDatabaseVersion = 550; + break; + case "SQLSERVER_2025_EXPRESS": + case 551: + message.targetDatabaseVersion = 551; + break; } if (object.preCheckResponse) { if (!Array.isArray(object.preCheckResponse)) @@ -12912,6 +12952,8 @@ * @property {Array.|null} [allowedConsumerProjects] PscConfig allowedConsumerProjects * @property {Array.|null} [pscAutoConnections] PscConfig pscAutoConnections * @property {string|null} [networkAttachmentUri] PscConfig networkAttachmentUri + * @property {boolean|null} [pscAutoDnsEnabled] PscConfig pscAutoDnsEnabled + * @property {boolean|null} [pscWriteEndpointDnsEnabled] PscConfig pscWriteEndpointDnsEnabled */ /** @@ -12963,6 +13005,22 @@ */ PscConfig.prototype.networkAttachmentUri = ""; + /** + * PscConfig pscAutoDnsEnabled. + * @member {boolean|null|undefined} pscAutoDnsEnabled + * @memberof google.cloud.sql.v1.PscConfig + * @instance + */ + PscConfig.prototype.pscAutoDnsEnabled = null; + + /** + * PscConfig pscWriteEndpointDnsEnabled. + * @member {boolean|null|undefined} pscWriteEndpointDnsEnabled + * @memberof google.cloud.sql.v1.PscConfig + * @instance + */ + PscConfig.prototype.pscWriteEndpointDnsEnabled = null; + // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -12972,6 +13030,18 @@ set: $util.oneOfSetter($oneOfFields) }); + // Virtual OneOf for proto3 optional field + Object.defineProperty(PscConfig.prototype, "_pscAutoDnsEnabled", { + get: $util.oneOfGetter($oneOfFields = ["pscAutoDnsEnabled"]), + set: $util.oneOfSetter($oneOfFields) + }); + + // Virtual OneOf for proto3 optional field + Object.defineProperty(PscConfig.prototype, "_pscWriteEndpointDnsEnabled", { + get: $util.oneOfGetter($oneOfFields = ["pscWriteEndpointDnsEnabled"]), + set: $util.oneOfSetter($oneOfFields) + }); + /** * Creates a new PscConfig instance using the specified properties. * @function create @@ -13006,6 +13076,10 @@ $root.google.cloud.sql.v1.PscAutoConnectionConfig.encode(message.pscAutoConnections[i], writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); if (message.networkAttachmentUri != null && Object.hasOwnProperty.call(message, "networkAttachmentUri")) writer.uint32(/* id 4, wireType 2 =*/34).string(message.networkAttachmentUri); + if (message.pscAutoDnsEnabled != null && Object.hasOwnProperty.call(message, "pscAutoDnsEnabled")) + writer.uint32(/* id 5, wireType 0 =*/40).bool(message.pscAutoDnsEnabled); + if (message.pscWriteEndpointDnsEnabled != null && Object.hasOwnProperty.call(message, "pscWriteEndpointDnsEnabled")) + writer.uint32(/* id 6, wireType 0 =*/48).bool(message.pscWriteEndpointDnsEnabled); return writer; }; @@ -13062,6 +13136,14 @@ message.networkAttachmentUri = reader.string(); break; } + case 5: { + message.pscAutoDnsEnabled = reader.bool(); + break; + } + case 6: { + message.pscWriteEndpointDnsEnabled = reader.bool(); + break; + } default: reader.skipType(tag & 7); break; @@ -13122,6 +13204,16 @@ if (message.networkAttachmentUri != null && message.hasOwnProperty("networkAttachmentUri")) if (!$util.isString(message.networkAttachmentUri)) return "networkAttachmentUri: string expected"; + if (message.pscAutoDnsEnabled != null && message.hasOwnProperty("pscAutoDnsEnabled")) { + properties._pscAutoDnsEnabled = 1; + if (typeof message.pscAutoDnsEnabled !== "boolean") + return "pscAutoDnsEnabled: boolean expected"; + } + if (message.pscWriteEndpointDnsEnabled != null && message.hasOwnProperty("pscWriteEndpointDnsEnabled")) { + properties._pscWriteEndpointDnsEnabled = 1; + if (typeof message.pscWriteEndpointDnsEnabled !== "boolean") + return "pscWriteEndpointDnsEnabled: boolean expected"; + } return null; }; @@ -13158,6 +13250,10 @@ } if (object.networkAttachmentUri != null) message.networkAttachmentUri = String(object.networkAttachmentUri); + if (object.pscAutoDnsEnabled != null) + message.pscAutoDnsEnabled = Boolean(object.pscAutoDnsEnabled); + if (object.pscWriteEndpointDnsEnabled != null) + message.pscWriteEndpointDnsEnabled = Boolean(object.pscWriteEndpointDnsEnabled); return message; }; @@ -13197,6 +13293,16 @@ } if (message.networkAttachmentUri != null && message.hasOwnProperty("networkAttachmentUri")) object.networkAttachmentUri = message.networkAttachmentUri; + if (message.pscAutoDnsEnabled != null && message.hasOwnProperty("pscAutoDnsEnabled")) { + object.pscAutoDnsEnabled = message.pscAutoDnsEnabled; + if (options.oneofs) + object._pscAutoDnsEnabled = "pscAutoDnsEnabled"; + } + if (message.pscWriteEndpointDnsEnabled != null && message.hasOwnProperty("pscWriteEndpointDnsEnabled")) { + object.pscWriteEndpointDnsEnabled = message.pscWriteEndpointDnsEnabled; + if (options.oneofs) + object._pscWriteEndpointDnsEnabled = "pscWriteEndpointDnsEnabled"; + } return object; }; @@ -16733,6 +16839,7 @@ case 51: case 52: case 53: + case 54: break; } if (message.importContext != null && message.hasOwnProperty("importContext")) { @@ -17062,6 +17169,10 @@ case 53: message.operationType = 53; break; + case "PRE_CHECK_MAJOR_VERSION_UPGRADE": + case 54: + message.operationType = 54; + break; } if (object.importContext != null) { if (typeof object.importContext !== "object") @@ -17264,6 +17375,7 @@ * @property {number} ENHANCED_BACKUP=51 ENHANCED_BACKUP value * @property {number} REPAIR_READ_POOL=52 REPAIR_READ_POOL value * @property {number} CREATE_READ_POOL=53 CREATE_READ_POOL value + * @property {number} PRE_CHECK_MAJOR_VERSION_UPGRADE=54 PRE_CHECK_MAJOR_VERSION_UPGRADE value */ Operation.SqlOperationType = (function() { var valuesById = {}, values = Object.create(valuesById); @@ -17319,6 +17431,7 @@ values[valuesById[51] = "ENHANCED_BACKUP"] = 51; values[valuesById[52] = "REPAIR_READ_POOL"] = 52; values[valuesById[53] = "CREATE_READ_POOL"] = 53; + values[valuesById[54] = "PRE_CHECK_MAJOR_VERSION_UPGRADE"] = 54; return values; })(); @@ -18755,6 +18868,7 @@ * @property {google.cloud.sql.v1.IConnectionPoolConfig|null} [connectionPoolConfig] Settings connectionPoolConfig * @property {google.cloud.sql.v1.IFinalBackupConfig|null} [finalBackupConfig] Settings finalBackupConfig * @property {google.cloud.sql.v1.IReadPoolAutoScaleConfig|null} [readPoolAutoScaleConfig] Settings readPoolAutoScaleConfig + * @property {google.protobuf.IBoolValue|null} [acceleratedReplicaMode] Settings acceleratedReplicaMode * @property {boolean|null} [autoUpgradeEnabled] Settings autoUpgradeEnabled * @property {google.cloud.sql.v1.ISqlServerEntraIdConfig|null} [entraidConfig] Settings entraidConfig * @property {google.cloud.sql.v1.Settings.DataApiAccess|null} [dataApiAccess] Settings dataApiAccess @@ -19108,6 +19222,14 @@ */ Settings.prototype.readPoolAutoScaleConfig = null; + /** + * Settings acceleratedReplicaMode. + * @member {google.protobuf.IBoolValue|null|undefined} acceleratedReplicaMode + * @memberof google.cloud.sql.v1.Settings + * @instance + */ + Settings.prototype.acceleratedReplicaMode = null; + /** * Settings autoUpgradeEnabled. * @member {boolean|null|undefined} autoUpgradeEnabled @@ -19295,6 +19417,8 @@ $root.google.cloud.sql.v1.FinalBackupConfig.encode(message.finalBackupConfig, writer.uint32(/* id 47, wireType 2 =*/378).fork()).ldelim(); if (message.readPoolAutoScaleConfig != null && Object.hasOwnProperty.call(message, "readPoolAutoScaleConfig")) $root.google.cloud.sql.v1.ReadPoolAutoScaleConfig.encode(message.readPoolAutoScaleConfig, writer.uint32(/* id 48, wireType 2 =*/386).fork()).ldelim(); + if (message.acceleratedReplicaMode != null && Object.hasOwnProperty.call(message, "acceleratedReplicaMode")) + $root.google.protobuf.BoolValue.encode(message.acceleratedReplicaMode, writer.uint32(/* id 49, wireType 2 =*/394).fork()).ldelim(); if (message.autoUpgradeEnabled != null && Object.hasOwnProperty.call(message, "autoUpgradeEnabled")) writer.uint32(/* id 50, wireType 0 =*/400).bool(message.autoUpgradeEnabled); if (message.entraidConfig != null && Object.hasOwnProperty.call(message, "entraidConfig")) @@ -19528,6 +19652,10 @@ message.readPoolAutoScaleConfig = $root.google.cloud.sql.v1.ReadPoolAutoScaleConfig.decode(reader, reader.uint32()); break; } + case 49: { + message.acceleratedReplicaMode = $root.google.protobuf.BoolValue.decode(reader, reader.uint32()); + break; + } case 50: { message.autoUpgradeEnabled = reader.bool(); break; @@ -19830,6 +19958,11 @@ return "readPoolAutoScaleConfig." + error; } } + if (message.acceleratedReplicaMode != null && message.hasOwnProperty("acceleratedReplicaMode")) { + var error = $root.google.protobuf.BoolValue.verify(message.acceleratedReplicaMode); + if (error) + return "acceleratedReplicaMode." + error; + } if (message.autoUpgradeEnabled != null && message.hasOwnProperty("autoUpgradeEnabled")) { properties._autoUpgradeEnabled = 1; if (typeof message.autoUpgradeEnabled !== "boolean") @@ -20203,6 +20336,11 @@ throw TypeError(".google.cloud.sql.v1.Settings.readPoolAutoScaleConfig: object expected"); message.readPoolAutoScaleConfig = $root.google.cloud.sql.v1.ReadPoolAutoScaleConfig.fromObject(object.readPoolAutoScaleConfig); } + if (object.acceleratedReplicaMode != null) { + if (typeof object.acceleratedReplicaMode !== "object") + throw TypeError(".google.cloud.sql.v1.Settings.acceleratedReplicaMode: object expected"); + message.acceleratedReplicaMode = $root.google.protobuf.BoolValue.fromObject(object.acceleratedReplicaMode); + } if (object.autoUpgradeEnabled != null) message.autoUpgradeEnabled = Boolean(object.autoUpgradeEnabled); if (object.entraidConfig != null) { @@ -20291,6 +20429,7 @@ object.enableGoogleMlIntegration = null; object.enableDataplexIntegration = null; object.retainBackupsOnDelete = null; + object.acceleratedReplicaMode = null; object.entraidConfig = null; object.performanceCaptureConfig = null; } @@ -20410,6 +20549,8 @@ if (options.oneofs) object._readPoolAutoScaleConfig = "readPoolAutoScaleConfig"; } + if (message.acceleratedReplicaMode != null && message.hasOwnProperty("acceleratedReplicaMode")) + object.acceleratedReplicaMode = $root.google.protobuf.BoolValue.toObject(message.acceleratedReplicaMode, options); if (message.autoUpgradeEnabled != null && message.hasOwnProperty("autoUpgradeEnabled")) { object.autoUpgradeEnabled = message.autoUpgradeEnabled; if (options.oneofs) @@ -23955,6 +24096,7 @@ * @property {number} POSTGRES_16=272 POSTGRES_16 value * @property {number} POSTGRES_17=408 POSTGRES_17 value * @property {number} POSTGRES_18=557 POSTGRES_18 value + * @property {number} POSTGRES_19=684 POSTGRES_19 value * @property {number} SQLSERVER_2019_STANDARD=26 SQLSERVER_2019_STANDARD value * @property {number} SQLSERVER_2019_ENTERPRISE=27 SQLSERVER_2019_ENTERPRISE value * @property {number} SQLSERVER_2019_EXPRESS=28 SQLSERVER_2019_EXPRESS value @@ -23963,6 +24105,9 @@ * @property {number} SQLSERVER_2022_ENTERPRISE=200 SQLSERVER_2022_ENTERPRISE value * @property {number} SQLSERVER_2022_EXPRESS=201 SQLSERVER_2022_EXPRESS value * @property {number} SQLSERVER_2022_WEB=202 SQLSERVER_2022_WEB value + * @property {number} SQLSERVER_2025_STANDARD=549 SQLSERVER_2025_STANDARD value + * @property {number} SQLSERVER_2025_ENTERPRISE=550 SQLSERVER_2025_ENTERPRISE value + * @property {number} SQLSERVER_2025_EXPRESS=551 SQLSERVER_2025_EXPRESS value */ v1.SqlDatabaseVersion = (function() { var valuesById = {}, values = Object.create(valuesById); @@ -24009,6 +24154,7 @@ values[valuesById[272] = "POSTGRES_16"] = 272; values[valuesById[408] = "POSTGRES_17"] = 408; values[valuesById[557] = "POSTGRES_18"] = 557; + values[valuesById[684] = "POSTGRES_19"] = 684; values[valuesById[26] = "SQLSERVER_2019_STANDARD"] = 26; values[valuesById[27] = "SQLSERVER_2019_ENTERPRISE"] = 27; values[valuesById[28] = "SQLSERVER_2019_EXPRESS"] = 28; @@ -24017,6 +24163,9 @@ values[valuesById[200] = "SQLSERVER_2022_ENTERPRISE"] = 200; values[valuesById[201] = "SQLSERVER_2022_EXPRESS"] = 201; values[valuesById[202] = "SQLSERVER_2022_WEB"] = 202; + values[valuesById[549] = "SQLSERVER_2025_STANDARD"] = 549; + values[valuesById[550] = "SQLSERVER_2025_ENTERPRISE"] = 550; + values[valuesById[551] = "SQLSERVER_2025_EXPRESS"] = 551; return values; })(); @@ -27099,6 +27248,7 @@ case 272: case 408: case 557: + case 684: case 26: case 27: case 28: @@ -27107,6 +27257,9 @@ case 200: case 201: case 202: + case 549: + case 550: + case 551: break; } if (message.maxChargeableBytes != null && message.hasOwnProperty("maxChargeableBytes")) { @@ -27453,6 +27606,10 @@ case 557: message.databaseVersion = 557; break; + case "POSTGRES_19": + case 684: + message.databaseVersion = 684; + break; case "SQLSERVER_2019_STANDARD": case 26: message.databaseVersion = 26; @@ -27485,6 +27642,18 @@ case 202: message.databaseVersion = 202; break; + case "SQLSERVER_2025_STANDARD": + case 549: + message.databaseVersion = 549; + break; + case "SQLSERVER_2025_ENTERPRISE": + case 550: + message.databaseVersion = 550; + break; + case "SQLSERVER_2025_EXPRESS": + case 551: + message.databaseVersion = 551; + break; } if (object.maxChargeableBytes != null) if ($util.Long) @@ -45881,6 +46050,9 @@ * @property {string|null} [allocatedIpRange] PointInTimeRestoreContext allocatedIpRange * @property {string|null} [preferredZone] PointInTimeRestoreContext preferredZone * @property {string|null} [preferredSecondaryZone] PointInTimeRestoreContext preferredSecondaryZone + * @property {google.cloud.sql.v1.IDatabaseInstance|null} [targetInstanceSettings] PointInTimeRestoreContext targetInstanceSettings + * @property {Array.|null} [targetInstanceClearSettingsFieldNames] PointInTimeRestoreContext targetInstanceClearSettingsFieldNames + * @property {string|null} [region] PointInTimeRestoreContext region */ /** @@ -45892,6 +46064,7 @@ * @param {google.cloud.sql.v1.IPointInTimeRestoreContext=} [properties] Properties to set */ function PointInTimeRestoreContext(properties) { + this.targetInstanceClearSettingsFieldNames = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -45954,6 +46127,30 @@ */ PointInTimeRestoreContext.prototype.preferredSecondaryZone = null; + /** + * PointInTimeRestoreContext targetInstanceSettings. + * @member {google.cloud.sql.v1.IDatabaseInstance|null|undefined} targetInstanceSettings + * @memberof google.cloud.sql.v1.PointInTimeRestoreContext + * @instance + */ + PointInTimeRestoreContext.prototype.targetInstanceSettings = null; + + /** + * PointInTimeRestoreContext targetInstanceClearSettingsFieldNames. + * @member {Array.} targetInstanceClearSettingsFieldNames + * @memberof google.cloud.sql.v1.PointInTimeRestoreContext + * @instance + */ + PointInTimeRestoreContext.prototype.targetInstanceClearSettingsFieldNames = $util.emptyArray; + + /** + * PointInTimeRestoreContext region. + * @member {string|null|undefined} region + * @memberof google.cloud.sql.v1.PointInTimeRestoreContext + * @instance + */ + PointInTimeRestoreContext.prototype.region = null; + // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -45993,6 +46190,12 @@ set: $util.oneOfSetter($oneOfFields) }); + // Virtual OneOf for proto3 optional field + Object.defineProperty(PointInTimeRestoreContext.prototype, "_region", { + get: $util.oneOfGetter($oneOfFields = ["region"]), + set: $util.oneOfSetter($oneOfFields) + }); + /** * Creates a new PointInTimeRestoreContext instance using the specified properties. * @function create @@ -46031,6 +46234,13 @@ writer.uint32(/* id 6, wireType 2 =*/50).string(message.preferredZone); if (message.preferredSecondaryZone != null && Object.hasOwnProperty.call(message, "preferredSecondaryZone")) writer.uint32(/* id 9, wireType 2 =*/74).string(message.preferredSecondaryZone); + if (message.targetInstanceSettings != null && Object.hasOwnProperty.call(message, "targetInstanceSettings")) + $root.google.cloud.sql.v1.DatabaseInstance.encode(message.targetInstanceSettings, writer.uint32(/* id 11, wireType 2 =*/90).fork()).ldelim(); + if (message.targetInstanceClearSettingsFieldNames != null && message.targetInstanceClearSettingsFieldNames.length) + for (var i = 0; i < message.targetInstanceClearSettingsFieldNames.length; ++i) + writer.uint32(/* id 12, wireType 2 =*/98).string(message.targetInstanceClearSettingsFieldNames[i]); + if (message.region != null && Object.hasOwnProperty.call(message, "region")) + writer.uint32(/* id 13, wireType 2 =*/106).string(message.region); return writer; }; @@ -46095,6 +46305,20 @@ message.preferredSecondaryZone = reader.string(); break; } + case 11: { + message.targetInstanceSettings = $root.google.cloud.sql.v1.DatabaseInstance.decode(reader, reader.uint32()); + break; + } + case 12: { + if (!(message.targetInstanceClearSettingsFieldNames && message.targetInstanceClearSettingsFieldNames.length)) + message.targetInstanceClearSettingsFieldNames = []; + message.targetInstanceClearSettingsFieldNames.push(reader.string()); + break; + } + case 13: { + message.region = reader.string(); + break; + } default: reader.skipType(tag & 7); break; @@ -46166,6 +46390,23 @@ if (!$util.isString(message.preferredSecondaryZone)) return "preferredSecondaryZone: string expected"; } + if (message.targetInstanceSettings != null && message.hasOwnProperty("targetInstanceSettings")) { + var error = $root.google.cloud.sql.v1.DatabaseInstance.verify(message.targetInstanceSettings); + if (error) + return "targetInstanceSettings." + error; + } + if (message.targetInstanceClearSettingsFieldNames != null && message.hasOwnProperty("targetInstanceClearSettingsFieldNames")) { + if (!Array.isArray(message.targetInstanceClearSettingsFieldNames)) + return "targetInstanceClearSettingsFieldNames: array expected"; + for (var i = 0; i < message.targetInstanceClearSettingsFieldNames.length; ++i) + if (!$util.isString(message.targetInstanceClearSettingsFieldNames[i])) + return "targetInstanceClearSettingsFieldNames: string[] expected"; + } + if (message.region != null && message.hasOwnProperty("region")) { + properties._region = 1; + if (!$util.isString(message.region)) + return "region: string expected"; + } return null; }; @@ -46198,6 +46439,20 @@ message.preferredZone = String(object.preferredZone); if (object.preferredSecondaryZone != null) message.preferredSecondaryZone = String(object.preferredSecondaryZone); + if (object.targetInstanceSettings != null) { + if (typeof object.targetInstanceSettings !== "object") + throw TypeError(".google.cloud.sql.v1.PointInTimeRestoreContext.targetInstanceSettings: object expected"); + message.targetInstanceSettings = $root.google.cloud.sql.v1.DatabaseInstance.fromObject(object.targetInstanceSettings); + } + if (object.targetInstanceClearSettingsFieldNames) { + if (!Array.isArray(object.targetInstanceClearSettingsFieldNames)) + throw TypeError(".google.cloud.sql.v1.PointInTimeRestoreContext.targetInstanceClearSettingsFieldNames: array expected"); + message.targetInstanceClearSettingsFieldNames = []; + for (var i = 0; i < object.targetInstanceClearSettingsFieldNames.length; ++i) + message.targetInstanceClearSettingsFieldNames[i] = String(object.targetInstanceClearSettingsFieldNames[i]); + } + if (object.region != null) + message.region = String(object.region); return message; }; @@ -46214,8 +46469,12 @@ if (!options) options = {}; var object = {}; - if (options.defaults) + if (options.arrays || options.defaults) + object.targetInstanceClearSettingsFieldNames = []; + if (options.defaults) { object.pointInTime = null; + object.targetInstanceSettings = null; + } if (message.datasource != null && message.hasOwnProperty("datasource")) { object.datasource = message.datasource; if (options.oneofs) @@ -46248,6 +46507,18 @@ if (options.oneofs) object._preferredSecondaryZone = "preferredSecondaryZone"; } + if (message.targetInstanceSettings != null && message.hasOwnProperty("targetInstanceSettings")) + object.targetInstanceSettings = $root.google.cloud.sql.v1.DatabaseInstance.toObject(message.targetInstanceSettings, options); + if (message.targetInstanceClearSettingsFieldNames && message.targetInstanceClearSettingsFieldNames.length) { + object.targetInstanceClearSettingsFieldNames = []; + for (var j = 0; j < message.targetInstanceClearSettingsFieldNames.length; ++j) + object.targetInstanceClearSettingsFieldNames[j] = message.targetInstanceClearSettingsFieldNames[j]; + } + if (message.region != null && message.hasOwnProperty("region")) { + object.region = message.region; + if (options.oneofs) + object._region = "region"; + } return object; }; @@ -47615,6 +47886,7 @@ case 272: case 408: case 557: + case 684: case 26: case 27: case 28: @@ -47623,6 +47895,9 @@ case 200: case 201: case 202: + case 549: + case 550: + case 551: break; } if (message.settings != null && message.hasOwnProperty("settings")) { @@ -47727,6 +48002,7 @@ case 3: case 4: case 5: + case 8: break; } } @@ -48139,6 +48415,10 @@ case 557: message.databaseVersion = 557; break; + case "POSTGRES_19": + case 684: + message.databaseVersion = 684; + break; case "SQLSERVER_2019_STANDARD": case 26: message.databaseVersion = 26; @@ -48171,6 +48451,18 @@ case 202: message.databaseVersion = 202; break; + case "SQLSERVER_2025_STANDARD": + case 549: + message.databaseVersion = 549; + break; + case "SQLSERVER_2025_ENTERPRISE": + case 550: + message.databaseVersion = 550; + break; + case "SQLSERVER_2025_EXPRESS": + case 551: + message.databaseVersion = 551; + break; } if (object.settings != null) { if (typeof object.settings !== "object") @@ -48319,6 +48611,10 @@ case 5: message.suspensionReason[i] = 5; break; + case "PROJECT_ABUSE": + case 8: + message.suspensionReason[i] = 8; + break; } } if (object.connectionName != null) @@ -58862,6 +59158,7 @@ * @property {number} LEGAL_ISSUE=3 LEGAL_ISSUE value * @property {number} OPERATIONAL_ISSUE=4 OPERATIONAL_ISSUE value * @property {number} KMS_KEY_ISSUE=5 KMS_KEY_ISSUE value + * @property {number} PROJECT_ABUSE=8 PROJECT_ABUSE value */ v1.SqlSuspensionReason = (function() { var valuesById = {}, values = Object.create(valuesById); @@ -58870,6 +59167,7 @@ values[valuesById[3] = "LEGAL_ISSUE"] = 3; values[valuesById[4] = "OPERATIONAL_ISSUE"] = 4; values[valuesById[5] = "KMS_KEY_ISSUE"] = 5; + values[valuesById[8] = "PROJECT_ABUSE"] = 8; return values; })(); @@ -59664,6 +59962,7 @@ case 272: case 408: case 557: + case 684: case 26: case 27: case 28: @@ -59672,6 +59971,9 @@ case 200: case 201: case 202: + case 549: + case 550: + case 551: break; } if (message.backendType != null && message.hasOwnProperty("backendType")) @@ -59955,6 +60257,10 @@ case 557: message.databaseVersion = 557; break; + case "POSTGRES_19": + case 684: + message.databaseVersion = 684; + break; case "SQLSERVER_2019_STANDARD": case 26: message.databaseVersion = 26; @@ -59987,6 +60293,18 @@ case 202: message.databaseVersion = 202; break; + case "SQLSERVER_2025_STANDARD": + case 549: + message.databaseVersion = 549; + break; + case "SQLSERVER_2025_ENTERPRISE": + case 550: + message.databaseVersion = 550; + break; + case "SQLSERVER_2025_EXPRESS": + case 551: + message.databaseVersion = 551; + break; } switch (object.backendType) { default: @@ -63945,6 +64263,7 @@ case 272: case 408: case 557: + case 684: case 26: case 27: case 28: @@ -63953,6 +64272,9 @@ case 200: case 201: case 202: + case 549: + case 550: + case 551: break; } } @@ -64257,6 +64579,10 @@ case 557: message.appliesTo[i] = 557; break; + case "POSTGRES_19": + case 684: + message.appliesTo[i] = 684; + break; case "SQLSERVER_2019_STANDARD": case 26: message.appliesTo[i] = 26; @@ -64289,6 +64615,18 @@ case 202: message.appliesTo[i] = 202; break; + case "SQLSERVER_2025_STANDARD": + case 549: + message.appliesTo[i] = 549; + break; + case "SQLSERVER_2025_ENTERPRISE": + case 550: + message.appliesTo[i] = 550; + break; + case "SQLSERVER_2025_EXPRESS": + case 551: + message.appliesTo[i] = 551; + break; } } if (object.allowedStringValues) { @@ -144678,6 +145016,7 @@ * @interface ICommonLanguageSettings * @property {string|null} [referenceDocsUri] CommonLanguageSettings referenceDocsUri * @property {Array.|null} [destinations] CommonLanguageSettings destinations + * @property {google.api.ISelectiveGapicGeneration|null} [selectiveGapicGeneration] CommonLanguageSettings selectiveGapicGeneration */ /** @@ -144712,6 +145051,14 @@ */ CommonLanguageSettings.prototype.destinations = $util.emptyArray; + /** + * CommonLanguageSettings selectiveGapicGeneration. + * @member {google.api.ISelectiveGapicGeneration|null|undefined} selectiveGapicGeneration + * @memberof google.api.CommonLanguageSettings + * @instance + */ + CommonLanguageSettings.prototype.selectiveGapicGeneration = null; + /** * Creates a new CommonLanguageSettings instance using the specified properties. * @function create @@ -144744,6 +145091,8 @@ writer.int32(message.destinations[i]); writer.ldelim(); } + if (message.selectiveGapicGeneration != null && Object.hasOwnProperty.call(message, "selectiveGapicGeneration")) + $root.google.api.SelectiveGapicGeneration.encode(message.selectiveGapicGeneration, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); return writer; }; @@ -144795,6 +145144,10 @@ message.destinations.push(reader.int32()); break; } + case 3: { + message.selectiveGapicGeneration = $root.google.api.SelectiveGapicGeneration.decode(reader, reader.uint32()); + break; + } default: reader.skipType(tag & 7); break; @@ -144846,6 +145199,11 @@ break; } } + if (message.selectiveGapicGeneration != null && message.hasOwnProperty("selectiveGapicGeneration")) { + var error = $root.google.api.SelectiveGapicGeneration.verify(message.selectiveGapicGeneration); + if (error) + return "selectiveGapicGeneration." + error; + } return null; }; @@ -144888,6 +145246,11 @@ break; } } + if (object.selectiveGapicGeneration != null) { + if (typeof object.selectiveGapicGeneration !== "object") + throw TypeError(".google.api.CommonLanguageSettings.selectiveGapicGeneration: object expected"); + message.selectiveGapicGeneration = $root.google.api.SelectiveGapicGeneration.fromObject(object.selectiveGapicGeneration); + } return message; }; @@ -144906,8 +145269,10 @@ var object = {}; if (options.arrays || options.defaults) object.destinations = []; - if (options.defaults) + if (options.defaults) { object.referenceDocsUri = ""; + object.selectiveGapicGeneration = null; + } if (message.referenceDocsUri != null && message.hasOwnProperty("referenceDocsUri")) object.referenceDocsUri = message.referenceDocsUri; if (message.destinations && message.destinations.length) { @@ -144915,6 +145280,8 @@ for (var j = 0; j < message.destinations.length; ++j) object.destinations[j] = options.enums === String ? $root.google.api.ClientLibraryDestination[message.destinations[j]] === undefined ? message.destinations[j] : $root.google.api.ClientLibraryDestination[message.destinations[j]] : message.destinations[j]; } + if (message.selectiveGapicGeneration != null && message.hasOwnProperty("selectiveGapicGeneration")) + object.selectiveGapicGeneration = $root.google.api.SelectiveGapicGeneration.toObject(message.selectiveGapicGeneration, options); return object; }; @@ -146737,6 +147104,7 @@ * @memberof google.api * @interface IPythonSettings * @property {google.api.ICommonLanguageSettings|null} [common] PythonSettings common + * @property {google.api.PythonSettings.IExperimentalFeatures|null} [experimentalFeatures] PythonSettings experimentalFeatures */ /** @@ -146762,6 +147130,14 @@ */ PythonSettings.prototype.common = null; + /** + * PythonSettings experimentalFeatures. + * @member {google.api.PythonSettings.IExperimentalFeatures|null|undefined} experimentalFeatures + * @memberof google.api.PythonSettings + * @instance + */ + PythonSettings.prototype.experimentalFeatures = null; + /** * Creates a new PythonSettings instance using the specified properties. * @function create @@ -146788,6 +147164,8 @@ writer = $Writer.create(); if (message.common != null && Object.hasOwnProperty.call(message, "common")) $root.google.api.CommonLanguageSettings.encode(message.common, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.experimentalFeatures != null && Object.hasOwnProperty.call(message, "experimentalFeatures")) + $root.google.api.PythonSettings.ExperimentalFeatures.encode(message.experimentalFeatures, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); return writer; }; @@ -146828,6 +147206,10 @@ message.common = $root.google.api.CommonLanguageSettings.decode(reader, reader.uint32()); break; } + case 2: { + message.experimentalFeatures = $root.google.api.PythonSettings.ExperimentalFeatures.decode(reader, reader.uint32()); + break; + } default: reader.skipType(tag & 7); break; @@ -146868,6 +147250,11 @@ if (error) return "common." + error; } + if (message.experimentalFeatures != null && message.hasOwnProperty("experimentalFeatures")) { + var error = $root.google.api.PythonSettings.ExperimentalFeatures.verify(message.experimentalFeatures); + if (error) + return "experimentalFeatures." + error; + } return null; }; @@ -146888,6 +147275,11 @@ throw TypeError(".google.api.PythonSettings.common: object expected"); message.common = $root.google.api.CommonLanguageSettings.fromObject(object.common); } + if (object.experimentalFeatures != null) { + if (typeof object.experimentalFeatures !== "object") + throw TypeError(".google.api.PythonSettings.experimentalFeatures: object expected"); + message.experimentalFeatures = $root.google.api.PythonSettings.ExperimentalFeatures.fromObject(object.experimentalFeatures); + } return message; }; @@ -146904,10 +147296,14 @@ if (!options) options = {}; var object = {}; - if (options.defaults) + if (options.defaults) { object.common = null; + object.experimentalFeatures = null; + } if (message.common != null && message.hasOwnProperty("common")) object.common = $root.google.api.CommonLanguageSettings.toObject(message.common, options); + if (message.experimentalFeatures != null && message.hasOwnProperty("experimentalFeatures")) + object.experimentalFeatures = $root.google.api.PythonSettings.ExperimentalFeatures.toObject(message.experimentalFeatures, options); return object; }; @@ -146937,6 +147333,258 @@ return typeUrlPrefix + "/google.api.PythonSettings"; }; + PythonSettings.ExperimentalFeatures = (function() { + + /** + * Properties of an ExperimentalFeatures. + * @memberof google.api.PythonSettings + * @interface IExperimentalFeatures + * @property {boolean|null} [restAsyncIoEnabled] ExperimentalFeatures restAsyncIoEnabled + * @property {boolean|null} [protobufPythonicTypesEnabled] ExperimentalFeatures protobufPythonicTypesEnabled + * @property {boolean|null} [unversionedPackageDisabled] ExperimentalFeatures unversionedPackageDisabled + */ + + /** + * Constructs a new ExperimentalFeatures. + * @memberof google.api.PythonSettings + * @classdesc Represents an ExperimentalFeatures. + * @implements IExperimentalFeatures + * @constructor + * @param {google.api.PythonSettings.IExperimentalFeatures=} [properties] Properties to set + */ + function ExperimentalFeatures(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ExperimentalFeatures restAsyncIoEnabled. + * @member {boolean} restAsyncIoEnabled + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @instance + */ + ExperimentalFeatures.prototype.restAsyncIoEnabled = false; + + /** + * ExperimentalFeatures protobufPythonicTypesEnabled. + * @member {boolean} protobufPythonicTypesEnabled + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @instance + */ + ExperimentalFeatures.prototype.protobufPythonicTypesEnabled = false; + + /** + * ExperimentalFeatures unversionedPackageDisabled. + * @member {boolean} unversionedPackageDisabled + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @instance + */ + ExperimentalFeatures.prototype.unversionedPackageDisabled = false; + + /** + * Creates a new ExperimentalFeatures instance using the specified properties. + * @function create + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {google.api.PythonSettings.IExperimentalFeatures=} [properties] Properties to set + * @returns {google.api.PythonSettings.ExperimentalFeatures} ExperimentalFeatures instance + */ + ExperimentalFeatures.create = function create(properties) { + return new ExperimentalFeatures(properties); + }; + + /** + * Encodes the specified ExperimentalFeatures message. Does not implicitly {@link google.api.PythonSettings.ExperimentalFeatures.verify|verify} messages. + * @function encode + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {google.api.PythonSettings.IExperimentalFeatures} message ExperimentalFeatures message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ExperimentalFeatures.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.restAsyncIoEnabled != null && Object.hasOwnProperty.call(message, "restAsyncIoEnabled")) + writer.uint32(/* id 1, wireType 0 =*/8).bool(message.restAsyncIoEnabled); + if (message.protobufPythonicTypesEnabled != null && Object.hasOwnProperty.call(message, "protobufPythonicTypesEnabled")) + writer.uint32(/* id 2, wireType 0 =*/16).bool(message.protobufPythonicTypesEnabled); + if (message.unversionedPackageDisabled != null && Object.hasOwnProperty.call(message, "unversionedPackageDisabled")) + writer.uint32(/* id 3, wireType 0 =*/24).bool(message.unversionedPackageDisabled); + return writer; + }; + + /** + * Encodes the specified ExperimentalFeatures message, length delimited. Does not implicitly {@link google.api.PythonSettings.ExperimentalFeatures.verify|verify} messages. + * @function encodeDelimited + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {google.api.PythonSettings.IExperimentalFeatures} message ExperimentalFeatures message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ExperimentalFeatures.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an ExperimentalFeatures message from the specified reader or buffer. + * @function decode + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.api.PythonSettings.ExperimentalFeatures} ExperimentalFeatures + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ExperimentalFeatures.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.api.PythonSettings.ExperimentalFeatures(); + while (reader.pos < end) { + var tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + message.restAsyncIoEnabled = reader.bool(); + break; + } + case 2: { + message.protobufPythonicTypesEnabled = reader.bool(); + break; + } + case 3: { + message.unversionedPackageDisabled = reader.bool(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an ExperimentalFeatures message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.api.PythonSettings.ExperimentalFeatures} ExperimentalFeatures + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ExperimentalFeatures.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an ExperimentalFeatures message. + * @function verify + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ExperimentalFeatures.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.restAsyncIoEnabled != null && message.hasOwnProperty("restAsyncIoEnabled")) + if (typeof message.restAsyncIoEnabled !== "boolean") + return "restAsyncIoEnabled: boolean expected"; + if (message.protobufPythonicTypesEnabled != null && message.hasOwnProperty("protobufPythonicTypesEnabled")) + if (typeof message.protobufPythonicTypesEnabled !== "boolean") + return "protobufPythonicTypesEnabled: boolean expected"; + if (message.unversionedPackageDisabled != null && message.hasOwnProperty("unversionedPackageDisabled")) + if (typeof message.unversionedPackageDisabled !== "boolean") + return "unversionedPackageDisabled: boolean expected"; + return null; + }; + + /** + * Creates an ExperimentalFeatures message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {Object.} object Plain object + * @returns {google.api.PythonSettings.ExperimentalFeatures} ExperimentalFeatures + */ + ExperimentalFeatures.fromObject = function fromObject(object) { + if (object instanceof $root.google.api.PythonSettings.ExperimentalFeatures) + return object; + var message = new $root.google.api.PythonSettings.ExperimentalFeatures(); + if (object.restAsyncIoEnabled != null) + message.restAsyncIoEnabled = Boolean(object.restAsyncIoEnabled); + if (object.protobufPythonicTypesEnabled != null) + message.protobufPythonicTypesEnabled = Boolean(object.protobufPythonicTypesEnabled); + if (object.unversionedPackageDisabled != null) + message.unversionedPackageDisabled = Boolean(object.unversionedPackageDisabled); + return message; + }; + + /** + * Creates a plain object from an ExperimentalFeatures message. Also converts values to other types if specified. + * @function toObject + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {google.api.PythonSettings.ExperimentalFeatures} message ExperimentalFeatures + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ExperimentalFeatures.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.restAsyncIoEnabled = false; + object.protobufPythonicTypesEnabled = false; + object.unversionedPackageDisabled = false; + } + if (message.restAsyncIoEnabled != null && message.hasOwnProperty("restAsyncIoEnabled")) + object.restAsyncIoEnabled = message.restAsyncIoEnabled; + if (message.protobufPythonicTypesEnabled != null && message.hasOwnProperty("protobufPythonicTypesEnabled")) + object.protobufPythonicTypesEnabled = message.protobufPythonicTypesEnabled; + if (message.unversionedPackageDisabled != null && message.hasOwnProperty("unversionedPackageDisabled")) + object.unversionedPackageDisabled = message.unversionedPackageDisabled; + return object; + }; + + /** + * Converts this ExperimentalFeatures to JSON. + * @function toJSON + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @instance + * @returns {Object.} JSON object + */ + ExperimentalFeatures.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ExperimentalFeatures + * @function getTypeUrl + * @memberof google.api.PythonSettings.ExperimentalFeatures + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ExperimentalFeatures.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.api.PythonSettings.ExperimentalFeatures"; + }; + + return ExperimentalFeatures; + })(); + return PythonSettings; })(); @@ -147813,6 +148461,7 @@ * @memberof google.api * @interface IGoSettings * @property {google.api.ICommonLanguageSettings|null} [common] GoSettings common + * @property {Object.|null} [renamedServices] GoSettings renamedServices */ /** @@ -147824,6 +148473,7 @@ * @param {google.api.IGoSettings=} [properties] Properties to set */ function GoSettings(properties) { + this.renamedServices = {}; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -147838,6 +148488,14 @@ */ GoSettings.prototype.common = null; + /** + * GoSettings renamedServices. + * @member {Object.} renamedServices + * @memberof google.api.GoSettings + * @instance + */ + GoSettings.prototype.renamedServices = $util.emptyObject; + /** * Creates a new GoSettings instance using the specified properties. * @function create @@ -147864,6 +148522,9 @@ writer = $Writer.create(); if (message.common != null && Object.hasOwnProperty.call(message, "common")) $root.google.api.CommonLanguageSettings.encode(message.common, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.renamedServices != null && Object.hasOwnProperty.call(message, "renamedServices")) + for (var keys = Object.keys(message.renamedServices), i = 0; i < keys.length; ++i) + writer.uint32(/* id 2, wireType 2 =*/18).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.renamedServices[keys[i]]).ldelim(); return writer; }; @@ -147894,7 +148555,7 @@ GoSettings.decode = function decode(reader, length, error) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.api.GoSettings(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.api.GoSettings(), key, value; while (reader.pos < end) { var tag = reader.uint32(); if (tag === error) @@ -147904,6 +148565,29 @@ message.common = $root.google.api.CommonLanguageSettings.decode(reader, reader.uint32()); break; } + case 2: { + if (message.renamedServices === $util.emptyObject) + message.renamedServices = {}; + var end2 = reader.uint32() + reader.pos; + key = ""; + value = ""; + while (reader.pos < end2) { + var tag2 = reader.uint32(); + switch (tag2 >>> 3) { + case 1: + key = reader.string(); + break; + case 2: + value = reader.string(); + break; + default: + reader.skipType(tag2 & 7); + break; + } + } + message.renamedServices[key] = value; + break; + } default: reader.skipType(tag & 7); break; @@ -147944,6 +148628,14 @@ if (error) return "common." + error; } + if (message.renamedServices != null && message.hasOwnProperty("renamedServices")) { + if (!$util.isObject(message.renamedServices)) + return "renamedServices: object expected"; + var key = Object.keys(message.renamedServices); + for (var i = 0; i < key.length; ++i) + if (!$util.isString(message.renamedServices[key[i]])) + return "renamedServices: string{k:string} expected"; + } return null; }; @@ -147964,6 +148656,13 @@ throw TypeError(".google.api.GoSettings.common: object expected"); message.common = $root.google.api.CommonLanguageSettings.fromObject(object.common); } + if (object.renamedServices) { + if (typeof object.renamedServices !== "object") + throw TypeError(".google.api.GoSettings.renamedServices: object expected"); + message.renamedServices = {}; + for (var keys = Object.keys(object.renamedServices), i = 0; i < keys.length; ++i) + message.renamedServices[keys[i]] = String(object.renamedServices[keys[i]]); + } return message; }; @@ -147980,10 +148679,18 @@ if (!options) options = {}; var object = {}; + if (options.objects || options.defaults) + object.renamedServices = {}; if (options.defaults) object.common = null; if (message.common != null && message.hasOwnProperty("common")) object.common = $root.google.api.CommonLanguageSettings.toObject(message.common, options); + var keys2; + if (message.renamedServices && (keys2 = Object.keys(message.renamedServices)).length) { + object.renamedServices = {}; + for (var j = 0; j < keys2.length; ++j) + object.renamedServices[keys2[j]] = message.renamedServices[keys2[j]]; + } return object; }; @@ -148622,6 +149329,251 @@ return values; })(); + api.SelectiveGapicGeneration = (function() { + + /** + * Properties of a SelectiveGapicGeneration. + * @memberof google.api + * @interface ISelectiveGapicGeneration + * @property {Array.|null} [methods] SelectiveGapicGeneration methods + * @property {boolean|null} [generateOmittedAsInternal] SelectiveGapicGeneration generateOmittedAsInternal + */ + + /** + * Constructs a new SelectiveGapicGeneration. + * @memberof google.api + * @classdesc Represents a SelectiveGapicGeneration. + * @implements ISelectiveGapicGeneration + * @constructor + * @param {google.api.ISelectiveGapicGeneration=} [properties] Properties to set + */ + function SelectiveGapicGeneration(properties) { + this.methods = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * SelectiveGapicGeneration methods. + * @member {Array.} methods + * @memberof google.api.SelectiveGapicGeneration + * @instance + */ + SelectiveGapicGeneration.prototype.methods = $util.emptyArray; + + /** + * SelectiveGapicGeneration generateOmittedAsInternal. + * @member {boolean} generateOmittedAsInternal + * @memberof google.api.SelectiveGapicGeneration + * @instance + */ + SelectiveGapicGeneration.prototype.generateOmittedAsInternal = false; + + /** + * Creates a new SelectiveGapicGeneration instance using the specified properties. + * @function create + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {google.api.ISelectiveGapicGeneration=} [properties] Properties to set + * @returns {google.api.SelectiveGapicGeneration} SelectiveGapicGeneration instance + */ + SelectiveGapicGeneration.create = function create(properties) { + return new SelectiveGapicGeneration(properties); + }; + + /** + * Encodes the specified SelectiveGapicGeneration message. Does not implicitly {@link google.api.SelectiveGapicGeneration.verify|verify} messages. + * @function encode + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {google.api.ISelectiveGapicGeneration} message SelectiveGapicGeneration message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SelectiveGapicGeneration.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.methods != null && message.methods.length) + for (var i = 0; i < message.methods.length; ++i) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.methods[i]); + if (message.generateOmittedAsInternal != null && Object.hasOwnProperty.call(message, "generateOmittedAsInternal")) + writer.uint32(/* id 2, wireType 0 =*/16).bool(message.generateOmittedAsInternal); + return writer; + }; + + /** + * Encodes the specified SelectiveGapicGeneration message, length delimited. Does not implicitly {@link google.api.SelectiveGapicGeneration.verify|verify} messages. + * @function encodeDelimited + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {google.api.ISelectiveGapicGeneration} message SelectiveGapicGeneration message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + SelectiveGapicGeneration.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a SelectiveGapicGeneration message from the specified reader or buffer. + * @function decode + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.api.SelectiveGapicGeneration} SelectiveGapicGeneration + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SelectiveGapicGeneration.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.api.SelectiveGapicGeneration(); + while (reader.pos < end) { + var tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + if (!(message.methods && message.methods.length)) + message.methods = []; + message.methods.push(reader.string()); + break; + } + case 2: { + message.generateOmittedAsInternal = reader.bool(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a SelectiveGapicGeneration message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.api.SelectiveGapicGeneration} SelectiveGapicGeneration + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + SelectiveGapicGeneration.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a SelectiveGapicGeneration message. + * @function verify + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + SelectiveGapicGeneration.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.methods != null && message.hasOwnProperty("methods")) { + if (!Array.isArray(message.methods)) + return "methods: array expected"; + for (var i = 0; i < message.methods.length; ++i) + if (!$util.isString(message.methods[i])) + return "methods: string[] expected"; + } + if (message.generateOmittedAsInternal != null && message.hasOwnProperty("generateOmittedAsInternal")) + if (typeof message.generateOmittedAsInternal !== "boolean") + return "generateOmittedAsInternal: boolean expected"; + return null; + }; + + /** + * Creates a SelectiveGapicGeneration message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {Object.} object Plain object + * @returns {google.api.SelectiveGapicGeneration} SelectiveGapicGeneration + */ + SelectiveGapicGeneration.fromObject = function fromObject(object) { + if (object instanceof $root.google.api.SelectiveGapicGeneration) + return object; + var message = new $root.google.api.SelectiveGapicGeneration(); + if (object.methods) { + if (!Array.isArray(object.methods)) + throw TypeError(".google.api.SelectiveGapicGeneration.methods: array expected"); + message.methods = []; + for (var i = 0; i < object.methods.length; ++i) + message.methods[i] = String(object.methods[i]); + } + if (object.generateOmittedAsInternal != null) + message.generateOmittedAsInternal = Boolean(object.generateOmittedAsInternal); + return message; + }; + + /** + * Creates a plain object from a SelectiveGapicGeneration message. Also converts values to other types if specified. + * @function toObject + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {google.api.SelectiveGapicGeneration} message SelectiveGapicGeneration + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + SelectiveGapicGeneration.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.methods = []; + if (options.defaults) + object.generateOmittedAsInternal = false; + if (message.methods && message.methods.length) { + object.methods = []; + for (var j = 0; j < message.methods.length; ++j) + object.methods[j] = message.methods[j]; + } + if (message.generateOmittedAsInternal != null && message.hasOwnProperty("generateOmittedAsInternal")) + object.generateOmittedAsInternal = message.generateOmittedAsInternal; + return object; + }; + + /** + * Converts this SelectiveGapicGeneration to JSON. + * @function toJSON + * @memberof google.api.SelectiveGapicGeneration + * @instance + * @returns {Object.} JSON object + */ + SelectiveGapicGeneration.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for SelectiveGapicGeneration + * @function getTypeUrl + * @memberof google.api.SelectiveGapicGeneration + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + SelectiveGapicGeneration.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.api.SelectiveGapicGeneration"; + }; + + return SelectiveGapicGeneration; + })(); + /** * LaunchStage enum. * @name google.api.LaunchStage @@ -149371,6 +150323,7 @@ * @memberof google.api * @interface IFieldInfo * @property {google.api.FieldInfo.Format|null} [format] FieldInfo format + * @property {Array.|null} [referencedTypes] FieldInfo referencedTypes */ /** @@ -149382,6 +150335,7 @@ * @param {google.api.IFieldInfo=} [properties] Properties to set */ function FieldInfo(properties) { + this.referencedTypes = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -149396,6 +150350,14 @@ */ FieldInfo.prototype.format = 0; + /** + * FieldInfo referencedTypes. + * @member {Array.} referencedTypes + * @memberof google.api.FieldInfo + * @instance + */ + FieldInfo.prototype.referencedTypes = $util.emptyArray; + /** * Creates a new FieldInfo instance using the specified properties. * @function create @@ -149422,6 +150384,9 @@ writer = $Writer.create(); if (message.format != null && Object.hasOwnProperty.call(message, "format")) writer.uint32(/* id 1, wireType 0 =*/8).int32(message.format); + if (message.referencedTypes != null && message.referencedTypes.length) + for (var i = 0; i < message.referencedTypes.length; ++i) + $root.google.api.TypeReference.encode(message.referencedTypes[i], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); return writer; }; @@ -149462,6 +150427,12 @@ message.format = reader.int32(); break; } + case 2: { + if (!(message.referencedTypes && message.referencedTypes.length)) + message.referencedTypes = []; + message.referencedTypes.push($root.google.api.TypeReference.decode(reader, reader.uint32())); + break; + } default: reader.skipType(tag & 7); break; @@ -149508,6 +150479,15 @@ case 4: break; } + if (message.referencedTypes != null && message.hasOwnProperty("referencedTypes")) { + if (!Array.isArray(message.referencedTypes)) + return "referencedTypes: array expected"; + for (var i = 0; i < message.referencedTypes.length; ++i) { + var error = $root.google.api.TypeReference.verify(message.referencedTypes[i]); + if (error) + return "referencedTypes." + error; + } + } return null; }; @@ -149551,6 +150531,16 @@ message.format = 4; break; } + if (object.referencedTypes) { + if (!Array.isArray(object.referencedTypes)) + throw TypeError(".google.api.FieldInfo.referencedTypes: array expected"); + message.referencedTypes = []; + for (var i = 0; i < object.referencedTypes.length; ++i) { + if (typeof object.referencedTypes[i] !== "object") + throw TypeError(".google.api.FieldInfo.referencedTypes: object expected"); + message.referencedTypes[i] = $root.google.api.TypeReference.fromObject(object.referencedTypes[i]); + } + } return message; }; @@ -149567,10 +150557,17 @@ if (!options) options = {}; var object = {}; + if (options.arrays || options.defaults) + object.referencedTypes = []; if (options.defaults) object.format = options.enums === String ? "FORMAT_UNSPECIFIED" : 0; if (message.format != null && message.hasOwnProperty("format")) object.format = options.enums === String ? $root.google.api.FieldInfo.Format[message.format] === undefined ? message.format : $root.google.api.FieldInfo.Format[message.format] : message.format; + if (message.referencedTypes && message.referencedTypes.length) { + object.referencedTypes = []; + for (var j = 0; j < message.referencedTypes.length; ++j) + object.referencedTypes[j] = $root.google.api.TypeReference.toObject(message.referencedTypes[j], options); + } return object; }; @@ -149623,6 +150620,211 @@ return FieldInfo; })(); + api.TypeReference = (function() { + + /** + * Properties of a TypeReference. + * @memberof google.api + * @interface ITypeReference + * @property {string|null} [typeName] TypeReference typeName + */ + + /** + * Constructs a new TypeReference. + * @memberof google.api + * @classdesc Represents a TypeReference. + * @implements ITypeReference + * @constructor + * @param {google.api.ITypeReference=} [properties] Properties to set + */ + function TypeReference(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * TypeReference typeName. + * @member {string} typeName + * @memberof google.api.TypeReference + * @instance + */ + TypeReference.prototype.typeName = ""; + + /** + * Creates a new TypeReference instance using the specified properties. + * @function create + * @memberof google.api.TypeReference + * @static + * @param {google.api.ITypeReference=} [properties] Properties to set + * @returns {google.api.TypeReference} TypeReference instance + */ + TypeReference.create = function create(properties) { + return new TypeReference(properties); + }; + + /** + * Encodes the specified TypeReference message. Does not implicitly {@link google.api.TypeReference.verify|verify} messages. + * @function encode + * @memberof google.api.TypeReference + * @static + * @param {google.api.ITypeReference} message TypeReference message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TypeReference.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.typeName != null && Object.hasOwnProperty.call(message, "typeName")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.typeName); + return writer; + }; + + /** + * Encodes the specified TypeReference message, length delimited. Does not implicitly {@link google.api.TypeReference.verify|verify} messages. + * @function encodeDelimited + * @memberof google.api.TypeReference + * @static + * @param {google.api.ITypeReference} message TypeReference message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + TypeReference.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a TypeReference message from the specified reader or buffer. + * @function decode + * @memberof google.api.TypeReference + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.api.TypeReference} TypeReference + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TypeReference.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.api.TypeReference(); + while (reader.pos < end) { + var tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + message.typeName = reader.string(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a TypeReference message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.api.TypeReference + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.api.TypeReference} TypeReference + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + TypeReference.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a TypeReference message. + * @function verify + * @memberof google.api.TypeReference + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + TypeReference.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.typeName != null && message.hasOwnProperty("typeName")) + if (!$util.isString(message.typeName)) + return "typeName: string expected"; + return null; + }; + + /** + * Creates a TypeReference message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.api.TypeReference + * @static + * @param {Object.} object Plain object + * @returns {google.api.TypeReference} TypeReference + */ + TypeReference.fromObject = function fromObject(object) { + if (object instanceof $root.google.api.TypeReference) + return object; + var message = new $root.google.api.TypeReference(); + if (object.typeName != null) + message.typeName = String(object.typeName); + return message; + }; + + /** + * Creates a plain object from a TypeReference message. Also converts values to other types if specified. + * @function toObject + * @memberof google.api.TypeReference + * @static + * @param {google.api.TypeReference} message TypeReference + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + TypeReference.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.typeName = ""; + if (message.typeName != null && message.hasOwnProperty("typeName")) + object.typeName = message.typeName; + return object; + }; + + /** + * Converts this TypeReference to JSON. + * @function toJSON + * @memberof google.api.TypeReference + * @instance + * @returns {Object.} JSON object + */ + TypeReference.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for TypeReference + * @function getTypeUrl + * @memberof google.api.TypeReference + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + TypeReference.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.api.TypeReference"; + }; + + return TypeReference; + })(); + return api; })(); @@ -149866,6 +151068,7 @@ * @name google.protobuf.Edition * @enum {number} * @property {number} EDITION_UNKNOWN=0 EDITION_UNKNOWN value + * @property {number} EDITION_LEGACY=900 EDITION_LEGACY value * @property {number} EDITION_PROTO2=998 EDITION_PROTO2 value * @property {number} EDITION_PROTO3=999 EDITION_PROTO3 value * @property {number} EDITION_2023=1000 EDITION_2023 value @@ -149880,6 +151083,7 @@ protobuf.Edition = (function() { var valuesById = {}, values = Object.create(valuesById); values[valuesById[0] = "EDITION_UNKNOWN"] = 0; + values[valuesById[900] = "EDITION_LEGACY"] = 900; values[valuesById[998] = "EDITION_PROTO2"] = 998; values[valuesById[999] = "EDITION_PROTO3"] = 999; values[valuesById[1000] = "EDITION_2023"] = 1000; @@ -149904,6 +151108,7 @@ * @property {Array.|null} [dependency] FileDescriptorProto dependency * @property {Array.|null} [publicDependency] FileDescriptorProto publicDependency * @property {Array.|null} [weakDependency] FileDescriptorProto weakDependency + * @property {Array.|null} [optionDependency] FileDescriptorProto optionDependency * @property {Array.|null} [messageType] FileDescriptorProto messageType * @property {Array.|null} [enumType] FileDescriptorProto enumType * @property {Array.|null} [service] FileDescriptorProto service @@ -149926,6 +151131,7 @@ this.dependency = []; this.publicDependency = []; this.weakDependency = []; + this.optionDependency = []; this.messageType = []; this.enumType = []; this.service = []; @@ -149976,6 +151182,14 @@ */ FileDescriptorProto.prototype.weakDependency = $util.emptyArray; + /** + * FileDescriptorProto optionDependency. + * @member {Array.} optionDependency + * @memberof google.protobuf.FileDescriptorProto + * @instance + */ + FileDescriptorProto.prototype.optionDependency = $util.emptyArray; + /** * FileDescriptorProto messageType. * @member {Array.} messageType @@ -150097,6 +151311,9 @@ writer.uint32(/* id 12, wireType 2 =*/98).string(message.syntax); if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) writer.uint32(/* id 14, wireType 0 =*/112).int32(message.edition); + if (message.optionDependency != null && message.optionDependency.length) + for (var i = 0; i < message.optionDependency.length; ++i) + writer.uint32(/* id 15, wireType 2 =*/122).string(message.optionDependency[i]); return writer; }; @@ -150169,6 +151386,12 @@ message.weakDependency.push(reader.int32()); break; } + case 15: { + if (!(message.optionDependency && message.optionDependency.length)) + message.optionDependency = []; + message.optionDependency.push(reader.string()); + break; + } case 4: { if (!(message.messageType && message.messageType.length)) message.messageType = []; @@ -150271,6 +151494,13 @@ if (!$util.isInteger(message.weakDependency[i])) return "weakDependency: integer[] expected"; } + if (message.optionDependency != null && message.hasOwnProperty("optionDependency")) { + if (!Array.isArray(message.optionDependency)) + return "optionDependency: array expected"; + for (var i = 0; i < message.optionDependency.length; ++i) + if (!$util.isString(message.optionDependency[i])) + return "optionDependency: string[] expected"; + } if (message.messageType != null && message.hasOwnProperty("messageType")) { if (!Array.isArray(message.messageType)) return "messageType: array expected"; @@ -150325,6 +151555,7 @@ default: return "edition: enum value expected"; case 0: + case 900: case 998: case 999: case 1000: @@ -150377,6 +151608,13 @@ for (var i = 0; i < object.weakDependency.length; ++i) message.weakDependency[i] = object.weakDependency[i] | 0; } + if (object.optionDependency) { + if (!Array.isArray(object.optionDependency)) + throw TypeError(".google.protobuf.FileDescriptorProto.optionDependency: array expected"); + message.optionDependency = []; + for (var i = 0; i < object.optionDependency.length; ++i) + message.optionDependency[i] = String(object.optionDependency[i]); + } if (object.messageType) { if (!Array.isArray(object.messageType)) throw TypeError(".google.protobuf.FileDescriptorProto.messageType: array expected"); @@ -150440,6 +151678,10 @@ case 0: message.edition = 0; break; + case "EDITION_LEGACY": + case 900: + message.edition = 900; + break; case "EDITION_PROTO2": case 998: message.edition = 998; @@ -150505,6 +151747,7 @@ object.extension = []; object.publicDependency = []; object.weakDependency = []; + object.optionDependency = []; } if (options.defaults) { object.name = ""; @@ -150561,6 +151804,11 @@ object.syntax = message.syntax; if (message.edition != null && message.hasOwnProperty("edition")) object.edition = options.enums === String ? $root.google.protobuf.Edition[message.edition] === undefined ? message.edition : $root.google.protobuf.Edition[message.edition] : message.edition; + if (message.optionDependency && message.optionDependency.length) { + object.optionDependency = []; + for (var j = 0; j < message.optionDependency.length; ++j) + object.optionDependency[j] = message.optionDependency[j]; + } return object; }; @@ -150609,6 +151857,7 @@ * @property {google.protobuf.IMessageOptions|null} [options] DescriptorProto options * @property {Array.|null} [reservedRange] DescriptorProto reservedRange * @property {Array.|null} [reservedName] DescriptorProto reservedName + * @property {google.protobuf.SymbolVisibility|null} [visibility] DescriptorProto visibility */ /** @@ -150714,6 +151963,14 @@ */ DescriptorProto.prototype.reservedName = $util.emptyArray; + /** + * DescriptorProto visibility. + * @member {google.protobuf.SymbolVisibility} visibility + * @memberof google.protobuf.DescriptorProto + * @instance + */ + DescriptorProto.prototype.visibility = 0; + /** * Creates a new DescriptorProto instance using the specified properties. * @function create @@ -150766,6 +152023,8 @@ if (message.reservedName != null && message.reservedName.length) for (var i = 0; i < message.reservedName.length; ++i) writer.uint32(/* id 10, wireType 2 =*/82).string(message.reservedName[i]); + if (message.visibility != null && Object.hasOwnProperty.call(message, "visibility")) + writer.uint32(/* id 11, wireType 0 =*/88).int32(message.visibility); return writer; }; @@ -150858,6 +152117,10 @@ message.reservedName.push(reader.string()); break; } + case 11: { + message.visibility = reader.int32(); + break; + } default: reader.skipType(tag & 7); break; @@ -150971,6 +152234,15 @@ if (!$util.isString(message.reservedName[i])) return "reservedName: string[] expected"; } + if (message.visibility != null && message.hasOwnProperty("visibility")) + switch (message.visibility) { + default: + return "visibility: enum value expected"; + case 0: + case 1: + case 2: + break; + } return null; }; @@ -151070,6 +152342,26 @@ for (var i = 0; i < object.reservedName.length; ++i) message.reservedName[i] = String(object.reservedName[i]); } + switch (object.visibility) { + default: + if (typeof object.visibility === "number") { + message.visibility = object.visibility; + break; + } + break; + case "VISIBILITY_UNSET": + case 0: + message.visibility = 0; + break; + case "VISIBILITY_LOCAL": + case 1: + message.visibility = 1; + break; + case "VISIBILITY_EXPORT": + case 2: + message.visibility = 2; + break; + } return message; }; @@ -151099,6 +152391,7 @@ if (options.defaults) { object.name = ""; object.options = null; + object.visibility = options.enums === String ? "VISIBILITY_UNSET" : 0; } if (message.name != null && message.hasOwnProperty("name")) object.name = message.name; @@ -151144,6 +152437,8 @@ for (var j = 0; j < message.reservedName.length; ++j) object.reservedName[j] = message.reservedName[j]; } + if (message.visibility != null && message.hasOwnProperty("visibility")) + object.visibility = options.enums === String ? $root.google.protobuf.SymbolVisibility[message.visibility] === undefined ? message.visibility : $root.google.protobuf.SymbolVisibility[message.visibility] : message.visibility; return object; }; @@ -153188,6 +154483,7 @@ * @property {google.protobuf.IEnumOptions|null} [options] EnumDescriptorProto options * @property {Array.|null} [reservedRange] EnumDescriptorProto reservedRange * @property {Array.|null} [reservedName] EnumDescriptorProto reservedName + * @property {google.protobuf.SymbolVisibility|null} [visibility] EnumDescriptorProto visibility */ /** @@ -153248,6 +154544,14 @@ */ EnumDescriptorProto.prototype.reservedName = $util.emptyArray; + /** + * EnumDescriptorProto visibility. + * @member {google.protobuf.SymbolVisibility} visibility + * @memberof google.protobuf.EnumDescriptorProto + * @instance + */ + EnumDescriptorProto.prototype.visibility = 0; + /** * Creates a new EnumDescriptorProto instance using the specified properties. * @function create @@ -153285,6 +154589,8 @@ if (message.reservedName != null && message.reservedName.length) for (var i = 0; i < message.reservedName.length; ++i) writer.uint32(/* id 5, wireType 2 =*/42).string(message.reservedName[i]); + if (message.visibility != null && Object.hasOwnProperty.call(message, "visibility")) + writer.uint32(/* id 6, wireType 0 =*/48).int32(message.visibility); return writer; }; @@ -153347,6 +154653,10 @@ message.reservedName.push(reader.string()); break; } + case 6: { + message.visibility = reader.int32(); + break; + } default: reader.skipType(tag & 7); break; @@ -153415,6 +154725,15 @@ if (!$util.isString(message.reservedName[i])) return "reservedName: string[] expected"; } + if (message.visibility != null && message.hasOwnProperty("visibility")) + switch (message.visibility) { + default: + return "visibility: enum value expected"; + case 0: + case 1: + case 2: + break; + } return null; }; @@ -153464,6 +154783,26 @@ for (var i = 0; i < object.reservedName.length; ++i) message.reservedName[i] = String(object.reservedName[i]); } + switch (object.visibility) { + default: + if (typeof object.visibility === "number") { + message.visibility = object.visibility; + break; + } + break; + case "VISIBILITY_UNSET": + case 0: + message.visibility = 0; + break; + case "VISIBILITY_LOCAL": + case 1: + message.visibility = 1; + break; + case "VISIBILITY_EXPORT": + case 2: + message.visibility = 2; + break; + } return message; }; @@ -153488,6 +154827,7 @@ if (options.defaults) { object.name = ""; object.options = null; + object.visibility = options.enums === String ? "VISIBILITY_UNSET" : 0; } if (message.name != null && message.hasOwnProperty("name")) object.name = message.name; @@ -153508,6 +154848,8 @@ for (var j = 0; j < message.reservedName.length; ++j) object.reservedName[j] = message.reservedName[j]; } + if (message.visibility != null && message.hasOwnProperty("visibility")) + object.visibility = options.enums === String ? $root.google.protobuf.SymbolVisibility[message.visibility] === undefined ? message.visibility : $root.google.protobuf.SymbolVisibility[message.visibility] : message.visibility; return object; }; @@ -155826,6 +157168,7 @@ * @property {Array.|null} [targets] FieldOptions targets * @property {Array.|null} [editionDefaults] FieldOptions editionDefaults * @property {google.protobuf.IFeatureSet|null} [features] FieldOptions features + * @property {google.protobuf.FieldOptions.IFeatureSupport|null} [featureSupport] FieldOptions featureSupport * @property {Array.|null} [uninterpretedOption] FieldOptions uninterpretedOption * @property {Array.|null} [".google.api.fieldBehavior"] FieldOptions .google.api.fieldBehavior * @property {google.api.IResourceReference|null} [".google.api.resourceReference"] FieldOptions .google.api.resourceReference @@ -155947,6 +157290,14 @@ */ FieldOptions.prototype.features = null; + /** + * FieldOptions featureSupport. + * @member {google.protobuf.FieldOptions.IFeatureSupport|null|undefined} featureSupport + * @memberof google.protobuf.FieldOptions + * @instance + */ + FieldOptions.prototype.featureSupport = null; + /** * FieldOptions uninterpretedOption. * @member {Array.} uninterpretedOption @@ -156029,6 +157380,8 @@ $root.google.protobuf.FieldOptions.EditionDefault.encode(message.editionDefaults[i], writer.uint32(/* id 20, wireType 2 =*/162).fork()).ldelim(); if (message.features != null && Object.hasOwnProperty.call(message, "features")) $root.google.protobuf.FeatureSet.encode(message.features, writer.uint32(/* id 21, wireType 2 =*/170).fork()).ldelim(); + if (message.featureSupport != null && Object.hasOwnProperty.call(message, "featureSupport")) + $root.google.protobuf.FieldOptions.FeatureSupport.encode(message.featureSupport, writer.uint32(/* id 22, wireType 2 =*/178).fork()).ldelim(); if (message.uninterpretedOption != null && message.uninterpretedOption.length) for (var i = 0; i < message.uninterpretedOption.length; ++i) $root.google.protobuf.UninterpretedOption.encode(message.uninterpretedOption[i], writer.uint32(/* id 999, wireType 2 =*/7994).fork()).ldelim(); @@ -156132,6 +157485,10 @@ message.features = $root.google.protobuf.FeatureSet.decode(reader, reader.uint32()); break; } + case 22: { + message.featureSupport = $root.google.protobuf.FieldOptions.FeatureSupport.decode(reader, reader.uint32()); + break; + } case 999: { if (!(message.uninterpretedOption && message.uninterpretedOption.length)) message.uninterpretedOption = []; @@ -156271,6 +157628,11 @@ if (error) return "features." + error; } + if (message.featureSupport != null && message.hasOwnProperty("featureSupport")) { + var error = $root.google.protobuf.FieldOptions.FeatureSupport.verify(message.featureSupport); + if (error) + return "featureSupport." + error; + } if (message.uninterpretedOption != null && message.hasOwnProperty("uninterpretedOption")) { if (!Array.isArray(message.uninterpretedOption)) return "uninterpretedOption: array expected"; @@ -156464,6 +157826,11 @@ throw TypeError(".google.protobuf.FieldOptions.features: object expected"); message.features = $root.google.protobuf.FeatureSet.fromObject(object.features); } + if (object.featureSupport != null) { + if (typeof object.featureSupport !== "object") + throw TypeError(".google.protobuf.FieldOptions.featureSupport: object expected"); + message.featureSupport = $root.google.protobuf.FieldOptions.FeatureSupport.fromObject(object.featureSupport); + } if (object.uninterpretedOption) { if (!Array.isArray(object.uninterpretedOption)) throw TypeError(".google.protobuf.FieldOptions.uninterpretedOption: array expected"); @@ -156566,6 +157933,7 @@ object.debugRedact = false; object.retention = options.enums === String ? "RETENTION_UNKNOWN" : 0; object.features = null; + object.featureSupport = null; object[".google.api.resourceReference"] = null; object[".google.api.fieldInfo"] = null; } @@ -156599,6 +157967,8 @@ } if (message.features != null && message.hasOwnProperty("features")) object.features = $root.google.protobuf.FeatureSet.toObject(message.features, options); + if (message.featureSupport != null && message.hasOwnProperty("featureSupport")) + object.featureSupport = $root.google.protobuf.FieldOptions.FeatureSupport.toObject(message.featureSupport, options); if (message.uninterpretedOption && message.uninterpretedOption.length) { object.uninterpretedOption = []; for (var j = 0; j < message.uninterpretedOption.length; ++j) @@ -156873,6 +158243,7 @@ default: return "edition: enum value expected"; case 0: + case 900: case 998: case 999: case 1000: @@ -156914,6 +158285,10 @@ case 0: message.edition = 0; break; + case "EDITION_LEGACY": + case 900: + message.edition = 900; + break; case "EDITION_PROTO2": case 998: message.edition = 998; @@ -157013,6 +158388,488 @@ return EditionDefault; })(); + FieldOptions.FeatureSupport = (function() { + + /** + * Properties of a FeatureSupport. + * @memberof google.protobuf.FieldOptions + * @interface IFeatureSupport + * @property {google.protobuf.Edition|null} [editionIntroduced] FeatureSupport editionIntroduced + * @property {google.protobuf.Edition|null} [editionDeprecated] FeatureSupport editionDeprecated + * @property {string|null} [deprecationWarning] FeatureSupport deprecationWarning + * @property {google.protobuf.Edition|null} [editionRemoved] FeatureSupport editionRemoved + */ + + /** + * Constructs a new FeatureSupport. + * @memberof google.protobuf.FieldOptions + * @classdesc Represents a FeatureSupport. + * @implements IFeatureSupport + * @constructor + * @param {google.protobuf.FieldOptions.IFeatureSupport=} [properties] Properties to set + */ + function FeatureSupport(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * FeatureSupport editionIntroduced. + * @member {google.protobuf.Edition} editionIntroduced + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @instance + */ + FeatureSupport.prototype.editionIntroduced = 0; + + /** + * FeatureSupport editionDeprecated. + * @member {google.protobuf.Edition} editionDeprecated + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @instance + */ + FeatureSupport.prototype.editionDeprecated = 0; + + /** + * FeatureSupport deprecationWarning. + * @member {string} deprecationWarning + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @instance + */ + FeatureSupport.prototype.deprecationWarning = ""; + + /** + * FeatureSupport editionRemoved. + * @member {google.protobuf.Edition} editionRemoved + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @instance + */ + FeatureSupport.prototype.editionRemoved = 0; + + /** + * Creates a new FeatureSupport instance using the specified properties. + * @function create + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {google.protobuf.FieldOptions.IFeatureSupport=} [properties] Properties to set + * @returns {google.protobuf.FieldOptions.FeatureSupport} FeatureSupport instance + */ + FeatureSupport.create = function create(properties) { + return new FeatureSupport(properties); + }; + + /** + * Encodes the specified FeatureSupport message. Does not implicitly {@link google.protobuf.FieldOptions.FeatureSupport.verify|verify} messages. + * @function encode + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {google.protobuf.FieldOptions.IFeatureSupport} message FeatureSupport message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FeatureSupport.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.editionIntroduced != null && Object.hasOwnProperty.call(message, "editionIntroduced")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.editionIntroduced); + if (message.editionDeprecated != null && Object.hasOwnProperty.call(message, "editionDeprecated")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.editionDeprecated); + if (message.deprecationWarning != null && Object.hasOwnProperty.call(message, "deprecationWarning")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.deprecationWarning); + if (message.editionRemoved != null && Object.hasOwnProperty.call(message, "editionRemoved")) + writer.uint32(/* id 4, wireType 0 =*/32).int32(message.editionRemoved); + return writer; + }; + + /** + * Encodes the specified FeatureSupport message, length delimited. Does not implicitly {@link google.protobuf.FieldOptions.FeatureSupport.verify|verify} messages. + * @function encodeDelimited + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {google.protobuf.FieldOptions.IFeatureSupport} message FeatureSupport message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FeatureSupport.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a FeatureSupport message from the specified reader or buffer. + * @function decode + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.protobuf.FieldOptions.FeatureSupport} FeatureSupport + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FeatureSupport.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.protobuf.FieldOptions.FeatureSupport(); + while (reader.pos < end) { + var tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + message.editionIntroduced = reader.int32(); + break; + } + case 2: { + message.editionDeprecated = reader.int32(); + break; + } + case 3: { + message.deprecationWarning = reader.string(); + break; + } + case 4: { + message.editionRemoved = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a FeatureSupport message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.protobuf.FieldOptions.FeatureSupport} FeatureSupport + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FeatureSupport.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a FeatureSupport message. + * @function verify + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + FeatureSupport.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.editionIntroduced != null && message.hasOwnProperty("editionIntroduced")) + switch (message.editionIntroduced) { + default: + return "editionIntroduced: enum value expected"; + case 0: + case 900: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } + if (message.editionDeprecated != null && message.hasOwnProperty("editionDeprecated")) + switch (message.editionDeprecated) { + default: + return "editionDeprecated: enum value expected"; + case 0: + case 900: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } + if (message.deprecationWarning != null && message.hasOwnProperty("deprecationWarning")) + if (!$util.isString(message.deprecationWarning)) + return "deprecationWarning: string expected"; + if (message.editionRemoved != null && message.hasOwnProperty("editionRemoved")) + switch (message.editionRemoved) { + default: + return "editionRemoved: enum value expected"; + case 0: + case 900: + case 998: + case 999: + case 1000: + case 1001: + case 1: + case 2: + case 99997: + case 99998: + case 99999: + case 2147483647: + break; + } + return null; + }; + + /** + * Creates a FeatureSupport message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {Object.} object Plain object + * @returns {google.protobuf.FieldOptions.FeatureSupport} FeatureSupport + */ + FeatureSupport.fromObject = function fromObject(object) { + if (object instanceof $root.google.protobuf.FieldOptions.FeatureSupport) + return object; + var message = new $root.google.protobuf.FieldOptions.FeatureSupport(); + switch (object.editionIntroduced) { + default: + if (typeof object.editionIntroduced === "number") { + message.editionIntroduced = object.editionIntroduced; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.editionIntroduced = 0; + break; + case "EDITION_LEGACY": + case 900: + message.editionIntroduced = 900; + break; + case "EDITION_PROTO2": + case 998: + message.editionIntroduced = 998; + break; + case "EDITION_PROTO3": + case 999: + message.editionIntroduced = 999; + break; + case "EDITION_2023": + case 1000: + message.editionIntroduced = 1000; + break; + case "EDITION_2024": + case 1001: + message.editionIntroduced = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.editionIntroduced = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.editionIntroduced = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.editionIntroduced = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.editionIntroduced = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.editionIntroduced = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.editionIntroduced = 2147483647; + break; + } + switch (object.editionDeprecated) { + default: + if (typeof object.editionDeprecated === "number") { + message.editionDeprecated = object.editionDeprecated; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.editionDeprecated = 0; + break; + case "EDITION_LEGACY": + case 900: + message.editionDeprecated = 900; + break; + case "EDITION_PROTO2": + case 998: + message.editionDeprecated = 998; + break; + case "EDITION_PROTO3": + case 999: + message.editionDeprecated = 999; + break; + case "EDITION_2023": + case 1000: + message.editionDeprecated = 1000; + break; + case "EDITION_2024": + case 1001: + message.editionDeprecated = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.editionDeprecated = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.editionDeprecated = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.editionDeprecated = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.editionDeprecated = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.editionDeprecated = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.editionDeprecated = 2147483647; + break; + } + if (object.deprecationWarning != null) + message.deprecationWarning = String(object.deprecationWarning); + switch (object.editionRemoved) { + default: + if (typeof object.editionRemoved === "number") { + message.editionRemoved = object.editionRemoved; + break; + } + break; + case "EDITION_UNKNOWN": + case 0: + message.editionRemoved = 0; + break; + case "EDITION_LEGACY": + case 900: + message.editionRemoved = 900; + break; + case "EDITION_PROTO2": + case 998: + message.editionRemoved = 998; + break; + case "EDITION_PROTO3": + case 999: + message.editionRemoved = 999; + break; + case "EDITION_2023": + case 1000: + message.editionRemoved = 1000; + break; + case "EDITION_2024": + case 1001: + message.editionRemoved = 1001; + break; + case "EDITION_1_TEST_ONLY": + case 1: + message.editionRemoved = 1; + break; + case "EDITION_2_TEST_ONLY": + case 2: + message.editionRemoved = 2; + break; + case "EDITION_99997_TEST_ONLY": + case 99997: + message.editionRemoved = 99997; + break; + case "EDITION_99998_TEST_ONLY": + case 99998: + message.editionRemoved = 99998; + break; + case "EDITION_99999_TEST_ONLY": + case 99999: + message.editionRemoved = 99999; + break; + case "EDITION_MAX": + case 2147483647: + message.editionRemoved = 2147483647; + break; + } + return message; + }; + + /** + * Creates a plain object from a FeatureSupport message. Also converts values to other types if specified. + * @function toObject + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {google.protobuf.FieldOptions.FeatureSupport} message FeatureSupport + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FeatureSupport.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.editionIntroduced = options.enums === String ? "EDITION_UNKNOWN" : 0; + object.editionDeprecated = options.enums === String ? "EDITION_UNKNOWN" : 0; + object.deprecationWarning = ""; + object.editionRemoved = options.enums === String ? "EDITION_UNKNOWN" : 0; + } + if (message.editionIntroduced != null && message.hasOwnProperty("editionIntroduced")) + object.editionIntroduced = options.enums === String ? $root.google.protobuf.Edition[message.editionIntroduced] === undefined ? message.editionIntroduced : $root.google.protobuf.Edition[message.editionIntroduced] : message.editionIntroduced; + if (message.editionDeprecated != null && message.hasOwnProperty("editionDeprecated")) + object.editionDeprecated = options.enums === String ? $root.google.protobuf.Edition[message.editionDeprecated] === undefined ? message.editionDeprecated : $root.google.protobuf.Edition[message.editionDeprecated] : message.editionDeprecated; + if (message.deprecationWarning != null && message.hasOwnProperty("deprecationWarning")) + object.deprecationWarning = message.deprecationWarning; + if (message.editionRemoved != null && message.hasOwnProperty("editionRemoved")) + object.editionRemoved = options.enums === String ? $root.google.protobuf.Edition[message.editionRemoved] === undefined ? message.editionRemoved : $root.google.protobuf.Edition[message.editionRemoved] : message.editionRemoved; + return object; + }; + + /** + * Converts this FeatureSupport to JSON. + * @function toJSON + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @instance + * @returns {Object.} JSON object + */ + FeatureSupport.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for FeatureSupport + * @function getTypeUrl + * @memberof google.protobuf.FieldOptions.FeatureSupport + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + FeatureSupport.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.protobuf.FieldOptions.FeatureSupport"; + }; + + return FeatureSupport; + })(); + return FieldOptions; })(); @@ -157605,6 +159462,7 @@ * @property {boolean|null} [deprecated] EnumValueOptions deprecated * @property {google.protobuf.IFeatureSet|null} [features] EnumValueOptions features * @property {boolean|null} [debugRedact] EnumValueOptions debugRedact + * @property {google.protobuf.FieldOptions.IFeatureSupport|null} [featureSupport] EnumValueOptions featureSupport * @property {Array.|null} [uninterpretedOption] EnumValueOptions uninterpretedOption */ @@ -157648,6 +159506,14 @@ */ EnumValueOptions.prototype.debugRedact = false; + /** + * EnumValueOptions featureSupport. + * @member {google.protobuf.FieldOptions.IFeatureSupport|null|undefined} featureSupport + * @memberof google.protobuf.EnumValueOptions + * @instance + */ + EnumValueOptions.prototype.featureSupport = null; + /** * EnumValueOptions uninterpretedOption. * @member {Array.} uninterpretedOption @@ -157686,6 +159552,8 @@ $root.google.protobuf.FeatureSet.encode(message.features, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); if (message.debugRedact != null && Object.hasOwnProperty.call(message, "debugRedact")) writer.uint32(/* id 3, wireType 0 =*/24).bool(message.debugRedact); + if (message.featureSupport != null && Object.hasOwnProperty.call(message, "featureSupport")) + $root.google.protobuf.FieldOptions.FeatureSupport.encode(message.featureSupport, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); if (message.uninterpretedOption != null && message.uninterpretedOption.length) for (var i = 0; i < message.uninterpretedOption.length; ++i) $root.google.protobuf.UninterpretedOption.encode(message.uninterpretedOption[i], writer.uint32(/* id 999, wireType 2 =*/7994).fork()).ldelim(); @@ -157737,6 +159605,10 @@ message.debugRedact = reader.bool(); break; } + case 4: { + message.featureSupport = $root.google.protobuf.FieldOptions.FeatureSupport.decode(reader, reader.uint32()); + break; + } case 999: { if (!(message.uninterpretedOption && message.uninterpretedOption.length)) message.uninterpretedOption = []; @@ -157789,6 +159661,11 @@ if (message.debugRedact != null && message.hasOwnProperty("debugRedact")) if (typeof message.debugRedact !== "boolean") return "debugRedact: boolean expected"; + if (message.featureSupport != null && message.hasOwnProperty("featureSupport")) { + var error = $root.google.protobuf.FieldOptions.FeatureSupport.verify(message.featureSupport); + if (error) + return "featureSupport." + error; + } if (message.uninterpretedOption != null && message.hasOwnProperty("uninterpretedOption")) { if (!Array.isArray(message.uninterpretedOption)) return "uninterpretedOption: array expected"; @@ -157822,6 +159699,11 @@ } if (object.debugRedact != null) message.debugRedact = Boolean(object.debugRedact); + if (object.featureSupport != null) { + if (typeof object.featureSupport !== "object") + throw TypeError(".google.protobuf.EnumValueOptions.featureSupport: object expected"); + message.featureSupport = $root.google.protobuf.FieldOptions.FeatureSupport.fromObject(object.featureSupport); + } if (object.uninterpretedOption) { if (!Array.isArray(object.uninterpretedOption)) throw TypeError(".google.protobuf.EnumValueOptions.uninterpretedOption: array expected"); @@ -157854,6 +159736,7 @@ object.deprecated = false; object.features = null; object.debugRedact = false; + object.featureSupport = null; } if (message.deprecated != null && message.hasOwnProperty("deprecated")) object.deprecated = message.deprecated; @@ -157861,6 +159744,8 @@ object.features = $root.google.protobuf.FeatureSet.toObject(message.features, options); if (message.debugRedact != null && message.hasOwnProperty("debugRedact")) object.debugRedact = message.debugRedact; + if (message.featureSupport != null && message.hasOwnProperty("featureSupport")) + object.featureSupport = $root.google.protobuf.FieldOptions.FeatureSupport.toObject(message.featureSupport, options); if (message.uninterpretedOption && message.uninterpretedOption.length) { object.uninterpretedOption = []; for (var j = 0; j < message.uninterpretedOption.length; ++j) @@ -159300,6 +161185,8 @@ * @property {google.protobuf.FeatureSet.Utf8Validation|null} [utf8Validation] FeatureSet utf8Validation * @property {google.protobuf.FeatureSet.MessageEncoding|null} [messageEncoding] FeatureSet messageEncoding * @property {google.protobuf.FeatureSet.JsonFormat|null} [jsonFormat] FeatureSet jsonFormat + * @property {google.protobuf.FeatureSet.EnforceNamingStyle|null} [enforceNamingStyle] FeatureSet enforceNamingStyle + * @property {google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility|null} [defaultSymbolVisibility] FeatureSet defaultSymbolVisibility */ /** @@ -159365,6 +161252,22 @@ */ FeatureSet.prototype.jsonFormat = 0; + /** + * FeatureSet enforceNamingStyle. + * @member {google.protobuf.FeatureSet.EnforceNamingStyle} enforceNamingStyle + * @memberof google.protobuf.FeatureSet + * @instance + */ + FeatureSet.prototype.enforceNamingStyle = 0; + + /** + * FeatureSet defaultSymbolVisibility. + * @member {google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility} defaultSymbolVisibility + * @memberof google.protobuf.FeatureSet + * @instance + */ + FeatureSet.prototype.defaultSymbolVisibility = 0; + /** * Creates a new FeatureSet instance using the specified properties. * @function create @@ -159401,6 +161304,10 @@ writer.uint32(/* id 5, wireType 0 =*/40).int32(message.messageEncoding); if (message.jsonFormat != null && Object.hasOwnProperty.call(message, "jsonFormat")) writer.uint32(/* id 6, wireType 0 =*/48).int32(message.jsonFormat); + if (message.enforceNamingStyle != null && Object.hasOwnProperty.call(message, "enforceNamingStyle")) + writer.uint32(/* id 7, wireType 0 =*/56).int32(message.enforceNamingStyle); + if (message.defaultSymbolVisibility != null && Object.hasOwnProperty.call(message, "defaultSymbolVisibility")) + writer.uint32(/* id 8, wireType 0 =*/64).int32(message.defaultSymbolVisibility); return writer; }; @@ -159461,6 +161368,14 @@ message.jsonFormat = reader.int32(); break; } + case 7: { + message.enforceNamingStyle = reader.int32(); + break; + } + case 8: { + message.defaultSymbolVisibility = reader.int32(); + break; + } default: reader.skipType(tag & 7); break; @@ -159551,6 +161466,26 @@ case 2: break; } + if (message.enforceNamingStyle != null && message.hasOwnProperty("enforceNamingStyle")) + switch (message.enforceNamingStyle) { + default: + return "enforceNamingStyle: enum value expected"; + case 0: + case 1: + case 2: + break; + } + if (message.defaultSymbolVisibility != null && message.hasOwnProperty("defaultSymbolVisibility")) + switch (message.defaultSymbolVisibility) { + default: + return "defaultSymbolVisibility: enum value expected"; + case 0: + case 1: + case 2: + case 3: + case 4: + break; + } return null; }; @@ -159690,6 +161625,54 @@ message.jsonFormat = 2; break; } + switch (object.enforceNamingStyle) { + default: + if (typeof object.enforceNamingStyle === "number") { + message.enforceNamingStyle = object.enforceNamingStyle; + break; + } + break; + case "ENFORCE_NAMING_STYLE_UNKNOWN": + case 0: + message.enforceNamingStyle = 0; + break; + case "STYLE2024": + case 1: + message.enforceNamingStyle = 1; + break; + case "STYLE_LEGACY": + case 2: + message.enforceNamingStyle = 2; + break; + } + switch (object.defaultSymbolVisibility) { + default: + if (typeof object.defaultSymbolVisibility === "number") { + message.defaultSymbolVisibility = object.defaultSymbolVisibility; + break; + } + break; + case "DEFAULT_SYMBOL_VISIBILITY_UNKNOWN": + case 0: + message.defaultSymbolVisibility = 0; + break; + case "EXPORT_ALL": + case 1: + message.defaultSymbolVisibility = 1; + break; + case "EXPORT_TOP_LEVEL": + case 2: + message.defaultSymbolVisibility = 2; + break; + case "LOCAL_ALL": + case 3: + message.defaultSymbolVisibility = 3; + break; + case "STRICT": + case 4: + message.defaultSymbolVisibility = 4; + break; + } return message; }; @@ -159713,6 +161696,8 @@ object.utf8Validation = options.enums === String ? "UTF8_VALIDATION_UNKNOWN" : 0; object.messageEncoding = options.enums === String ? "MESSAGE_ENCODING_UNKNOWN" : 0; object.jsonFormat = options.enums === String ? "JSON_FORMAT_UNKNOWN" : 0; + object.enforceNamingStyle = options.enums === String ? "ENFORCE_NAMING_STYLE_UNKNOWN" : 0; + object.defaultSymbolVisibility = options.enums === String ? "DEFAULT_SYMBOL_VISIBILITY_UNKNOWN" : 0; } if (message.fieldPresence != null && message.hasOwnProperty("fieldPresence")) object.fieldPresence = options.enums === String ? $root.google.protobuf.FeatureSet.FieldPresence[message.fieldPresence] === undefined ? message.fieldPresence : $root.google.protobuf.FeatureSet.FieldPresence[message.fieldPresence] : message.fieldPresence; @@ -159726,6 +161711,10 @@ object.messageEncoding = options.enums === String ? $root.google.protobuf.FeatureSet.MessageEncoding[message.messageEncoding] === undefined ? message.messageEncoding : $root.google.protobuf.FeatureSet.MessageEncoding[message.messageEncoding] : message.messageEncoding; if (message.jsonFormat != null && message.hasOwnProperty("jsonFormat")) object.jsonFormat = options.enums === String ? $root.google.protobuf.FeatureSet.JsonFormat[message.jsonFormat] === undefined ? message.jsonFormat : $root.google.protobuf.FeatureSet.JsonFormat[message.jsonFormat] : message.jsonFormat; + if (message.enforceNamingStyle != null && message.hasOwnProperty("enforceNamingStyle")) + object.enforceNamingStyle = options.enums === String ? $root.google.protobuf.FeatureSet.EnforceNamingStyle[message.enforceNamingStyle] === undefined ? message.enforceNamingStyle : $root.google.protobuf.FeatureSet.EnforceNamingStyle[message.enforceNamingStyle] : message.enforceNamingStyle; + if (message.defaultSymbolVisibility != null && message.hasOwnProperty("defaultSymbolVisibility")) + object.defaultSymbolVisibility = options.enums === String ? $root.google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility[message.defaultSymbolVisibility] === undefined ? message.defaultSymbolVisibility : $root.google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility[message.defaultSymbolVisibility] : message.defaultSymbolVisibility; return object; }; @@ -159853,6 +161842,219 @@ return values; })(); + /** + * EnforceNamingStyle enum. + * @name google.protobuf.FeatureSet.EnforceNamingStyle + * @enum {number} + * @property {number} ENFORCE_NAMING_STYLE_UNKNOWN=0 ENFORCE_NAMING_STYLE_UNKNOWN value + * @property {number} STYLE2024=1 STYLE2024 value + * @property {number} STYLE_LEGACY=2 STYLE_LEGACY value + */ + FeatureSet.EnforceNamingStyle = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "ENFORCE_NAMING_STYLE_UNKNOWN"] = 0; + values[valuesById[1] = "STYLE2024"] = 1; + values[valuesById[2] = "STYLE_LEGACY"] = 2; + return values; + })(); + + FeatureSet.VisibilityFeature = (function() { + + /** + * Properties of a VisibilityFeature. + * @memberof google.protobuf.FeatureSet + * @interface IVisibilityFeature + */ + + /** + * Constructs a new VisibilityFeature. + * @memberof google.protobuf.FeatureSet + * @classdesc Represents a VisibilityFeature. + * @implements IVisibilityFeature + * @constructor + * @param {google.protobuf.FeatureSet.IVisibilityFeature=} [properties] Properties to set + */ + function VisibilityFeature(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a new VisibilityFeature instance using the specified properties. + * @function create + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {google.protobuf.FeatureSet.IVisibilityFeature=} [properties] Properties to set + * @returns {google.protobuf.FeatureSet.VisibilityFeature} VisibilityFeature instance + */ + VisibilityFeature.create = function create(properties) { + return new VisibilityFeature(properties); + }; + + /** + * Encodes the specified VisibilityFeature message. Does not implicitly {@link google.protobuf.FeatureSet.VisibilityFeature.verify|verify} messages. + * @function encode + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {google.protobuf.FeatureSet.IVisibilityFeature} message VisibilityFeature message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + VisibilityFeature.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; + + /** + * Encodes the specified VisibilityFeature message, length delimited. Does not implicitly {@link google.protobuf.FeatureSet.VisibilityFeature.verify|verify} messages. + * @function encodeDelimited + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {google.protobuf.FeatureSet.IVisibilityFeature} message VisibilityFeature message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + VisibilityFeature.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a VisibilityFeature message from the specified reader or buffer. + * @function decode + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.protobuf.FeatureSet.VisibilityFeature} VisibilityFeature + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + VisibilityFeature.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.protobuf.FeatureSet.VisibilityFeature(); + while (reader.pos < end) { + var tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a VisibilityFeature message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.protobuf.FeatureSet.VisibilityFeature} VisibilityFeature + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + VisibilityFeature.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a VisibilityFeature message. + * @function verify + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + VisibilityFeature.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; + + /** + * Creates a VisibilityFeature message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {Object.} object Plain object + * @returns {google.protobuf.FeatureSet.VisibilityFeature} VisibilityFeature + */ + VisibilityFeature.fromObject = function fromObject(object) { + if (object instanceof $root.google.protobuf.FeatureSet.VisibilityFeature) + return object; + return new $root.google.protobuf.FeatureSet.VisibilityFeature(); + }; + + /** + * Creates a plain object from a VisibilityFeature message. Also converts values to other types if specified. + * @function toObject + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {google.protobuf.FeatureSet.VisibilityFeature} message VisibilityFeature + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + VisibilityFeature.toObject = function toObject() { + return {}; + }; + + /** + * Converts this VisibilityFeature to JSON. + * @function toJSON + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @instance + * @returns {Object.} JSON object + */ + VisibilityFeature.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for VisibilityFeature + * @function getTypeUrl + * @memberof google.protobuf.FeatureSet.VisibilityFeature + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + VisibilityFeature.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.protobuf.FeatureSet.VisibilityFeature"; + }; + + /** + * DefaultSymbolVisibility enum. + * @name google.protobuf.FeatureSet.VisibilityFeature.DefaultSymbolVisibility + * @enum {number} + * @property {number} DEFAULT_SYMBOL_VISIBILITY_UNKNOWN=0 DEFAULT_SYMBOL_VISIBILITY_UNKNOWN value + * @property {number} EXPORT_ALL=1 EXPORT_ALL value + * @property {number} EXPORT_TOP_LEVEL=2 EXPORT_TOP_LEVEL value + * @property {number} LOCAL_ALL=3 LOCAL_ALL value + * @property {number} STRICT=4 STRICT value + */ + VisibilityFeature.DefaultSymbolVisibility = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "DEFAULT_SYMBOL_VISIBILITY_UNKNOWN"] = 0; + values[valuesById[1] = "EXPORT_ALL"] = 1; + values[valuesById[2] = "EXPORT_TOP_LEVEL"] = 2; + values[valuesById[3] = "LOCAL_ALL"] = 3; + values[valuesById[4] = "STRICT"] = 4; + return values; + })(); + + return VisibilityFeature; + })(); + return FeatureSet; })(); @@ -160037,6 +162239,7 @@ default: return "minimumEdition: enum value expected"; case 0: + case 900: case 998: case 999: case 1000: @@ -160054,6 +162257,7 @@ default: return "maximumEdition: enum value expected"; case 0: + case 900: case 998: case 999: case 1000: @@ -160102,6 +162306,10 @@ case 0: message.minimumEdition = 0; break; + case "EDITION_LEGACY": + case 900: + message.minimumEdition = 900; + break; case "EDITION_PROTO2": case 998: message.minimumEdition = 998; @@ -160154,6 +162362,10 @@ case 0: message.maximumEdition = 0; break; + case "EDITION_LEGACY": + case 900: + message.maximumEdition = 900; + break; case "EDITION_PROTO2": case 998: message.maximumEdition = 998; @@ -160262,7 +162474,8 @@ * @memberof google.protobuf.FeatureSetDefaults * @interface IFeatureSetEditionDefault * @property {google.protobuf.Edition|null} [edition] FeatureSetEditionDefault edition - * @property {google.protobuf.IFeatureSet|null} [features] FeatureSetEditionDefault features + * @property {google.protobuf.IFeatureSet|null} [overridableFeatures] FeatureSetEditionDefault overridableFeatures + * @property {google.protobuf.IFeatureSet|null} [fixedFeatures] FeatureSetEditionDefault fixedFeatures */ /** @@ -160289,12 +162502,20 @@ FeatureSetEditionDefault.prototype.edition = 0; /** - * FeatureSetEditionDefault features. - * @member {google.protobuf.IFeatureSet|null|undefined} features + * FeatureSetEditionDefault overridableFeatures. + * @member {google.protobuf.IFeatureSet|null|undefined} overridableFeatures + * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault + * @instance + */ + FeatureSetEditionDefault.prototype.overridableFeatures = null; + + /** + * FeatureSetEditionDefault fixedFeatures. + * @member {google.protobuf.IFeatureSet|null|undefined} fixedFeatures * @memberof google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault * @instance */ - FeatureSetEditionDefault.prototype.features = null; + FeatureSetEditionDefault.prototype.fixedFeatures = null; /** * Creates a new FeatureSetEditionDefault instance using the specified properties. @@ -160320,10 +162541,12 @@ FeatureSetEditionDefault.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.features != null && Object.hasOwnProperty.call(message, "features")) - $root.google.protobuf.FeatureSet.encode(message.features, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) writer.uint32(/* id 3, wireType 0 =*/24).int32(message.edition); + if (message.overridableFeatures != null && Object.hasOwnProperty.call(message, "overridableFeatures")) + $root.google.protobuf.FeatureSet.encode(message.overridableFeatures, writer.uint32(/* id 4, wireType 2 =*/34).fork()).ldelim(); + if (message.fixedFeatures != null && Object.hasOwnProperty.call(message, "fixedFeatures")) + $root.google.protobuf.FeatureSet.encode(message.fixedFeatures, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); return writer; }; @@ -160364,8 +162587,12 @@ message.edition = reader.int32(); break; } - case 2: { - message.features = $root.google.protobuf.FeatureSet.decode(reader, reader.uint32()); + case 4: { + message.overridableFeatures = $root.google.protobuf.FeatureSet.decode(reader, reader.uint32()); + break; + } + case 5: { + message.fixedFeatures = $root.google.protobuf.FeatureSet.decode(reader, reader.uint32()); break; } default: @@ -160408,6 +162635,7 @@ default: return "edition: enum value expected"; case 0: + case 900: case 998: case 999: case 1000: @@ -160420,10 +162648,15 @@ case 2147483647: break; } - if (message.features != null && message.hasOwnProperty("features")) { - var error = $root.google.protobuf.FeatureSet.verify(message.features); + if (message.overridableFeatures != null && message.hasOwnProperty("overridableFeatures")) { + var error = $root.google.protobuf.FeatureSet.verify(message.overridableFeatures); + if (error) + return "overridableFeatures." + error; + } + if (message.fixedFeatures != null && message.hasOwnProperty("fixedFeatures")) { + var error = $root.google.protobuf.FeatureSet.verify(message.fixedFeatures); if (error) - return "features." + error; + return "fixedFeatures." + error; } return null; }; @@ -160451,6 +162684,10 @@ case 0: message.edition = 0; break; + case "EDITION_LEGACY": + case 900: + message.edition = 900; + break; case "EDITION_PROTO2": case 998: message.edition = 998; @@ -160492,10 +162729,15 @@ message.edition = 2147483647; break; } - if (object.features != null) { - if (typeof object.features !== "object") - throw TypeError(".google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.features: object expected"); - message.features = $root.google.protobuf.FeatureSet.fromObject(object.features); + if (object.overridableFeatures != null) { + if (typeof object.overridableFeatures !== "object") + throw TypeError(".google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.overridableFeatures: object expected"); + message.overridableFeatures = $root.google.protobuf.FeatureSet.fromObject(object.overridableFeatures); + } + if (object.fixedFeatures != null) { + if (typeof object.fixedFeatures !== "object") + throw TypeError(".google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault.fixedFeatures: object expected"); + message.fixedFeatures = $root.google.protobuf.FeatureSet.fromObject(object.fixedFeatures); } return message; }; @@ -160514,13 +162756,16 @@ options = {}; var object = {}; if (options.defaults) { - object.features = null; object.edition = options.enums === String ? "EDITION_UNKNOWN" : 0; + object.overridableFeatures = null; + object.fixedFeatures = null; } - if (message.features != null && message.hasOwnProperty("features")) - object.features = $root.google.protobuf.FeatureSet.toObject(message.features, options); if (message.edition != null && message.hasOwnProperty("edition")) object.edition = options.enums === String ? $root.google.protobuf.Edition[message.edition] === undefined ? message.edition : $root.google.protobuf.Edition[message.edition] : message.edition; + if (message.overridableFeatures != null && message.hasOwnProperty("overridableFeatures")) + object.overridableFeatures = $root.google.protobuf.FeatureSet.toObject(message.overridableFeatures, options); + if (message.fixedFeatures != null && message.hasOwnProperty("fixedFeatures")) + object.fixedFeatures = $root.google.protobuf.FeatureSet.toObject(message.fixedFeatures, options); return object; }; @@ -161735,6 +163980,22 @@ return GeneratedCodeInfo; })(); + /** + * SymbolVisibility enum. + * @name google.protobuf.SymbolVisibility + * @enum {number} + * @property {number} VISIBILITY_UNSET=0 VISIBILITY_UNSET value + * @property {number} VISIBILITY_LOCAL=1 VISIBILITY_LOCAL value + * @property {number} VISIBILITY_EXPORT=2 VISIBILITY_EXPORT value + */ + protobuf.SymbolVisibility = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "VISIBILITY_UNSET"] = 0; + values[valuesById[1] = "VISIBILITY_LOCAL"] = 1; + values[valuesById[2] = "VISIBILITY_EXPORT"] = 2; + return values; + })(); + protobuf.Duration = (function() { /** diff --git a/packages/google-cloud-sql/protos/protos.json b/packages/google-cloud-sql/protos/protos.json index bc666cfd4e7d..d3a8e054dbf8 100644 --- a/packages/google-cloud-sql/protos/protos.json +++ b/packages/google-cloud-sql/protos/protos.json @@ -1267,6 +1267,16 @@ "oneof": [ "pscEnabled" ] + }, + "_pscAutoDnsEnabled": { + "oneof": [ + "pscAutoDnsEnabled" + ] + }, + "_pscWriteEndpointDnsEnabled": { + "oneof": [ + "pscWriteEndpointDnsEnabled" + ] } }, "fields": { @@ -1299,6 +1309,22 @@ "options": { "(google.api.field_behavior)": "OPTIONAL" } + }, + "pscAutoDnsEnabled": { + "type": "bool", + "id": 5, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "proto3_optional": true + } + }, + "pscWriteEndpointDnsEnabled": { + "type": "bool", + "id": 6, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "proto3_optional": true + } } } }, @@ -1727,7 +1753,8 @@ "MANAGE_BACKUP": 50, "ENHANCED_BACKUP": 51, "REPAIR_READ_POOL": 52, - "CREATE_READ_POOL": 53 + "CREATE_READ_POOL": 53, + "PRE_CHECK_MAJOR_VERSION_UPGRADE": 54 } }, "SqlOperationStatus": { @@ -2101,6 +2128,13 @@ "proto3_optional": true } }, + "acceleratedReplicaMode": { + "type": "google.protobuf.BoolValue", + "id": 49, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, "autoUpgradeEnabled": { "type": "bool", "id": 50, @@ -2667,6 +2701,7 @@ "POSTGRES_16": 272, "POSTGRES_17": 408, "POSTGRES_18": 557, + "POSTGRES_19": 684, "SQLSERVER_2019_STANDARD": 26, "SQLSERVER_2019_ENTERPRISE": 27, "SQLSERVER_2019_EXPRESS": 28, @@ -2674,7 +2709,10 @@ "SQLSERVER_2022_STANDARD": 199, "SQLSERVER_2022_ENTERPRISE": 200, "SQLSERVER_2022_EXPRESS": 201, - "SQLSERVER_2022_WEB": 202 + "SQLSERVER_2022_WEB": 202, + "SQLSERVER_2025_STANDARD": 549, + "SQLSERVER_2025_ENTERPRISE": 550, + "SQLSERVER_2025_EXPRESS": 551 } }, "SqlPricingPlan": { @@ -5191,6 +5229,11 @@ "oneof": [ "preferredSecondaryZone" ] + }, + "_region": { + "oneof": [ + "region" + ] } }, "fields": { @@ -5246,6 +5289,29 @@ "(google.api.field_behavior)": "OPTIONAL", "proto3_optional": true } + }, + "targetInstanceSettings": { + "type": "DatabaseInstance", + "id": 11, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "targetInstanceClearSettingsFieldNames": { + "rule": "repeated", + "type": "string", + "id": 12, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "region": { + "type": "string", + "id": 13, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "proto3_optional": true + } } } }, @@ -6608,7 +6674,8 @@ "BILLING_ISSUE": 2, "LEGAL_ISSUE": 3, "OPERATIONAL_ISSUE": 4, - "KMS_KEY_ISSUE": 5 + "KMS_KEY_ISSUE": 5, + "PROJECT_ABUSE": 8 } }, "SqlConnectService": { @@ -15951,8 +16018,7 @@ "java_multiple_files": true, "java_outer_classname": "FieldInfoProto", "java_package": "com.google.api", - "objc_class_prefix": "GAPI", - "cc_enable_arenas": true + "objc_class_prefix": "GAPI" }, "nested": { "http": { @@ -16076,6 +16142,10 @@ "rule": "repeated", "type": "ClientLibraryDestination", "id": 2 + }, + "selectiveGapicGeneration": { + "type": "SelectiveGapicGeneration", + "id": 3 } } }, @@ -16216,6 +16286,28 @@ "common": { "type": "CommonLanguageSettings", "id": 1 + }, + "experimentalFeatures": { + "type": "ExperimentalFeatures", + "id": 2 + } + }, + "nested": { + "ExperimentalFeatures": { + "fields": { + "restAsyncIoEnabled": { + "type": "bool", + "id": 1 + }, + "protobufPythonicTypesEnabled": { + "type": "bool", + "id": 2 + }, + "unversionedPackageDisabled": { + "type": "bool", + "id": 3 + } + } } } }, @@ -16273,6 +16365,11 @@ "common": { "type": "CommonLanguageSettings", "id": 1 + }, + "renamedServices": { + "keyType": "string", + "type": "string", + "id": 2 } } }, @@ -16334,6 +16431,19 @@ "PACKAGE_MANAGER": 20 } }, + "SelectiveGapicGeneration": { + "fields": { + "methods": { + "rule": "repeated", + "type": "string", + "id": 1 + }, + "generateOmittedAsInternal": { + "type": "bool", + "id": 2 + } + } + }, "LaunchStage": { "values": { "LAUNCH_STAGE_UNSPECIFIED": 0, @@ -16455,6 +16565,11 @@ "format": { "type": "Format", "id": 1 + }, + "referencedTypes": { + "rule": "repeated", + "type": "TypeReference", + "id": 2 } }, "nested": { @@ -16468,6 +16583,14 @@ } } } + }, + "TypeReference": { + "fields": { + "typeName": { + "type": "string", + "id": 1 + } + } } } }, @@ -16490,12 +16613,19 @@ "type": "FileDescriptorProto", "id": 1 } - } + }, + "extensions": [ + [ + 536000000, + 536000000 + ] + ] }, "Edition": { "edition": "proto2", "values": { "EDITION_UNKNOWN": 0, + "EDITION_LEGACY": 900, "EDITION_PROTO2": 998, "EDITION_PROTO3": 999, "EDITION_2023": 1000, @@ -16534,6 +16664,11 @@ "type": "int32", "id": 11 }, + "optionDependency": { + "rule": "repeated", + "type": "string", + "id": 15 + }, "messageType": { "rule": "repeated", "type": "DescriptorProto", @@ -16622,6 +16757,10 @@ "rule": "repeated", "type": "string", "id": 10 + }, + "visibility": { + "type": "SymbolVisibility", + "id": 11 } }, "nested": { @@ -16847,6 +16986,10 @@ "rule": "repeated", "type": "string", "id": 5 + }, + "visibility": { + "type": "SymbolVisibility", + "id": 6 } }, "nested": { @@ -16897,7 +17040,14 @@ "type": "ServiceOptions", "id": 3 } - } + }, + "reserved": [ + [ + 4, + 4 + ], + "stream" + ] }, "MethodDescriptorProto": { "edition": "proto2", @@ -17061,6 +17211,7 @@ 42, 42 ], + "php_generic_services", [ 38, 38 @@ -17196,7 +17347,8 @@ "type": "bool", "id": 10, "options": { - "default": false + "default": false, + "deprecated": true } }, "debugRedact": { @@ -17224,6 +17376,10 @@ "type": "FeatureSet", "id": 21 }, + "featureSupport": { + "type": "FeatureSupport", + "id": 22 + }, "uninterpretedOption": { "rule": "repeated", "type": "UninterpretedOption", @@ -17293,6 +17449,26 @@ "id": 2 } } + }, + "FeatureSupport": { + "fields": { + "editionIntroduced": { + "type": "Edition", + "id": 1 + }, + "editionDeprecated": { + "type": "Edition", + "id": 2 + }, + "deprecationWarning": { + "type": "string", + "id": 3 + }, + "editionRemoved": { + "type": "Edition", + "id": 4 + } + } } } }, @@ -17381,6 +17557,10 @@ "default": false } }, + "featureSupport": { + "type": "FieldOptions.FeatureSupport", + "id": 4 + }, "uninterpretedOption": { "rule": "repeated", "type": "UninterpretedOption", @@ -17523,6 +17703,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", + "feature_support.edition_introduced": "EDITION_2023", "edition_defaults.edition": "EDITION_2023", "edition_defaults.value": "EXPLICIT" } @@ -17533,6 +17714,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", + "feature_support.edition_introduced": "EDITION_2023", "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "OPEN" } @@ -17543,6 +17725,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", + "feature_support.edition_introduced": "EDITION_2023", "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "PACKED" } @@ -17553,6 +17736,7 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", + "feature_support.edition_introduced": "EDITION_2023", "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "VERIFY" } @@ -17563,7 +17747,8 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", - "edition_defaults.edition": "EDITION_PROTO2", + "feature_support.edition_introduced": "EDITION_2023", + "edition_defaults.edition": "EDITION_LEGACY", "edition_defaults.value": "LENGTH_PREFIXED" } }, @@ -17573,27 +17758,38 @@ "options": { "retention": "RETENTION_RUNTIME", "targets": "TARGET_TYPE_FILE", + "feature_support.edition_introduced": "EDITION_2023", "edition_defaults.edition": "EDITION_PROTO3", "edition_defaults.value": "ALLOW" } + }, + "enforceNamingStyle": { + "type": "EnforceNamingStyle", + "id": 7, + "options": { + "retention": "RETENTION_SOURCE", + "targets": "TARGET_TYPE_METHOD", + "feature_support.edition_introduced": "EDITION_2024", + "edition_defaults.edition": "EDITION_2024", + "edition_defaults.value": "STYLE2024" + } + }, + "defaultSymbolVisibility": { + "type": "VisibilityFeature.DefaultSymbolVisibility", + "id": 8, + "options": { + "retention": "RETENTION_SOURCE", + "targets": "TARGET_TYPE_FILE", + "feature_support.edition_introduced": "EDITION_2024", + "edition_defaults.edition": "EDITION_2024", + "edition_defaults.value": "EXPORT_TOP_LEVEL" + } } }, "extensions": [ [ 1000, - 1000 - ], - [ - 1001, - 1001 - ], - [ - 1002, - 1002 - ], - [ - 9990, - 9990 + 9994 ], [ 9995, @@ -17638,7 +17834,13 @@ "UTF8_VALIDATION_UNKNOWN": 0, "VERIFY": 2, "NONE": 3 - } + }, + "reserved": [ + [ + 1, + 1 + ] + ] }, "MessageEncoding": { "values": { @@ -17653,6 +17855,33 @@ "ALLOW": 1, "LEGACY_BEST_EFFORT": 2 } + }, + "EnforceNamingStyle": { + "values": { + "ENFORCE_NAMING_STYLE_UNKNOWN": 0, + "STYLE2024": 1, + "STYLE_LEGACY": 2 + } + }, + "VisibilityFeature": { + "fields": {}, + "reserved": [ + [ + 1, + 536870911 + ] + ], + "nested": { + "DefaultSymbolVisibility": { + "values": { + "DEFAULT_SYMBOL_VISIBILITY_UNKNOWN": 0, + "EXPORT_ALL": 1, + "EXPORT_TOP_LEVEL": 2, + "LOCAL_ALL": 3, + "STRICT": 4 + } + } + } } } }, @@ -17680,11 +17909,26 @@ "type": "Edition", "id": 3 }, - "features": { + "overridableFeatures": { "type": "FeatureSet", - "id": 2 + "id": 4 + }, + "fixedFeatures": { + "type": "FeatureSet", + "id": 5 } - } + }, + "reserved": [ + [ + 1, + 1 + ], + [ + 2, + 2 + ], + "features" + ] } } }, @@ -17697,6 +17941,12 @@ "id": 1 } }, + "extensions": [ + [ + 536000000, + 536000000 + ] + ], "nested": { "Location": { "fields": { @@ -17782,6 +18032,14 @@ } } }, + "SymbolVisibility": { + "edition": "proto2", + "values": { + "VISIBILITY_UNSET": 0, + "VISIBILITY_LOCAL": 1, + "VISIBILITY_EXPORT": 2 + } + }, "Duration": { "fields": { "seconds": { diff --git a/packages/google-cloud-sql/samples/generated/v1/snippet_metadata_google.cloud.sql.v1.json b/packages/google-cloud-sql/samples/generated/v1/snippet_metadata_google.cloud.sql.v1.json index eebb8ef8de18..76103b57b6ed 100644 --- a/packages/google-cloud-sql/samples/generated/v1/snippet_metadata_google.cloud.sql.v1.json +++ b/packages/google-cloud-sql/samples/generated/v1/snippet_metadata_google.cloud.sql.v1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "nodejs-sql", - "version": "0.24.0", + "version": "0.1.0", "language": "TYPESCRIPT", "apis": [ { diff --git a/packages/google-cloud-sql/samples/generated/v1/sql_instances_service.clone.js b/packages/google-cloud-sql/samples/generated/v1/sql_instances_service.clone.js index 4f700337fe2c..e8213ce4277d 100644 --- a/packages/google-cloud-sql/samples/generated/v1/sql_instances_service.clone.js +++ b/packages/google-cloud-sql/samples/generated/v1/sql_instances_service.clone.js @@ -34,7 +34,7 @@ function main(instance, project, body) { */ // const instance = 'abc123' /** - * Required. Project ID of the source as well as the clone Cloud SQL instance. + * Required. Project ID of the source Cloud SQL instance. */ // const project = 'my-project' /** diff --git a/packages/google-cloud-sql/samples/generated/v1beta4/snippet_metadata_google.cloud.sql.v1beta4.json b/packages/google-cloud-sql/samples/generated/v1beta4/snippet_metadata_google.cloud.sql.v1beta4.json index 477eae4f43d4..3806a1cf62ff 100644 --- a/packages/google-cloud-sql/samples/generated/v1beta4/snippet_metadata_google.cloud.sql.v1beta4.json +++ b/packages/google-cloud-sql/samples/generated/v1beta4/snippet_metadata_google.cloud.sql.v1beta4.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "nodejs-sql", - "version": "0.24.0", + "version": "0.1.0", "language": "TYPESCRIPT", "apis": [ { diff --git a/packages/google-cloud-sql/src/v1/index.ts b/packages/google-cloud-sql/src/v1/index.ts index fa8a89f713a8..3e843e173570 100644 --- a/packages/google-cloud-sql/src/v1/index.ts +++ b/packages/google-cloud-sql/src/v1/index.ts @@ -16,19 +16,19 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** - -export {SqlBackupRunsServiceClient} from './sql_backup_runs_service_client'; -export {SqlBackupsServiceClient} from './sql_backups_service_client'; -export {SqlConnectServiceClient} from './sql_connect_service_client'; -export {SqlDatabasesServiceClient} from './sql_databases_service_client'; - -export {SqlFeatureEligibilityServiceClient} from './sql_feature_eligibility_service_client'; -export {SqlFlagsServiceClient} from './sql_flags_service_client'; - - -export {SqlInstancesServiceClient} from './sql_instances_service_client'; -export {SqlOperationsServiceClient} from './sql_operations_service_client'; - -export {SqlSslCertsServiceClient} from './sql_ssl_certs_service_client'; -export {SqlTiersServiceClient} from './sql_tiers_service_client'; -export {SqlUsersServiceClient} from './sql_users_service_client'; +export { SqlAvailableDatabaseVersionsServiceClient } from './sql_available_database_versions_service_client'; +export { SqlBackupRunsServiceClient } from './sql_backup_runs_service_client'; +export { SqlBackupsServiceClient } from './sql_backups_service_client'; +export { SqlConnectServiceClient } from './sql_connect_service_client'; +export { SqlDatabasesServiceClient } from './sql_databases_service_client'; +export { SqlEventsServiceClient } from './sql_events_service_client'; +export { SqlFeatureEligibilityServiceClient } from './sql_feature_eligibility_service_client'; +export { SqlFlagsServiceClient } from './sql_flags_service_client'; +export { SqlIamPoliciesServiceClient } from './sql_iam_policies_service_client'; +export { SqlInstanceNamesServiceClient } from './sql_instance_names_service_client'; +export { SqlInstancesServiceClient } from './sql_instances_service_client'; +export { SqlOperationsServiceClient } from './sql_operations_service_client'; +export { SqlRegionsServiceClient } from './sql_regions_service_client'; +export { SqlSslCertsServiceClient } from './sql_ssl_certs_service_client'; +export { SqlTiersServiceClient } from './sql_tiers_service_client'; +export { SqlUsersServiceClient } from './sql_users_service_client'; diff --git a/packages/google-cloud-sql/src/v1/sql_backup_runs_service_client.ts b/packages/google-cloud-sql/src/v1/sql_backup_runs_service_client.ts index e6258c7ae72b..582b1c1f4ae2 100644 --- a/packages/google-cloud-sql/src/v1/sql_backup_runs_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_backup_runs_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlBackupRunsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlBackupRunsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlBackupRunsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlBackupRunsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlBackupRunsServiceClient. @@ -101,21 +108,42 @@ export class SqlBackupRunsServiceClient { * const client = new SqlBackupRunsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlBackupRunsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlBackupRunsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlBackupRunsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlBackupRunsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlBackupRunsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlBackupRunsService', + 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 @@ -222,36 +249,40 @@ export class SqlBackupRunsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlBackupRunsService. this.sqlBackupRunsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlBackupRunsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlBackupRunsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlBackupRunsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlBackupRunsServiceStubMethods = - ['delete', 'get', 'insert', 'list']; + const sqlBackupRunsServiceStubMethods = ['delete', 'get', 'insert', 'list']; for (const methodName of sqlBackupRunsServiceStubMethods) { const callPromise = this.sqlBackupRunsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +297,14 @@ export class SqlBackupRunsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +315,14 @@ export class SqlBackupRunsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +355,7 @@ export class SqlBackupRunsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +365,9 @@ export class SqlBackupRunsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,413 +378,549 @@ export class SqlBackupRunsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes the backup taken by a backup run. - * - * @param {Object} request - * The request object that will be sent. - * @param {number} request.id - * The ID of the backup run to delete. To find a backup run ID, use the - * [list](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1/backupRuns/list) - * method. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_backup_runs_service.delete.js - * region_tag:sqladmin_v1_generated_SqlBackupRunsService_Delete_async - */ + /** + * Deletes the backup taken by a backup run. + * + * @param {Object} request + * The request object that will be sent. + * @param {number} request.id + * The ID of the backup run to delete. To find a backup run ID, use the + * [list](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1/backupRuns/list) + * method. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_backup_runs_service.delete.js + * region_tag:sqladmin_v1_generated_SqlBackupRunsService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'id': request.id?.toString() ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + id: request.id?.toString() ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a resource containing information about a backup run. - * - * @param {Object} request - * The request object that will be sent. - * @param {number} request.id - * The ID of this backup run. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.BackupRun|BackupRun}. - * 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/sql_backup_runs_service.get.js - * region_tag:sqladmin_v1_generated_SqlBackupRunsService_Get_async - */ + /** + * Retrieves a resource containing information about a backup run. + * + * @param {Object} request + * The request object that will be sent. + * @param {number} request.id + * The ID of this backup run. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.BackupRun|BackupRun}. + * 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/sql_backup_runs_service.get.js + * region_tag:sqladmin_v1_generated_SqlBackupRunsService_Get_async + */ get( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackupRun, + protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IBackupRun, + protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, - callback: Callback< - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, + callback: Callback< + protos.google.cloud.sql.v1.IBackupRun, + protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IBackupRun, + protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackupRun, + protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'id': request.id?.toString() ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + id: request.id?.toString() ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IBackupRun, + | protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IBackupRun, - protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IBackupRun, + protos.google.cloud.sql.v1.ISqlBackupRunsGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Creates a new backup run on demand. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.BackupRun} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_backup_runs_service.insert.js - * region_tag:sqladmin_v1_generated_SqlBackupRunsService_Insert_async - */ + /** + * Creates a new backup run on demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.BackupRun} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_backup_runs_service.insert.js + * region_tag:sqladmin_v1_generated_SqlBackupRunsService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlBackupRunsInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists all backup runs associated with the project or a given instance - * and configuration in the reverse chronological order of the backup - * initiation time. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID, or "-" for all instances. This does not include - * the project ID. - * @param {number} request.maxResults - * Maximum number of backup runs per response. - * @param {string} request.pageToken - * A previously-returned page token representing part of the larger set of - * results to view. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.BackupRunsListResponse|BackupRunsListResponse}. - * 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/sql_backup_runs_service.list.js - * region_tag:sqladmin_v1_generated_SqlBackupRunsService_List_async - */ + /** + * Lists all backup runs associated with the project or a given instance + * and configuration in the reverse chronological order of the backup + * initiation time. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID, or "-" for all instances. This does not include + * the project ID. + * @param {number} request.maxResults + * Maximum number of backup runs per response. + * @param {string} request.pageToken + * A previously-returned page token representing part of the larger set of + * results to view. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.BackupRunsListResponse|BackupRunsListResponse}. + * 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/sql_backup_runs_service.list.js + * region_tag:sqladmin_v1_generated_SqlBackupRunsService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackupRunsListResponse, + protos.google.cloud.sql.v1.ISqlBackupRunsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IBackupRunsListResponse, + protos.google.cloud.sql.v1.ISqlBackupRunsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, - callback: Callback< - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, + callback: Callback< + protos.google.cloud.sql.v1.IBackupRunsListResponse, + protos.google.cloud.sql.v1.ISqlBackupRunsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlBackupRunsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IBackupRunsListResponse, + protos.google.cloud.sql.v1.ISqlBackupRunsListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackupRunsListResponse, + protos.google.cloud.sql.v1.ISqlBackupRunsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IBackupRunsListResponse, + | protos.google.cloud.sql.v1.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IBackupRunsListResponse, - protos.google.cloud.sql.v1.ISqlBackupRunsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IBackupRunsListResponse, + protos.google.cloud.sql.v1.ISqlBackupRunsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -775,12 +955,11 @@ export class SqlBackupRunsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -813,7 +992,7 @@ export class SqlBackupRunsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -829,7 +1008,7 @@ export class SqlBackupRunsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -866,13 +1045,15 @@ export class SqlBackupRunsServiceClient { */ close(): Promise { if (this.sqlBackupRunsServiceStub && !this._terminated) { - return this.sqlBackupRunsServiceStub.then(stub => { + return this.sqlBackupRunsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_backups_service_client.ts b/packages/google-cloud-sql/src/v1/sql_backups_service_client.ts index e564a09bad51..1931f7ec4f63 100644 --- a/packages/google-cloud-sql/src/v1/sql_backups_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_backups_service_client.ts @@ -18,11 +18,20 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, LocationsClient, LocationProtos} from 'google-gax'; -import {Transform} from 'stream'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + PaginationCallback, + GaxCall, + 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'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +52,7 @@ export class SqlBackupsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +65,10 @@ export class SqlBackupsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlBackupsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlBackupsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlBackupsServiceClient. @@ -100,21 +109,42 @@ export class SqlBackupsServiceClient { * const client = new SqlBackupsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlBackupsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +169,7 @@ export class SqlBackupsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +183,11 @@ export class SqlBackupsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,10 +209,10 @@ export class SqlBackupsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; @@ -194,14 +220,20 @@ export class SqlBackupsServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this.descriptors.page = { - listBackups: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'backups') + listBackups: new this._gaxModule.PageDescriptor( + 'pageToken', + 'nextPageToken', + 'backups', + ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlBackupsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlBackupsService', + 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 @@ -232,37 +264,46 @@ export class SqlBackupsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlBackupsService. this.sqlBackupsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlBackupsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlBackupsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlBackupsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlBackupsServiceStubMethods = - ['createBackup', 'getBackup', 'listBackups', 'updateBackup', 'deleteBackup']; + const sqlBackupsServiceStubMethods = [ + 'createBackup', + 'getBackup', + 'listBackups', + 'updateBackup', + 'deleteBackup', + ]; for (const methodName of sqlBackupsServiceStubMethods) { const callPromise = this.sqlBackupsServiceStub.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) => () => { + (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 descriptor = this.descriptors.page[methodName] || undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -277,8 +318,14 @@ export class SqlBackupsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -289,8 +336,14 @@ export class SqlBackupsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -323,7 +376,7 @@ export class SqlBackupsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -333,8 +386,9 @@ export class SqlBackupsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -345,490 +399,625 @@ export class SqlBackupsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Creates a backup for a Cloud SQL instance. This API can be used only to - * create on-demand backups. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource where this backup is created. - * Format: projects/{project} - * @param {google.cloud.sql.v1.Backup} request.backup - * Required. The Backup to create. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_backups_service.create_backup.js - * region_tag:sqladmin_v1_generated_SqlBackupsService_CreateBackup_async - */ + /** + * Creates a backup for a Cloud SQL instance. This API can be used only to + * create on-demand backups. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent resource where this backup is created. + * Format: projects/{project} + * @param {google.cloud.sql.v1.Backup} request.backup + * Required. The Backup to create. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_backups_service.create_backup.js + * region_tag:sqladmin_v1_generated_SqlBackupsService_CreateBackup_async + */ createBackup( - request?: protos.google.cloud.sql.v1.ICreateBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ICreateBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | undefined, + {} | undefined, + ] + >; createBackup( - request: protos.google.cloud.sql.v1.ICreateBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ICreateBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; createBackup( - request: protos.google.cloud.sql.v1.ICreateBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ICreateBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; createBackup( - request?: protos.google.cloud.sql.v1.ICreateBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ICreateBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'parent': request.parent ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('createBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('createBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.createBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ICreateBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('createBackup 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); + return this.innerApiCalls + .createBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ICreateBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('createBackup 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; }); } -/** - * Retrieves a resource containing information about a backup. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the backup to retrieve. - * Format: projects/{project}/backups/{backup} - * @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.cloud.sql.v1.Backup|Backup}. - * 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/sql_backups_service.get_backup.js - * region_tag:sqladmin_v1_generated_SqlBackupsService_GetBackup_async - */ + /** + * Retrieves a resource containing information about a backup. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the backup to retrieve. + * Format: projects/{project}/backups/{backup} + * @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.cloud.sql.v1.Backup|Backup}. + * 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/sql_backups_service.get_backup.js + * region_tag:sqladmin_v1_generated_SqlBackupsService_GetBackup_async + */ getBackup( - request?: protos.google.cloud.sql.v1.IGetBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.IGetBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | undefined, + {} | undefined, + ] + >; getBackup( - request: protos.google.cloud.sql.v1.IGetBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IGetBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; getBackup( - request: protos.google.cloud.sql.v1.IGetBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IGetBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; getBackup( - request?: protos.google.cloud.sql.v1.IGetBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.IGetBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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 ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IBackup, - protos.google.cloud.sql.v1.IGetBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('getBackup 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); + return this.innerApiCalls + .getBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IBackup, + protos.google.cloud.sql.v1.IGetBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('getBackup 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; }); } -/** - * Updates the retention period and description of the backup. You can use - * this API to update final backups only. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.cloud.sql.v1.Backup} request.backup - * Required. The backup to update. - * The backup’s `name` field is used to identify the backup to update. - * Format: projects/{project}/backups/{backup} - * @param {google.protobuf.FieldMask} request.updateMask - * The list of fields that you can update. You can update only the description - * and retention period of the final backup. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_backups_service.update_backup.js - * region_tag:sqladmin_v1_generated_SqlBackupsService_UpdateBackup_async - */ + /** + * Updates the retention period and description of the backup. You can use + * this API to update final backups only. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.cloud.sql.v1.Backup} request.backup + * Required. The backup to update. + * The backup’s `name` field is used to identify the backup to update. + * Format: projects/{project}/backups/{backup} + * @param {google.protobuf.FieldMask} request.updateMask + * The list of fields that you can update. You can update only the description + * and retention period of the final backup. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_backups_service.update_backup.js + * region_tag:sqladmin_v1_generated_SqlBackupsService_UpdateBackup_async + */ updateBackup( - request?: protos.google.cloud.sql.v1.IUpdateBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.IUpdateBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | undefined, + {} | undefined, + ] + >; updateBackup( - request: protos.google.cloud.sql.v1.IUpdateBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IUpdateBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; updateBackup( - request: protos.google.cloud.sql.v1.IUpdateBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IUpdateBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; updateBackup( - request?: protos.google.cloud.sql.v1.IUpdateBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.IUpdateBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'backup.name': request.backup!.name ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + 'backup.name': request.backup!.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('updateBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('updateBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.updateBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IUpdateBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('updateBackup 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); + return this.innerApiCalls + .updateBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IUpdateBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('updateBackup 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; }); } -/** - * Deletes the backup. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the backup to delete. - * Format: projects/{project}/backups/{backup} - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_backups_service.delete_backup.js - * region_tag:sqladmin_v1_generated_SqlBackupsService_DeleteBackup_async - */ + /** + * Deletes the backup. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the backup to delete. + * Format: projects/{project}/backups/{backup} + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_backups_service.delete_backup.js + * region_tag:sqladmin_v1_generated_SqlBackupsService_DeleteBackup_async + */ deleteBackup( - request?: protos.google.cloud.sql.v1.IDeleteBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.IDeleteBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | undefined, + {} | undefined, + ] + >; deleteBackup( - request: protos.google.cloud.sql.v1.IDeleteBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IDeleteBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; deleteBackup( - request: protos.google.cloud.sql.v1.IDeleteBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IDeleteBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; deleteBackup( - request?: protos.google.cloud.sql.v1.IDeleteBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.IDeleteBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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 ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('deleteBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('deleteBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.deleteBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.IDeleteBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('deleteBackup 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); + return this.innerApiCalls + .deleteBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.IDeleteBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('deleteBackup 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; }); } - /** - * Lists all backups associated with the project. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent that owns this collection of backups. - * Format: projects/{project} - * @param {number} request.pageSize - * The maximum number of backups to return per response. The service might - * return fewer backups than this value. If a value for this parameter isn't - * specified, then, at most, 500 backups are returned. The maximum value is - * 2,000. Any values that you set, which are greater than 2,000, are changed - * to 2,000. - * @param {string} request.pageToken - * A page token, received from a previous `ListBackups` call. - * Provide this to retrieve the subsequent page. - * - * When paginating, all other parameters provided to `ListBackups` must match - * the call that provided the page token. - * @param {string} request.filter - * Multiple filter queries are separated by spaces. For example, - * 'instance:abc AND type:FINAL, 'location:us', - * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by - * type, instance, backupInterval.startTime (creation time), or 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 Array of {@link protos.google.cloud.sql.v1.Backup|Backup}. - * 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 `listBackupsAsync()` - * 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. - */ + /** + * Lists all backups associated with the project. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent that owns this collection of backups. + * Format: projects/{project} + * @param {number} request.pageSize + * The maximum number of backups to return per response. The service might + * return fewer backups than this value. If a value for this parameter isn't + * specified, then, at most, 500 backups are returned. The maximum value is + * 2,000. Any values that you set, which are greater than 2,000, are changed + * to 2,000. + * @param {string} request.pageToken + * A page token, received from a previous `ListBackups` call. + * Provide this to retrieve the subsequent page. + * + * When paginating, all other parameters provided to `ListBackups` must match + * the call that provided the page token. + * @param {string} request.filter + * Multiple filter queries are separated by spaces. For example, + * 'instance:abc AND type:FINAL, 'location:us', + * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by + * type, instance, backupInterval.startTime (creation time), or 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 Array of {@link protos.google.cloud.sql.v1.Backup|Backup}. + * 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 `listBackupsAsync()` + * 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. + */ listBackups( - request?: protos.google.cloud.sql.v1.IListBackupsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IBackup[], - protos.google.cloud.sql.v1.IListBackupsRequest|null, - protos.google.cloud.sql.v1.IListBackupsResponse - ]>; + request?: protos.google.cloud.sql.v1.IListBackupsRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackup[], + protos.google.cloud.sql.v1.IListBackupsRequest | null, + protos.google.cloud.sql.v1.IListBackupsResponse, + ] + >; listBackups( - request: protos.google.cloud.sql.v1.IListBackupsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.sql.v1.IListBackupsRequest, - protos.google.cloud.sql.v1.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1.IBackup>): void; + request: protos.google.cloud.sql.v1.IListBackupsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.sql.v1.IListBackupsRequest, + protos.google.cloud.sql.v1.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1.IBackup + >, + ): void; listBackups( - request: protos.google.cloud.sql.v1.IListBackupsRequest, - callback: PaginationCallback< - protos.google.cloud.sql.v1.IListBackupsRequest, - protos.google.cloud.sql.v1.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1.IBackup>): void; + request: protos.google.cloud.sql.v1.IListBackupsRequest, + callback: PaginationCallback< + protos.google.cloud.sql.v1.IListBackupsRequest, + protos.google.cloud.sql.v1.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1.IBackup + >, + ): void; listBackups( - request?: protos.google.cloud.sql.v1.IListBackupsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.cloud.sql.v1.IListBackupsRequest, - protos.google.cloud.sql.v1.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1.IBackup>, - callback?: PaginationCallback< + request?: protos.google.cloud.sql.v1.IListBackupsRequest, + optionsOrCallback?: + | CallOptions + | PaginationCallback< protos.google.cloud.sql.v1.IListBackupsRequest, - protos.google.cloud.sql.v1.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1.IBackup>): - Promise<[ - protos.google.cloud.sql.v1.IBackup[], - protos.google.cloud.sql.v1.IListBackupsRequest|null, - protos.google.cloud.sql.v1.IListBackupsResponse - ]>|void { + protos.google.cloud.sql.v1.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1.IBackup + >, + callback?: PaginationCallback< + protos.google.cloud.sql.v1.IListBackupsRequest, + protos.google.cloud.sql.v1.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1.IBackup + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IBackup[], + protos.google.cloud.sql.v1.IListBackupsRequest | null, + protos.google.cloud.sql.v1.IListBackupsResponse, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'parent': request.parent ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); - const wrappedCallback: PaginationCallback< - protos.google.cloud.sql.v1.IListBackupsRequest, - protos.google.cloud.sql.v1.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1.IBackup>|undefined = callback + const wrappedCallback: + | PaginationCallback< + protos.google.cloud.sql.v1.IListBackupsRequest, + protos.google.cloud.sql.v1.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1.IBackup + > + | undefined = callback ? (error, values, nextPageRequest, rawResponse) => { this._log.info('listBackups values %j', values); callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. @@ -837,137 +1026,142 @@ export class SqlBackupsServiceClient { this._log.info('listBackups request %j', request); return this.innerApiCalls .listBackups(request, options, wrappedCallback) - ?.then(([response, input, output]: [ - protos.google.cloud.sql.v1.IBackup[], - protos.google.cloud.sql.v1.IListBackupsRequest|null, - protos.google.cloud.sql.v1.IListBackupsResponse - ]) => { - this._log.info('listBackups values %j', response); - return [response, input, output]; - }); + ?.then( + ([response, input, output]: [ + protos.google.cloud.sql.v1.IBackup[], + protos.google.cloud.sql.v1.IListBackupsRequest | null, + protos.google.cloud.sql.v1.IListBackupsResponse, + ]) => { + this._log.info('listBackups values %j', response); + return [response, input, output]; + }, + ); } -/** - * Equivalent to `listBackups`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent that owns this collection of backups. - * Format: projects/{project} - * @param {number} request.pageSize - * The maximum number of backups to return per response. The service might - * return fewer backups than this value. If a value for this parameter isn't - * specified, then, at most, 500 backups are returned. The maximum value is - * 2,000. Any values that you set, which are greater than 2,000, are changed - * to 2,000. - * @param {string} request.pageToken - * A page token, received from a previous `ListBackups` call. - * Provide this to retrieve the subsequent page. - * - * When paginating, all other parameters provided to `ListBackups` must match - * the call that provided the page token. - * @param {string} request.filter - * Multiple filter queries are separated by spaces. For example, - * 'instance:abc AND type:FINAL, 'location:us', - * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by - * type, instance, backupInterval.startTime (creation time), or location. - * @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.sql.v1.Backup|Backup} 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 `listBackupsAsync()` - * 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. - */ + /** + * Equivalent to `listBackups`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent that owns this collection of backups. + * Format: projects/{project} + * @param {number} request.pageSize + * The maximum number of backups to return per response. The service might + * return fewer backups than this value. If a value for this parameter isn't + * specified, then, at most, 500 backups are returned. The maximum value is + * 2,000. Any values that you set, which are greater than 2,000, are changed + * to 2,000. + * @param {string} request.pageToken + * A page token, received from a previous `ListBackups` call. + * Provide this to retrieve the subsequent page. + * + * When paginating, all other parameters provided to `ListBackups` must match + * the call that provided the page token. + * @param {string} request.filter + * Multiple filter queries are separated by spaces. For example, + * 'instance:abc AND type:FINAL, 'location:us', + * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by + * type, instance, backupInterval.startTime (creation time), or location. + * @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.sql.v1.Backup|Backup} 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 `listBackupsAsync()` + * 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. + */ listBackupsStream( - request?: protos.google.cloud.sql.v1.IListBackupsRequest, - options?: CallOptions): - Transform{ + request?: protos.google.cloud.sql.v1.IListBackupsRequest, + 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({ - 'parent': request.parent ?? '', - }); + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); const defaultCallSettings = this._defaults['listBackups']; const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => {throw err}); + this.initialize().catch((err) => { + throw err; + }); this._log.info('listBackups stream %j', request); return this.descriptors.page.listBackups.createStream( this.innerApiCalls.listBackups as GaxCall, request, - callSettings + callSettings, ); } -/** - * Equivalent to `listBackups`, 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.parent - * Required. The parent that owns this collection of backups. - * Format: projects/{project} - * @param {number} request.pageSize - * The maximum number of backups to return per response. The service might - * return fewer backups than this value. If a value for this parameter isn't - * specified, then, at most, 500 backups are returned. The maximum value is - * 2,000. Any values that you set, which are greater than 2,000, are changed - * to 2,000. - * @param {string} request.pageToken - * A page token, received from a previous `ListBackups` call. - * Provide this to retrieve the subsequent page. - * - * When paginating, all other parameters provided to `ListBackups` must match - * the call that provided the page token. - * @param {string} request.filter - * Multiple filter queries are separated by spaces. For example, - * 'instance:abc AND type:FINAL, 'location:us', - * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by - * type, instance, backupInterval.startTime (creation time), or location. - * @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.sql.v1.Backup|Backup}. 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/sql_backups_service.list_backups.js - * region_tag:sqladmin_v1_generated_SqlBackupsService_ListBackups_async - */ + /** + * Equivalent to `listBackups`, 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.parent + * Required. The parent that owns this collection of backups. + * Format: projects/{project} + * @param {number} request.pageSize + * The maximum number of backups to return per response. The service might + * return fewer backups than this value. If a value for this parameter isn't + * specified, then, at most, 500 backups are returned. The maximum value is + * 2,000. Any values that you set, which are greater than 2,000, are changed + * to 2,000. + * @param {string} request.pageToken + * A page token, received from a previous `ListBackups` call. + * Provide this to retrieve the subsequent page. + * + * When paginating, all other parameters provided to `ListBackups` must match + * the call that provided the page token. + * @param {string} request.filter + * Multiple filter queries are separated by spaces. For example, + * 'instance:abc AND type:FINAL, 'location:us', + * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by + * type, instance, backupInterval.startTime (creation time), or location. + * @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.sql.v1.Backup|Backup}. 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/sql_backups_service.list_backups.js + * region_tag:sqladmin_v1_generated_SqlBackupsService_ListBackups_async + */ listBackupsAsync( - request?: protos.google.cloud.sql.v1.IListBackupsRequest, - options?: CallOptions): - AsyncIterable{ + request?: protos.google.cloud.sql.v1.IListBackupsRequest, + 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({ - 'parent': request.parent ?? '', - }); + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); const defaultCallSettings = this._defaults['listBackups']; const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => {throw err}); + this.initialize().catch((err) => { + throw err; + }); this._log.info('listBackups iterate %j', request); return this.descriptors.page.listBackups.asyncIterate( this.innerApiCalls['listBackups'] as GaxCall, request as {}, - callSettings + callSettings, ) as AsyncIterable; } -/** + + /** * Gets information about a location. * * @param {Object} request @@ -1002,12 +1196,11 @@ export class SqlBackupsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -1040,7 +1233,7 @@ export class SqlBackupsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -1056,7 +1249,7 @@ export class SqlBackupsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -1091,7 +1284,7 @@ export class SqlBackupsServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -1116,13 +1309,15 @@ export class SqlBackupsServiceClient { */ close(): Promise { if (this.sqlBackupsServiceStub && !this._terminated) { - return this.sqlBackupsServiceStub.then(stub => { + return this.sqlBackupsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_connect_service_client.ts b/packages/google-cloud-sql/src/v1/sql_connect_service_client.ts index 6c84fc9a1284..55bcc54b96ae 100644 --- a/packages/google-cloud-sql/src/v1/sql_connect_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_connect_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlConnectServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlConnectServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlConnectServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlConnectServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlConnectServiceClient. @@ -101,21 +108,42 @@ export class SqlConnectServiceClient { * const client = new SqlConnectServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlConnectServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlConnectServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlConnectServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlConnectServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlConnectService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlConnectService', + 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 @@ -222,36 +249,43 @@ export class SqlConnectServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlConnectService. this.sqlConnectServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlConnectService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlConnectService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlConnectService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlConnectServiceStubMethods = - ['getConnectSettings', 'generateEphemeralCert']; + const sqlConnectServiceStubMethods = [ + 'getConnectSettings', + 'generateEphemeralCert', + ]; for (const methodName of sqlConnectServiceStubMethods) { const callPromise = this.sqlConnectServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +300,14 @@ export class SqlConnectServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +318,14 @@ export class SqlConnectServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +358,7 @@ export class SqlConnectServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +368,9 @@ export class SqlConnectServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,217 +381,291 @@ export class SqlConnectServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Retrieves connect settings about a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.protobuf.Timestamp} [request.readTime] - * Optional. Optional snapshot read timestamp to trade freshness for - * performance. - * @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.cloud.sql.v1.ConnectSettings|ConnectSettings}. - * 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/sql_connect_service.get_connect_settings.js - * region_tag:sqladmin_v1_generated_SqlConnectService_GetConnectSettings_async - */ + /** + * Retrieves connect settings about a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.protobuf.Timestamp} [request.readTime] + * Optional. Optional snapshot read timestamp to trade freshness for + * performance. + * @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.cloud.sql.v1.ConnectSettings|ConnectSettings}. + * 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/sql_connect_service.get_connect_settings.js + * region_tag:sqladmin_v1_generated_SqlConnectService_GetConnectSettings_async + */ getConnectSettings( - request?: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IConnectSettings, + protos.google.cloud.sql.v1.IGetConnectSettingsRequest | undefined, + {} | undefined, + ] + >; getConnectSettings( - request: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IConnectSettings, + protos.google.cloud.sql.v1.IGetConnectSettingsRequest | null | undefined, + {} | null | undefined + >, + ): void; getConnectSettings( - request: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, - callback: Callback< - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, + callback: Callback< + protos.google.cloud.sql.v1.IConnectSettings, + protos.google.cloud.sql.v1.IGetConnectSettingsRequest | null | undefined, + {} | null | undefined + >, + ): void; getConnectSettings( - request?: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.IGetConnectSettingsRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IConnectSettings, + protos.google.cloud.sql.v1.IGetConnectSettingsRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IConnectSettings, + protos.google.cloud.sql.v1.IGetConnectSettingsRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getConnectSettings request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IConnectSettings, + | protos.google.cloud.sql.v1.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getConnectSettings response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getConnectSettings(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IConnectSettings, - protos.google.cloud.sql.v1.IGetConnectSettingsRequest|undefined, - {}|undefined - ]) => { - this._log.info('getConnectSettings 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); + return this.innerApiCalls + .getConnectSettings(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IConnectSettings, + protos.google.cloud.sql.v1.IGetConnectSettingsRequest | undefined, + {} | undefined, + ]) => { + this._log.info('getConnectSettings 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; }); } -/** - * Generates a short-lived X509 certificate containing the provided public key - * and signed by a private key specific to the target instance. Users may use - * the certificate to authenticate as themselves when connecting to the - * database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.publicKey - * PEM encoded public key to include in the signed certificate. - * @param {string} [request.accessToken] - * Optional. Access token to include in the signed certificate. - * @param {google.protobuf.Timestamp} [request.readTime] - * Optional. Optional snapshot read timestamp to trade freshness for - * performance. - * @param {google.protobuf.Duration} [request.validDuration] - * Optional. If set, it will contain the cert valid duration. - * @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.cloud.sql.v1.GenerateEphemeralCertResponse|GenerateEphemeralCertResponse}. - * 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/sql_connect_service.generate_ephemeral_cert.js - * region_tag:sqladmin_v1_generated_SqlConnectService_GenerateEphemeralCert_async - */ + /** + * Generates a short-lived X509 certificate containing the provided public key + * and signed by a private key specific to the target instance. Users may use + * the certificate to authenticate as themselves when connecting to the + * database. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.publicKey + * PEM encoded public key to include in the signed certificate. + * @param {string} [request.accessToken] + * Optional. Access token to include in the signed certificate. + * @param {google.protobuf.Timestamp} [request.readTime] + * Optional. Optional snapshot read timestamp to trade freshness for + * performance. + * @param {google.protobuf.Duration} [request.validDuration] + * Optional. If set, it will contain the cert valid duration. + * @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.cloud.sql.v1.GenerateEphemeralCertResponse|GenerateEphemeralCertResponse}. + * 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/sql_connect_service.generate_ephemeral_cert.js + * region_tag:sqladmin_v1_generated_SqlConnectService_GenerateEphemeralCert_async + */ generateEphemeralCert( - request?: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest | undefined, + {} | undefined, + ] + >; generateEphemeralCert( - request: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; generateEphemeralCert( - request: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, - callback: Callback< - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, + callback: Callback< + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; generateEphemeralCert( - request?: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('generateEphemeralCert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('generateEphemeralCert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.generateEphemeralCert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest|undefined, - {}|undefined - ]) => { - this._log.info('generateEphemeralCert 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); + return this.innerApiCalls + .generateEphemeralCert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse, + protos.google.cloud.sql.v1.IGenerateEphemeralCertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('generateEphemeralCert 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -579,12 +700,11 @@ export class SqlConnectServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -617,7 +737,7 @@ export class SqlConnectServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -633,7 +753,7 @@ export class SqlConnectServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -670,13 +790,15 @@ export class SqlConnectServiceClient { */ close(): Promise { if (this.sqlConnectServiceStub && !this._terminated) { - return this.sqlConnectServiceStub.then(stub => { + return this.sqlConnectServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_databases_service_client.ts b/packages/google-cloud-sql/src/v1/sql_databases_service_client.ts index 999cef663be5..6b679b46644a 100644 --- a/packages/google-cloud-sql/src/v1/sql_databases_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_databases_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlDatabasesServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlDatabasesServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlDatabasesServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlDatabasesServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlDatabasesServiceClient. @@ -101,21 +108,42 @@ export class SqlDatabasesServiceClient { * const client = new SqlDatabasesServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlDatabasesServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlDatabasesServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlDatabasesServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlDatabasesServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlDatabasesService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlDatabasesService', + 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 @@ -222,36 +249,47 @@ export class SqlDatabasesServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlDatabasesService. this.sqlDatabasesServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlDatabasesService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlDatabasesService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlDatabasesService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlDatabasesServiceStubMethods = - ['delete', 'get', 'insert', 'list', 'patch', 'update']; + const sqlDatabasesServiceStubMethods = [ + 'delete', + 'get', + 'insert', + 'list', + 'patch', + 'update', + ]; for (const methodName of sqlDatabasesServiceStubMethods) { const callPromise = this.sqlDatabasesServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +304,14 @@ export class SqlDatabasesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +322,14 @@ export class SqlDatabasesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +362,7 @@ export class SqlDatabasesServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +372,9 @@ export class SqlDatabasesServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,611 +385,811 @@ export class SqlDatabasesServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes a database from a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database to be deleted in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_databases_service.delete.js - * region_tag:sqladmin_v1_generated_SqlDatabasesService_Delete_async - */ + /** + * Deletes a database from a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database to be deleted in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_databases_service.delete.js + * region_tag:sqladmin_v1_generated_SqlDatabasesService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a resource containing information about a database inside a Cloud - * SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Database|Database}. - * 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/sql_databases_service.get.js - * region_tag:sqladmin_v1_generated_SqlDatabasesService_Get_async - */ + /** + * Retrieves a resource containing information about a database inside a Cloud + * SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Database|Database}. + * 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/sql_databases_service.get.js + * region_tag:sqladmin_v1_generated_SqlDatabasesService_Get_async + */ get( - request?: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, - callback: Callback< - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, + callback: Callback< + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlDatabasesGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IDatabase, - protos.google.cloud.sql.v1.ISqlDatabasesGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IDatabase, + protos.google.cloud.sql.v1.ISqlDatabasesGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Inserts a resource containing information about a database inside a Cloud - * SQL instance. - * - * **Note:** You can't modify the default character set and collation. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.Database} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_databases_service.insert.js - * region_tag:sqladmin_v1_generated_SqlDatabasesService_Insert_async - */ + /** + * Inserts a resource containing information about a database inside a Cloud + * SQL instance. + * + * **Note:** You can't modify the default character set and collation. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.Database} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_databases_service.insert.js + * region_tag:sqladmin_v1_generated_SqlDatabasesService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists databases in the specified Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.DatabasesListResponse|DatabasesListResponse}. - * 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/sql_databases_service.list.js - * region_tag:sqladmin_v1_generated_SqlDatabasesService_List_async - */ + /** + * Lists databases in the specified Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.DatabasesListResponse|DatabasesListResponse}. + * 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/sql_databases_service.list.js + * region_tag:sqladmin_v1_generated_SqlDatabasesService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IDatabasesListResponse, + protos.google.cloud.sql.v1.ISqlDatabasesListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IDatabasesListResponse, + protos.google.cloud.sql.v1.ISqlDatabasesListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, - callback: Callback< - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, + callback: Callback< + protos.google.cloud.sql.v1.IDatabasesListResponse, + protos.google.cloud.sql.v1.ISqlDatabasesListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlDatabasesListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IDatabasesListResponse, + protos.google.cloud.sql.v1.ISqlDatabasesListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IDatabasesListResponse, + protos.google.cloud.sql.v1.ISqlDatabasesListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IDatabasesListResponse, + | protos.google.cloud.sql.v1.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IDatabasesListResponse, - protos.google.cloud.sql.v1.ISqlDatabasesListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IDatabasesListResponse, + protos.google.cloud.sql.v1.ISqlDatabasesListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Partially updates a resource containing information about a database inside - * a Cloud SQL instance. This method supports patch semantics. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database to be updated in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.Database} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_databases_service.patch.js - * region_tag:sqladmin_v1_generated_SqlDatabasesService_Patch_async - */ + /** + * Partially updates a resource containing information about a database inside + * a Cloud SQL instance. This method supports patch semantics. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database to be updated in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.Database} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_databases_service.patch.js + * region_tag:sqladmin_v1_generated_SqlDatabasesService_Patch_async + */ patch( - request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + >; patch( - request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; patch( - request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; patch( - request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('patch request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('patch response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.patch(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('patch 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); + return this.innerApiCalls + .patch(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ]) => { + this._log.info('patch 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; }); } -/** - * Updates a resource containing information about a database inside a Cloud - * SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database to be updated in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.Database} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_databases_service.update.js - * region_tag:sqladmin_v1_generated_SqlDatabasesService_Update_async - */ + /** + * Updates a resource containing information about a database inside a Cloud + * SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database to be updated in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.Database} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_databases_service.update.js + * region_tag:sqladmin_v1_generated_SqlDatabasesService_Update_async + */ update( - request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + >; update( - request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('update request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('update response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.update(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('update 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); + return this.innerApiCalls + .update(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ]) => { + this._log.info('update 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -973,12 +1224,11 @@ export class SqlDatabasesServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -1011,7 +1261,7 @@ export class SqlDatabasesServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -1027,7 +1277,7 @@ export class SqlDatabasesServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -1064,13 +1314,15 @@ export class SqlDatabasesServiceClient { */ close(): Promise { if (this.sqlDatabasesServiceStub && !this._terminated) { - return this.sqlDatabasesServiceStub.then(stub => { + return this.sqlDatabasesServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_feature_eligibility_service_client.ts b/packages/google-cloud-sql/src/v1/sql_feature_eligibility_service_client.ts index 15082a1ebb78..55b053d0a121 100644 --- a/packages/google-cloud-sql/src/v1/sql_feature_eligibility_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_feature_eligibility_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlFeatureEligibilityServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlFeatureEligibilityServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlFeatureEligibilityServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlFeatureEligibilityServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlFeatureEligibilityServiceClient. @@ -101,21 +108,43 @@ export class SqlFeatureEligibilityServiceClient { * const client = new SqlFeatureEligibilityServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof SqlFeatureEligibilityServiceClient; - 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 staticMembers = this + .constructor as typeof SqlFeatureEligibilityServiceClient; + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +169,7 @@ export class SqlFeatureEligibilityServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +183,11 @@ export class SqlFeatureEligibilityServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +209,17 @@ export class SqlFeatureEligibilityServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlFeatureEligibilityService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlFeatureEligibilityService', + 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 @@ -222,11 +250,16 @@ export class SqlFeatureEligibilityServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlFeatureEligibilityService. this.sqlFeatureEligibilityServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlFeatureEligibilityService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.cloud.sql.v1.SqlFeatureEligibilityService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlFeatureEligibilityService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.cloud.sql.v1 + .SqlFeatureEligibilityService, + this._opts, + this._providedCustomServicePath, + ) as Promise<{ [method: string]: Function }>; return this.sqlFeatureEligibilityServiceStub; } @@ -237,8 +270,14 @@ export class SqlFeatureEligibilityServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -249,8 +288,14 @@ export class SqlFeatureEligibilityServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -290,8 +335,9 @@ export class SqlFeatureEligibilityServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -303,7 +349,7 @@ export class SqlFeatureEligibilityServiceClient { // -- Service calls -- // ------------------- -/** + /** * Gets information about a location. * * @param {Object} request @@ -338,12 +384,11 @@ export class SqlFeatureEligibilityServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -376,7 +421,7 @@ export class SqlFeatureEligibilityServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -392,7 +437,7 @@ export class SqlFeatureEligibilityServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -429,13 +474,15 @@ export class SqlFeatureEligibilityServiceClient { */ close(): Promise { if (this.sqlFeatureEligibilityServiceStub && !this._terminated) { - return this.sqlFeatureEligibilityServiceStub.then(stub => { + return this.sqlFeatureEligibilityServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_flags_service_client.ts b/packages/google-cloud-sql/src/v1/sql_flags_service_client.ts index deeadf3118b6..b30f40542afd 100644 --- a/packages/google-cloud-sql/src/v1/sql_flags_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_flags_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlFlagsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlFlagsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlFlagsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlFlagsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlFlagsServiceClient. @@ -101,21 +108,42 @@ export class SqlFlagsServiceClient { * const client = new SqlFlagsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlFlagsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlFlagsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlFlagsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlFlagsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlFlagsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlFlagsService', + 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 @@ -222,36 +249,40 @@ export class SqlFlagsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlFlagsService. this.sqlFlagsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlFlagsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlFlagsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlFlagsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlFlagsServiceStubMethods = - ['list']; + const sqlFlagsServiceStubMethods = ['list']; for (const methodName of sqlFlagsServiceStubMethods) { const callPromise = this.sqlFlagsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +297,14 @@ export class SqlFlagsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +315,14 @@ export class SqlFlagsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +355,7 @@ export class SqlFlagsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +365,9 @@ export class SqlFlagsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,101 +378,132 @@ export class SqlFlagsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Lists all available database flags for Cloud SQL instances. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.databaseVersion - * Database type and version you want to retrieve flags for. By default, this - * method returns flags for all database types and versions. - * @param {google.cloud.sql.v1.SqlFlagScope} [request.flagScope] - * Optional. Specify the scope of flags to be returned by SqlFlagsListService. - * Return list of database flags if unspecified. - * @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.cloud.sql.v1.FlagsListResponse|FlagsListResponse}. - * 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/sql_flags_service.list.js - * region_tag:sqladmin_v1_generated_SqlFlagsService_List_async - */ + /** + * Lists all available database flags for Cloud SQL instances. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.databaseVersion + * Database type and version you want to retrieve flags for. By default, this + * method returns flags for all database types and versions. + * @param {google.cloud.sql.v1.SqlFlagScope} [request.flagScope] + * Optional. Specify the scope of flags to be returned by SqlFlagsListService. + * Return list of database flags if unspecified. + * @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.cloud.sql.v1.FlagsListResponse|FlagsListResponse}. + * 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/sql_flags_service.list.js + * region_tag:sqladmin_v1_generated_SqlFlagsService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlFlagsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlFlagsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlFlagsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlFlagsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlFlagsListRequest, - callback: Callback< - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlFlagsListRequest, + callback: Callback< + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlFlagsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlFlagsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } else { options = optionsOrCallback as CallOptions; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - this.initialize().catch(err => {throw err}); + this.initialize().catch((err) => { + throw err; + }); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IFlagsListResponse, - protos.google.cloud.sql.v1.ISqlFlagsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IFlagsListResponse, + protos.google.cloud.sql.v1.ISqlFlagsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -463,12 +538,11 @@ export class SqlFlagsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -501,7 +575,7 @@ export class SqlFlagsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -517,7 +591,7 @@ export class SqlFlagsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -554,13 +628,15 @@ export class SqlFlagsServiceClient { */ close(): Promise { if (this.sqlFlagsServiceStub && !this._terminated) { - return this.sqlFlagsServiceStub.then(stub => { + return this.sqlFlagsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_instances_service_client.ts b/packages/google-cloud-sql/src/v1/sql_instances_service_client.ts index 754b0a26a55a..e4e372e22ccb 100644 --- a/packages/google-cloud-sql/src/v1/sql_instances_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_instances_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlInstancesServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlInstancesServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlInstancesServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlInstancesServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlInstancesServiceClient. @@ -100,21 +107,42 @@ export class SqlInstancesServiceClient { * const client = new SqlInstancesServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlInstancesServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlInstancesServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlInstancesServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlInstancesServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/locations/{location}/backupVaults/{backupvault}/dataSources/{datasource}/backups/{backup}' + 'projects/{project}/locations/{location}/backupVaults/{backupvault}/dataSources/{datasource}/backups/{backup}', ), networkPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/global/networks/{network}' + 'projects/{project}/global/networks/{network}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlInstancesService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlInstancesService', + 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 @@ -224,36 +251,84 @@ export class SqlInstancesServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlInstancesService. this.sqlInstancesServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlInstancesService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlInstancesService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlInstancesService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlInstancesServiceStubMethods = - ['addServerCa', 'addServerCertificate', 'addEntraIdCertificate', 'clone', 'delete', 'demoteMaster', 'demote', 'export', 'failover', 'reencrypt', 'get', 'import', 'insert', 'list', 'listServerCas', 'listServerCertificates', 'listEntraIdCertificates', 'patch', 'promoteReplica', 'switchover', 'resetSslConfig', 'restart', 'restoreBackup', 'rotateServerCa', 'rotateServerCertificate', 'rotateEntraIdCertificate', 'startReplica', 'stopReplica', 'truncateLog', 'update', 'createEphemeral', 'rescheduleMaintenance', 'verifyExternalSyncSettings', 'startExternalSync', 'performDiskShrink', 'getDiskShrinkConfig', 'resetReplicaSize', 'getLatestRecoveryTime', 'executeSql', 'acquireSsrsLease', 'releaseSsrsLease', 'preCheckMajorVersionUpgrade', 'pointInTimeRestore']; + const sqlInstancesServiceStubMethods = [ + 'addServerCa', + 'addServerCertificate', + 'addEntraIdCertificate', + 'clone', + 'delete', + 'demoteMaster', + 'demote', + 'export', + 'failover', + 'reencrypt', + 'get', + 'import', + 'insert', + 'list', + 'listServerCas', + 'listServerCertificates', + 'listEntraIdCertificates', + 'patch', + 'promoteReplica', + 'switchover', + 'resetSslConfig', + 'restart', + 'restoreBackup', + 'rotateServerCa', + 'rotateServerCertificate', + 'rotateEntraIdCertificate', + 'startReplica', + 'stopReplica', + 'truncateLog', + 'update', + 'createEphemeral', + 'rescheduleMaintenance', + 'verifyExternalSyncSettings', + 'startExternalSync', + 'performDiskShrink', + 'getDiskShrinkConfig', + 'resetReplicaSize', + 'getLatestRecoveryTime', + 'executeSql', + 'acquireSsrsLease', + 'releaseSsrsLease', + 'preCheckMajorVersionUpgrade', + 'pointInTimeRestore', + ]; for (const methodName of sqlInstancesServiceStubMethods) { const callPromise = this.sqlInstancesServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +343,14 @@ export class SqlInstancesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +361,14 @@ export class SqlInstancesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +401,7 @@ export class SqlInstancesServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +411,9 @@ export class SqlInstancesServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,4348 +424,6190 @@ export class SqlInstancesServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Adds a new trusted Certificate Authority (CA) version for the specified - * instance. Required to prepare for a certificate rotation. If a CA version - * was previously added but never used in a certificate rotation, this - * operation replaces that version. There cannot be more than one CA version - * waiting to be rotated in. For instances that have enabled Certificate - * Authority Service (CAS) based server CA, use AddServerCertificate to add a - * new server certificate. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.add_server_ca.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_AddServerCa_async - */ + /** + * Adds a new trusted Certificate Authority (CA) version for the specified + * instance. Required to prepare for a certificate rotation. If a CA version + * was previously added but never used in a certificate rotation, this + * operation replaces that version. There cannot be more than one CA version + * waiting to be rotated in. For instances that have enabled Certificate + * Authority Service (CAS) based server CA, use AddServerCertificate to add a + * new server certificate. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.add_server_ca.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_AddServerCa_async + */ addServerCa( - request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest | undefined, + {} | undefined, + ] + >; addServerCa( - request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCa( - request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCa( - request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('addServerCa request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('addServerCa response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.addServerCa(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest|undefined, - {}|undefined - ]) => { - this._log.info('addServerCa 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); + return this.innerApiCalls + .addServerCa(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('addServerCa 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; }); } -/** - * Add a new trusted server certificate version for the specified instance - * using Certificate Authority Service (CAS) server CA. Required to prepare - * for a certificate rotation. If a server certificate version was previously - * added but never used in a certificate rotation, this operation replaces - * that version. There cannot be more than one certificate version waiting to - * be rotated in. For instances not using CAS server CA, use AddServerCa - * instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.add_server_certificate.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_AddServerCertificate_async - */ + /** + * Add a new trusted server certificate version for the specified instance + * using Certificate Authority Service (CAS) server CA. Required to prepare + * for a certificate rotation. If a server certificate version was previously + * added but never used in a certificate rotation, this operation replaces + * that version. There cannot be more than one certificate version waiting to + * be rotated in. For instances not using CAS server CA, use AddServerCa + * instead. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.add_server_certificate.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_AddServerCertificate_async + */ addServerCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | undefined + ), + {} | undefined, + ] + >; addServerCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('addServerCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('addServerCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.addServerCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('addServerCertificate 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); + return this.innerApiCalls + .addServerCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddServerCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('addServerCertificate 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; }); } -/** - * Adds a new Entra ID certificate for the specified instance. If an Entra ID - * certificate was previously added but never used in a certificate rotation, - * this operation replaces that version. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.add_entra_id_certificate.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_AddEntraIdCertificate_async - */ + /** + * Adds a new Entra ID certificate for the specified instance. If an Entra ID + * certificate was previously added but never used in a certificate rotation, + * this operation replaces that version. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.add_entra_id_certificate.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_AddEntraIdCertificate_async + */ addEntraIdCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + >; addEntraIdCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addEntraIdCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addEntraIdCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('addEntraIdCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('addEntraIdCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.addEntraIdCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('addEntraIdCertificate 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); + return this.innerApiCalls + .addEntraIdCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAddEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('addEntraIdCertificate 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; }); } -/** - * Creates a Cloud SQL instance as a clone of the source instance. Using this - * operation might cause your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. The ID of the Cloud SQL instance to be cloned (source). This does - * not include the project ID. - * @param {string} request.project - * Required. Project ID of the source as well as the clone Cloud SQL instance. - * @param {google.cloud.sql.v1.InstancesCloneRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.clone.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Clone_async - */ + /** + * Creates a Cloud SQL instance as a clone of the source instance. Using this + * operation might cause your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. The ID of the Cloud SQL instance to be cloned (source). This does + * not include the project ID. + * @param {string} request.project + * Required. Project ID of the source Cloud SQL instance. + * @param {google.cloud.sql.v1.InstancesCloneRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.clone.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Clone_async + */ clone( - request?: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesCloneRequest | undefined, + {} | undefined, + ] + >; clone( - request: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesCloneRequest | null | undefined, + {} | null | undefined + >, + ): void; clone( - request: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesCloneRequest | null | undefined, + {} | null | undefined + >, + ): void; clone( - request?: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesCloneRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesCloneRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesCloneRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('clone request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('clone response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.clone(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesCloneRequest|undefined, - {}|undefined - ]) => { - this._log.info('clone 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); + return this.innerApiCalls + .clone(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesCloneRequest | undefined, + {} | undefined, + ]) => { + this._log.info('clone 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; }); } -/** - * Deletes a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance to be deleted. - * @param {boolean} request.enableFinalBackup - * Flag to opt-in for final backup. By default, it is turned off. - * @param {number} [request.finalBackupTtlDays] - * Optional. Retention period of the final backup. - * @param {google.protobuf.Timestamp} [request.finalBackupExpiryTime] - * Optional. Final Backup expiration time. - * Timestamp in UTC of when this resource is considered expired. - * @param {string} [request.finalBackupDescription] - * Optional. The description of the final backup. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.delete.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Delete_async - */ + /** + * Deletes a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance to be deleted. + * @param {boolean} request.enableFinalBackup + * Flag to opt-in for final backup. By default, it is turned off. + * @param {number} [request.finalBackupTtlDays] + * Optional. Retention period of the final backup. + * @param {google.protobuf.Timestamp} [request.finalBackupExpiryTime] + * Optional. Final Backup expiration time. + * Timestamp in UTC of when this resource is considered expired. + * @param {string} [request.finalBackupDescription] + * Optional. The description of the final backup. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.delete.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Demotes the stand-alone instance to be a Cloud SQL read replica for an - * external database server. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance name. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesDemoteMasterRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.demote_master.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_DemoteMaster_async - */ + /** + * Demotes the stand-alone instance to be a Cloud SQL read replica for an + * external database server. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance name. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesDemoteMasterRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.demote_master.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_DemoteMaster_async + */ demoteMaster( - request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest | undefined, + {} | undefined, + ] + >; demoteMaster( - request: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + ): void; demoteMaster( - request: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + ): void; demoteMaster( - request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('demoteMaster request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('demoteMaster response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.demoteMaster(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest|undefined, - {}|undefined - ]) => { - this._log.info('demoteMaster 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); + return this.innerApiCalls + .demoteMaster(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesDemoteMasterRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('demoteMaster 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; }); } -/** - * Demotes an existing standalone instance to be a Cloud SQL read replica - * for an external database server. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance name. - * @param {string} request.project - * Required. ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesDemoteRequest} request.body - * Required. The request body. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.demote.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Demote_async - */ - demote( - request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|undefined, {}|undefined - ]>; - demote( - request: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>): void; - demote( - request: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>): void; + /** + * Demotes an existing standalone instance to be a Cloud SQL read replica + * for an external database server. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance name. + * @param {string} request.project + * Required. ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesDemoteRequest} request.body + * Required. The request body. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.demote.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Demote_async + */ demote( - request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest | undefined, + {} | undefined, + ] + >; + demote( + request: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest | null | undefined, + {} | null | undefined + >, + ): void; + demote( + request: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest | null | undefined, + {} | null | undefined + >, + ): void; + demote( + request?: protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('demote request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('demote response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.demote(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest|undefined, - {}|undefined - ]) => { - this._log.info('demote 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); + return this.innerApiCalls + .demote(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesDemoteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('demote 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; }); } -/** - * Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL - * dump or CSV file. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance to be exported. - * @param {google.cloud.sql.v1.InstancesExportRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.export.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Export_async - */ + /** + * Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL + * dump or CSV file. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance to be exported. + * @param {google.cloud.sql.v1.InstancesExportRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.export.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Export_async + */ export( - request?: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesExportRequest | undefined, + {} | undefined, + ] + >; export( - request: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesExportRequest | null | undefined, + {} | null | undefined + >, + ): void; export( - request: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesExportRequest | null | undefined, + {} | null | undefined + >, + ): void; export( - request?: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesExportRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesExportRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesExportRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('export request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('export response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.export(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesExportRequest|undefined, - {}|undefined - ]) => { - this._log.info('export 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); + return this.innerApiCalls + .export(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesExportRequest | undefined, + {} | undefined, + ]) => { + this._log.info('export 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; }); } -/** - * Initiates a manual failover of a high availability (HA) primary instance - * to a standby instance, which becomes the primary instance. Users are - * then rerouted to the new primary. For more information, see the - * [Overview of high - * availability](https://cloud.google.com/sql/docs/mysql/high-availability) - * page in the Cloud SQL documentation. - * If using Legacy HA (MySQL only), this causes the instance to failover to - * its failover replica instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the read replica. - * @param {google.cloud.sql.v1.InstancesFailoverRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.failover.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Failover_async - */ + /** + * Initiates a manual failover of a high availability (HA) primary instance + * to a standby instance, which becomes the primary instance. Users are + * then rerouted to the new primary. For more information, see the + * [Overview of high + * availability](https://cloud.google.com/sql/docs/mysql/high-availability) + * page in the Cloud SQL documentation. + * If using Legacy HA (MySQL only), this causes the instance to failover to + * its failover replica instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the read replica. + * @param {google.cloud.sql.v1.InstancesFailoverRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.failover.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Failover_async + */ failover( - request?: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest | undefined, + {} | undefined, + ] + >; failover( - request: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; failover( - request: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; failover( - request?: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('failover request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('failover response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.failover(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest|undefined, - {}|undefined - ]) => { - this._log.info('failover 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); + return this.innerApiCalls + .failover(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesFailoverRequest | undefined, + {} | undefined, + ]) => { + this._log.info('failover 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; }); } -/** - * Reencrypt CMEK instance with latest key version. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesReencryptRequest} request.body - * Reencrypt body that users request - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.reencrypt.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Reencrypt_async - */ + /** + * Reencrypt CMEK instance with latest key version. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesReencryptRequest} request.body + * Reencrypt body that users request + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.reencrypt.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Reencrypt_async + */ reencrypt( - request?: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest | undefined, + {} | undefined, + ] + >; reencrypt( - request: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + ): void; reencrypt( - request: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + ): void; reencrypt( - request?: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('reencrypt request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('reencrypt response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.reencrypt(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest|undefined, - {}|undefined - ]) => { - this._log.info('reencrypt 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); + return this.innerApiCalls + .reencrypt(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesReencryptRequest | undefined, + {} | undefined, + ]) => { + this._log.info('reencrypt 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; }); } -/** - * Retrieves a resource containing information about a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Database instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1.DatabaseInstance|DatabaseInstance}. - * 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/sql_instances_service.get.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Get_async - */ + /** + * Retrieves a resource containing information about a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Database instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1.DatabaseInstance|DatabaseInstance}. + * 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/sql_instances_service.get.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Get_async + */ get( - request?: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, - callback: Callback< - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, + callback: Callback< + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IDatabaseInstance, - protos.google.cloud.sql.v1.ISqlInstancesGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IDatabaseInstance, + protos.google.cloud.sql.v1.ISqlInstancesGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Imports data into a Cloud SQL instance from a SQL dump or CSV file in - * Cloud Storage. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesImportRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.import.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Import_async - */ + /** + * Imports data into a Cloud SQL instance from a SQL dump or CSV file in + * Cloud Storage. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesImportRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.import.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Import_async + */ import( - request?: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesImportRequest | undefined, + {} | undefined, + ] + >; import( - request: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesImportRequest | null | undefined, + {} | null | undefined + >, + ): void; import( - request: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesImportRequest | null | undefined, + {} | null | undefined + >, + ): void; import( - request?: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesImportRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesImportRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesImportRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('import request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('import response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.import(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesImportRequest|undefined, - {}|undefined - ]) => { - this._log.info('import 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); + return this.innerApiCalls + .import(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesImportRequest | undefined, + {} | undefined, + ]) => { + this._log.info('import 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; }); } -/** - * Creates a new Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Project ID of the project to which the newly created Cloud SQL instances - * should belong. - * @param {google.cloud.sql.v1.DatabaseInstance} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.insert.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Insert_async - */ + /** + * Creates a new Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Project ID of the project to which the newly created Cloud SQL instances + * should belong. + * @param {google.cloud.sql.v1.DatabaseInstance} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.insert.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesInsertRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists instances under a given project. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.filter - * A filter expression that filters resources listed in the response. - * The expression is in the form of field:value. For example, - * 'instanceType:CLOUD_SQL_INSTANCE'. Fields can be nested as needed as per - * their JSON representation, such as 'settings.userLabels.auto_start:true'. - * - * Multiple filter queries are space-separated. For example. - * 'state:RUNNABLE instanceType:CLOUD_SQL_INSTANCE'. By default, each - * expression is an AND expression. However, you can include AND and OR - * expressions explicitly. - * @param {number} request.maxResults - * The maximum number of instances to return. The service may return fewer - * than this value. - * If unspecified, at most 500 instances are returned. - * The maximum value is 1000; values above 1000 are coerced to 1000. - * @param {string} request.pageToken - * A previously-returned page token representing part of the larger set of - * results to view. - * @param {string} request.project - * Project ID of the project for which to list Cloud SQL instances. - * @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.cloud.sql.v1.InstancesListResponse|InstancesListResponse}. - * 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/sql_instances_service.list.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_List_async - */ - list( - request?: protos.google.cloud.sql.v1.ISqlInstancesListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|undefined, {}|undefined - ]>; - list( - request: protos.google.cloud.sql.v1.ISqlInstancesListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>): void; + /** + * Lists instances under a given project. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.filter + * A filter expression that filters resources listed in the response. + * The expression is in the form of field:value. For example, + * 'instanceType:CLOUD_SQL_INSTANCE'. Fields can be nested as needed as per + * their JSON representation, such as 'settings.userLabels.auto_start:true'. + * + * Multiple filter queries are space-separated. For example. + * 'state:RUNNABLE instanceType:CLOUD_SQL_INSTANCE'. By default, each + * expression is an AND expression. However, you can include AND and OR + * expressions explicitly. + * @param {number} request.maxResults + * The maximum number of instances to return. The service may return fewer + * than this value. + * If unspecified, at most 500 instances are returned. + * The maximum value is 1000; values above 1000 are coerced to 1000. + * @param {string} request.pageToken + * A previously-returned page token representing part of the larger set of + * results to view. + * @param {string} request.project + * Project ID of the project for which to list Cloud SQL instances. + * @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.cloud.sql.v1.InstancesListResponse|InstancesListResponse}. + * 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/sql_instances_service.list.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_List_async + */ list( - request: protos.google.cloud.sql.v1.ISqlInstancesListRequest, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>): void; + request?: protos.google.cloud.sql.v1.ISqlInstancesListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListResponse, + protos.google.cloud.sql.v1.ISqlInstancesListRequest | undefined, + {} | undefined, + ] + >; list( - request?: protos.google.cloud.sql.v1.ISqlInstancesListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request: protos.google.cloud.sql.v1.ISqlInstancesListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListResponse, + protos.google.cloud.sql.v1.ISqlInstancesListRequest | null | undefined, + {} | null | undefined + >, + ): void; + list( + request: protos.google.cloud.sql.v1.ISqlInstancesListRequest, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListResponse, + protos.google.cloud.sql.v1.ISqlInstancesListRequest | null | undefined, + {} | null | undefined + >, + ): void; + list( + request?: protos.google.cloud.sql.v1.ISqlInstancesListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IInstancesListResponse, + protos.google.cloud.sql.v1.ISqlInstancesListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListResponse, + protos.google.cloud.sql.v1.ISqlInstancesListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IInstancesListResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IInstancesListResponse, - protos.google.cloud.sql.v1.ISqlInstancesListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IInstancesListResponse, + protos.google.cloud.sql.v1.ISqlInstancesListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Lists all of the trusted Certificate Authorities (CAs) for the specified - * instance. There can be up to three CAs listed: the CA that was used to sign - * the certificate that is currently in use, a CA that has been added but not - * yet used to sign a certificate, and a CA used to sign a certificate that - * has previously rotated out. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.InstancesListServerCasResponse|InstancesListServerCasResponse}. - * 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/sql_instances_service.list_server_cas.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ListServerCas_async - */ + /** + * Lists all of the trusted Certificate Authorities (CAs) for the specified + * instance. There can be up to three CAs listed: the CA that was used to sign + * the certificate that is currently in use, a CA that has been added but not + * yet used to sign a certificate, and a CA used to sign a certificate that + * has previously rotated out. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.InstancesListServerCasResponse|InstancesListServerCasResponse}. + * 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/sql_instances_service.list_server_cas.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ListServerCas_async + */ listServerCas( - request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest | undefined, + {} | undefined, + ] + >; listServerCas( - request: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCas( - request: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCas( - request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('listServerCas request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('listServerCas response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.listServerCas(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest|undefined, - {}|undefined - ]) => { - this._log.info('listServerCas 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); + return this.innerApiCalls + .listServerCas(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IInstancesListServerCasResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListServerCasRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('listServerCas 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; }); } -/** - * Lists all versions of server certificates and certificate authorities (CAs) - * for the specified instance. There can be up to three sets of certs listed: - * the certificate that is currently in use, a future that has been added but - * not yet used to sign a certificate, and a certificate that has been rotated - * out. For instances not using Certificate Authority Service (CAS) server CA, - * use ListServerCas instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1.InstancesListServerCertificatesResponse|InstancesListServerCertificatesResponse}. - * 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/sql_instances_service.list_server_certificates.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ListServerCertificates_async - */ + /** + * Lists all versions of server certificates and certificate authorities (CAs) + * for the specified instance. There can be up to three sets of certs listed: + * the certificate that is currently in use, a future that has been added but + * not yet used to sign a certificate, and a certificate that has been rotated + * out. For instances not using Certificate Authority Service (CAS) server CA, + * use ListServerCas instead. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1.InstancesListServerCertificatesResponse|InstancesListServerCertificatesResponse}. + * 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/sql_instances_service.list_server_certificates.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ListServerCertificates_async + */ listServerCertificates( - request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | undefined + ), + {} | undefined, + ] + >; listServerCertificates( - request: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCertificates( - request: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCertificates( - request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('listServerCertificates request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('listServerCertificates response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.listServerCertificates(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest|undefined, - {}|undefined - ]) => { - this._log.info('listServerCertificates 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); + return this.innerApiCalls + .listServerCertificates(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListServerCertificatesRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('listServerCertificates 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; }); } -/** - * Lists all versions of EntraID certificates for the specified instance. - * There can be up to three sets of certificates listed: the certificate that - * is currently in use, a future that has been added but not yet used to sign - * a certificate, and a certificate that has been rotated out. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1.InstancesListEntraIdCertificatesResponse|InstancesListEntraIdCertificatesResponse}. - * 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/sql_instances_service.list_entra_id_certificates.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ListEntraIdCertificates_async - */ + /** + * Lists all versions of EntraID certificates for the specified instance. + * There can be up to three sets of certificates listed: the certificate that + * is currently in use, a future that has been added but not yet used to sign + * a certificate, and a certificate that has been rotated out. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1.InstancesListEntraIdCertificatesResponse|InstancesListEntraIdCertificatesResponse}. + * 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/sql_instances_service.list_entra_id_certificates.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ListEntraIdCertificates_async + */ listEntraIdCertificates( - request?: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | undefined + ), + {} | undefined, + ] + >; listEntraIdCertificates( - request: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listEntraIdCertificates( - request: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, - callback: Callback< - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, + callback: Callback< + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listEntraIdCertificates( - request?: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('listEntraIdCertificates request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('listEntraIdCertificates response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.listEntraIdCertificates(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest|undefined, - {}|undefined - ]) => { - this._log.info('listEntraIdCertificates 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); + return this.innerApiCalls + .listEntraIdCertificates(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesListEntraIdCertificatesRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('listEntraIdCertificates 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; }); } -/** - * Partially updates settings of a Cloud SQL instance by merging the request - * with the current configuration. This method supports patch semantics. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.DatabaseInstance} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.patch.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Patch_async - */ + /** + * Partially updates settings of a Cloud SQL instance by merging the request + * with the current configuration. This method supports patch semantics. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.DatabaseInstance} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.patch.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Patch_async + */ patch( - request?: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPatchRequest | undefined, + {} | undefined, + ] + >; patch( - request: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPatchRequest | null | undefined, + {} | null | undefined + >, + ): void; patch( - request: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPatchRequest | null | undefined, + {} | null | undefined + >, + ): void; patch( - request?: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesPatchRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPatchRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPatchRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('patch request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('patch response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.patch(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPatchRequest|undefined, - {}|undefined - ]) => { - this._log.info('patch 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); + return this.innerApiCalls + .patch(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPatchRequest | undefined, + {} | undefined, + ]) => { + this._log.info('patch 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; }); } -/** - * Promotes the read replica instance to be an independent Cloud SQL - * primary instance. - * Using this operation might cause your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @param {boolean} request.failover - * Set to true to invoke a replica failover to the DR - * replica. As part of replica failover, the promote operation attempts - * to add the original primary instance as a replica of the promoted - * DR replica when the original primary instance comes back online. - * If set to false or not specified, then the original primary - * instance becomes an independent Cloud SQL primary instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.promote_replica.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_PromoteReplica_async - */ + /** + * Promotes the read replica instance to be an independent Cloud SQL + * primary instance. + * Using this operation might cause your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @param {boolean} request.failover + * Set to true to invoke a replica failover to the DR + * replica. As part of replica failover, the promote operation attempts + * to add the original primary instance as a replica of the promoted + * DR replica when the original primary instance comes back online. + * If set to false or not specified, then the original primary + * instance becomes an independent Cloud SQL primary instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.promote_replica.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_PromoteReplica_async + */ promoteReplica( - request?: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest | undefined, + {} | undefined, + ] + >; promoteReplica( - request: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; promoteReplica( - request: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; promoteReplica( - request?: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('promoteReplica request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('promoteReplica response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.promoteReplica(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest|undefined, - {}|undefined - ]) => { - this._log.info('promoteReplica 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); + return this.innerApiCalls + .promoteReplica(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPromoteReplicaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('promoteReplica 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; }); } -/** - * Switches over from the primary instance to the DR replica - * instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the replica. - * @param {google.protobuf.Duration} [request.dbTimeout] - * Optional. (MySQL and PostgreSQL only) Cloud SQL instance operations - * timeout, which is a sum of all database operations. Default value is 10 - * minutes and can be modified to a maximum value of 24 hours. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.switchover.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Switchover_async - */ + /** + * Switches over from the primary instance to the DR replica + * instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the replica. + * @param {google.protobuf.Duration} [request.dbTimeout] + * Optional. (MySQL and PostgreSQL only) Cloud SQL instance operations + * timeout, which is a sum of all database operations. Default value is 10 + * minutes and can be modified to a maximum value of 24 hours. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.switchover.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Switchover_async + */ switchover( - request?: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest | undefined, + {} | undefined, + ] + >; switchover( - request: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; switchover( - request: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; switchover( - request?: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('switchover request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('switchover response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.switchover(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest|undefined, - {}|undefined - ]) => { - this._log.info('switchover 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); + return this.innerApiCalls + .switchover(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesSwitchoverRequest | undefined, + {} | undefined, + ]) => { + this._log.info('switchover 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; }); } -/** - * Deletes all client certificates and generates a new server SSL certificate - * for the instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.SqlInstancesResetSslConfigRequest.ResetSslMode} [request.mode] - * Optional. Reset SSL mode to use. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.reset_ssl_config.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ResetSslConfig_async - */ + /** + * Deletes all client certificates and generates a new server SSL certificate + * for the instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.SqlInstancesResetSslConfigRequest.ResetSslMode} [request.mode] + * Optional. Reset SSL mode to use. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.reset_ssl_config.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ResetSslConfig_async + */ resetSslConfig( - request?: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest | undefined, + {} | undefined, + ] + >; resetSslConfig( - request: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetSslConfig( - request: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetSslConfig( - request?: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('resetSslConfig request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('resetSslConfig response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.resetSslConfig(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest|undefined, - {}|undefined - ]) => { - this._log.info('resetSslConfig 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); + return this.innerApiCalls + .resetSslConfig(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesResetSslConfigRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('resetSslConfig 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; }); } -/** - * Restarts a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance to be restarted. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.restart.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Restart_async - */ + /** + * Restarts a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance to be restarted. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.restart.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Restart_async + */ restart( - request?: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestartRequest | undefined, + {} | undefined, + ] + >; restart( - request: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestartRequest | null | undefined, + {} | null | undefined + >, + ): void; restart( - request: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestartRequest | null | undefined, + {} | null | undefined + >, + ): void; restart( - request?: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesRestartRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestartRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestartRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('restart request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('restart response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.restart(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestartRequest|undefined, - {}|undefined - ]) => { - this._log.info('restart 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); + return this.innerApiCalls + .restart(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestartRequest | undefined, + {} | undefined, + ]) => { + this._log.info('restart 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; }); } -/** - * Restores a backup of a Cloud SQL instance. Using this operation might cause - * your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesRestoreBackupRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.restore_backup.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_RestoreBackup_async - */ + /** + * Restores a backup of a Cloud SQL instance. Using this operation might cause + * your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesRestoreBackupRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.restore_backup.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_RestoreBackup_async + */ restoreBackup( - request?: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest | undefined, + {} | undefined, + ] + >; restoreBackup( - request: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + ): void; restoreBackup( - request: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + ): void; restoreBackup( - request?: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('restoreBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('restoreBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.restoreBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('restoreBackup 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); + return this.innerApiCalls + .restoreBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRestoreBackupRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('restoreBackup 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; }); } -/** - * Rotates the server certificate to one signed by the Certificate Authority - * (CA) version previously added with the addServerCA method. For instances - * that have enabled Certificate Authority Service (CAS) based server CA, - * use RotateServerCertificate to rotate the server certificate. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesRotateServerCaRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.rotate_server_ca.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_RotateServerCa_async - */ + /** + * Rotates the server certificate to one signed by the Certificate Authority + * (CA) version previously added with the addServerCA method. For instances + * that have enabled Certificate Authority Service (CAS) based server CA, + * use RotateServerCertificate to rotate the server certificate. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesRotateServerCaRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.rotate_server_ca.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_RotateServerCa_async + */ rotateServerCa( - request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest | undefined, + {} | undefined, + ] + >; rotateServerCa( - request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCa( - request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCa( - request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rotateServerCa request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rotateServerCa response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rotateServerCa(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest|undefined, - {}|undefined - ]) => { - this._log.info('rotateServerCa 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); + return this.innerApiCalls + .rotateServerCa(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rotateServerCa 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; }); } -/** - * Rotates the server certificate version to one previously added with the - * addServerCertificate method. For instances not using Certificate Authority - * Service (CAS) server CA, use RotateServerCa instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesRotateServerCertificateRequest} [request.body] - * Optional. Rotate server certificate request body. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.rotate_server_certificate.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_RotateServerCertificate_async - */ + /** + * Rotates the server certificate version to one previously added with the + * addServerCertificate method. For instances not using Certificate Authority + * Service (CAS) server CA, use RotateServerCa instead. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesRotateServerCertificateRequest} [request.body] + * Optional. Rotate server certificate request body. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.rotate_server_certificate.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_RotateServerCertificate_async + */ rotateServerCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | undefined + ), + {} | undefined, + ] + >; rotateServerCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rotateServerCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rotateServerCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rotateServerCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('rotateServerCertificate 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); + return this.innerApiCalls + .rotateServerCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateServerCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rotateServerCertificate 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; }); } -/** - * Rotates the server certificate version to one previously added with the - * addEntraIdCertificate method. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesRotateEntraIdCertificateRequest} [request.body] - * Optional. Rotate Entra ID certificate request body. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.rotate_entra_id_certificate.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_RotateEntraIdCertificate_async - */ + /** + * Rotates the server certificate version to one previously added with the + * addEntraIdCertificate method. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesRotateEntraIdCertificateRequest} [request.body] + * Optional. Rotate Entra ID certificate request body. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.rotate_entra_id_certificate.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_RotateEntraIdCertificate_async + */ rotateEntraIdCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + >; rotateEntraIdCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateEntraIdCertificate( - request: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateEntraIdCertificate( - request?: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rotateEntraIdCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rotateEntraIdCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rotateEntraIdCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('rotateEntraIdCertificate 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); + return this.innerApiCalls + .rotateEntraIdCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRotateEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rotateEntraIdCertificate 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; }); } -/** - * Starts the replication in the read replica instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.start_replica.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_StartReplica_async - */ + /** + * Starts the replication in the read replica instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.start_replica.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_StartReplica_async + */ startReplica( - request?: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest | undefined, + {} | undefined, + ] + >; startReplica( - request: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startReplica( - request: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startReplica( - request?: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('startReplica request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('startReplica response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.startReplica(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest|undefined, - {}|undefined - ]) => { - this._log.info('startReplica 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); + return this.innerApiCalls + .startReplica(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesStartReplicaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('startReplica 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; }); } -/** - * Stops the replication in the read replica instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.stop_replica.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_StopReplica_async - */ + /** + * Stops the replication in the read replica instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.stop_replica.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_StopReplica_async + */ stopReplica( - request?: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest | undefined, + {} | undefined, + ] + >; stopReplica( - request: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; stopReplica( - request: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; stopReplica( - request?: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('stopReplica request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('stopReplica response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.stopReplica(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest|undefined, - {}|undefined - ]) => { - this._log.info('stopReplica 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); + return this.innerApiCalls + .stopReplica(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesStopReplicaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('stopReplica 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; }); } -/** - * Truncate MySQL general and slow query log tables - * MySQL only. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the Cloud SQL project. - * @param {google.cloud.sql.v1.InstancesTruncateLogRequest} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.truncate_log.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_TruncateLog_async - */ + /** + * Truncate MySQL general and slow query log tables + * MySQL only. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the Cloud SQL project. + * @param {google.cloud.sql.v1.InstancesTruncateLogRequest} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.truncate_log.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_TruncateLog_async + */ truncateLog( - request?: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest | undefined, + {} | undefined, + ] + >; truncateLog( - request: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + ): void; truncateLog( - request: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + ): void; truncateLog( - request?: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('truncateLog request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('truncateLog response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.truncateLog(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest|undefined, - {}|undefined - ]) => { - this._log.info('truncateLog 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); + return this.innerApiCalls + .truncateLog(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesTruncateLogRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('truncateLog 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; }); } -/** - * Updates settings of a Cloud SQL instance. Using this operation might cause - * your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.DatabaseInstance} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.update.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_Update_async - */ + /** + * Updates settings of a Cloud SQL instance. Using this operation might cause + * your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.DatabaseInstance} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.update.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_Update_async + */ update( - request?: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest | undefined, + {} | undefined, + ] + >; update( - request: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request?: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('update request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('update response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.update(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('update 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); + return this.innerApiCalls + .update(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlInstancesUpdateRequest | undefined, + {} | undefined, + ]) => { + this._log.info('update 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; }); } -/** - * Generates a short-lived X509 certificate containing the provided public key - * and signed by a private key specific to the target instance. Users may use - * the certificate to authenticate as themselves when connecting to the - * database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the Cloud SQL project. - * @param {google.cloud.sql.v1.SslCertsCreateEphemeralRequest} request.body - * @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.cloud.sql.v1.SslCert|SslCert}. - * 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/sql_instances_service.create_ephemeral.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_CreateEphemeral_async - */ + /** + * Generates a short-lived X509 certificate containing the provided public key + * and signed by a private key specific to the target instance. Users may use + * the certificate to authenticate as themselves when connecting to the + * database. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the Cloud SQL project. + * @param {google.cloud.sql.v1.SslCertsCreateEphemeralRequest} request.body + * @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.cloud.sql.v1.SslCert|SslCert}. + * 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/sql_instances_service.create_ephemeral.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_CreateEphemeral_async + */ createEphemeral( - request?: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCert, + ( + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | undefined + ), + {} | undefined, + ] + >; createEphemeral( - request: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISslCert, + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; createEphemeral( - request: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISslCert, + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; createEphemeral( - request?: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISslCert, + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCert, + ( + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('createEphemeral request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISslCert, + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('createEphemeral response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.createEphemeral(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest|undefined, - {}|undefined - ]) => { - this._log.info('createEphemeral 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); + return this.innerApiCalls + .createEphemeral(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISslCert, + ( + | protos.google.cloud.sql.v1.ISqlInstancesCreateEphemeralCertRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('createEphemeral 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; }); } -/** - * Reschedules the maintenance on the given instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequestBody} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.reschedule_maintenance.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_RescheduleMaintenance_async - */ + /** + * Reschedules the maintenance on the given instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequestBody} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.reschedule_maintenance.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_RescheduleMaintenance_async + */ rescheduleMaintenance( - request?: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | undefined + ), + {} | undefined, + ] + >; rescheduleMaintenance( - request: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rescheduleMaintenance( - request: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rescheduleMaintenance( - request?: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rescheduleMaintenance request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rescheduleMaintenance response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rescheduleMaintenance(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest|undefined, - {}|undefined - ]) => { - this._log.info('rescheduleMaintenance 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); + return this.innerApiCalls + .rescheduleMaintenance(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesRescheduleMaintenanceRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rescheduleMaintenance 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; }); } -/** - * Verify External primary instance external sync settings. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {boolean} request.verifyConnectionOnly - * Flag to enable verifying connection only - * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode - * External sync mode - * @param {boolean} [request.verifyReplicationOnly] - * Optional. Flag to verify settings required by replication setup only - * @param {google.cloud.sql.v1.MySqlSyncConfig} [request.mysqlSyncConfig] - * Optional. MySQL-specific settings for start external sync. - * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] - * Optional. MigrationType configures the migration to use physical files or - * logical dump files. If not set, then the logical dump file configuration is - * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. - * @param {google.cloud.sql.v1.ExternalSyncParallelLevel} [request.syncParallelLevel] - * Optional. Parallel level for initial data sync. Only applicable for - * PostgreSQL. - * @param {number[]} [request.selectedObjects] - * Optional. Migrate only the specified objects from the source instance. If - * this field is empty, then migrate all objects. - * @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.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsResponse|SqlInstancesVerifyExternalSyncSettingsResponse}. - * 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/sql_instances_service.verify_external_sync_settings.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_VerifyExternalSyncSettings_async - */ + /** + * Verify External primary instance external sync settings. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {boolean} request.verifyConnectionOnly + * Flag to enable verifying connection only + * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode + * External sync mode + * @param {boolean} [request.verifyReplicationOnly] + * Optional. Flag to verify settings required by replication setup only + * @param {google.cloud.sql.v1.MySqlSyncConfig} [request.mysqlSyncConfig] + * Optional. MySQL-specific settings for start external sync. + * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] + * Optional. MigrationType configures the migration to use physical files or + * logical dump files. If not set, then the logical dump file configuration is + * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. + * @param {google.cloud.sql.v1.ExternalSyncParallelLevel} [request.syncParallelLevel] + * Optional. Parallel level for initial data sync. Only applicable for + * PostgreSQL. + * @param {number[]} [request.selectedObjects] + * Optional. Migrate only the specified objects from the source instance. If + * this field is empty, then migrate all objects. + * @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.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsResponse|SqlInstancesVerifyExternalSyncSettingsResponse}. + * 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/sql_instances_service.verify_external_sync_settings.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_VerifyExternalSyncSettings_async + */ verifyExternalSyncSettings( - request?: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | undefined + ), + {} | undefined, + ] + >; verifyExternalSyncSettings( - request: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): void; verifyExternalSyncSettings( - request: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): void; verifyExternalSyncSettings( - request?: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('verifyExternalSyncSettings request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('verifyExternalSyncSettings response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.verifyExternalSyncSettings(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest|undefined, - {}|undefined - ]) => { - this._log.info('verifyExternalSyncSettings 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); + return this.innerApiCalls + .verifyExternalSyncSettings(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('verifyExternalSyncSettings 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; }); } -/** - * Start External primary instance migration. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode - * External sync mode. - * @param {boolean} request.skipVerification - * Whether to skip the verification step (VESS). - * @param {google.cloud.sql.v1.MySqlSyncConfig} request.mysqlSyncConfig - * MySQL-specific settings for start external sync. - * @param {google.cloud.sql.v1.ExternalSyncParallelLevel} [request.syncParallelLevel] - * Optional. Parallel level for initial data sync. Currently only applicable - * for MySQL. - * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] - * Optional. MigrationType configures the migration to use physical files or - * logical dump files. If not set, then the logical dump file configuration is - * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. - * @param {boolean} [request.replicaOverwriteEnabled] - * Optional. MySQL only. True if end-user has confirmed that this SES call - * will wipe replica databases overlapping with the proposed selected_objects. - * If this field is not set and there are both overlapping and additional - * databases proposed, an error will be returned. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.start_external_sync.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_StartExternalSync_async - */ + /** + * Start External primary instance migration. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode + * External sync mode. + * @param {boolean} request.skipVerification + * Whether to skip the verification step (VESS). + * @param {google.cloud.sql.v1.MySqlSyncConfig} request.mysqlSyncConfig + * MySQL-specific settings for start external sync. + * @param {google.cloud.sql.v1.ExternalSyncParallelLevel} [request.syncParallelLevel] + * Optional. Parallel level for initial data sync. Currently only applicable + * for MySQL. + * @param {google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] + * Optional. MigrationType configures the migration to use physical files or + * logical dump files. If not set, then the logical dump file configuration is + * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. + * @param {boolean} [request.replicaOverwriteEnabled] + * Optional. MySQL only. True if end-user has confirmed that this SES call + * will wipe replica databases overlapping with the proposed selected_objects. + * If this field is not set and there are both overlapping and additional + * databases proposed, an error will be returned. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.start_external_sync.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_StartExternalSync_async + */ startExternalSync( - request?: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | undefined + ), + {} | undefined, + ] + >; startExternalSync( - request: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startExternalSync( - request: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startExternalSync( - request?: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('startExternalSync request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('startExternalSync response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.startExternalSync(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest|undefined, - {}|undefined - ]) => { - this._log.info('startExternalSync 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); + return this.innerApiCalls + .startExternalSync(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesStartExternalSyncRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('startExternalSync 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; }); } -/** - * Perform Disk Shrink on primary instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.PerformDiskShrinkContext} request.body - * Perform disk shrink context. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.perform_disk_shrink.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_PerformDiskShrink_async - */ + /** + * Perform Disk Shrink on primary instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.PerformDiskShrinkContext} request.body + * Perform disk shrink context. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.perform_disk_shrink.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_PerformDiskShrink_async + */ performDiskShrink( - request?: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | undefined + ), + {} | undefined, + ] + >; performDiskShrink( - request: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + ): void; performDiskShrink( - request: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + ): void; performDiskShrink( - request?: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('performDiskShrink request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('performDiskShrink response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.performDiskShrink(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest|undefined, - {}|undefined - ]) => { - this._log.info('performDiskShrink 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); + return this.innerApiCalls + .performDiskShrink(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPerformDiskShrinkRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('performDiskShrink 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; }); } -/** - * Get Disk Shrink Config for a given instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigResponse|SqlInstancesGetDiskShrinkConfigResponse}. - * 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/sql_instances_service.get_disk_shrink_config.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_GetDiskShrinkConfig_async - */ + /** + * Get Disk Shrink Config for a given instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigResponse|SqlInstancesGetDiskShrinkConfigResponse}. + * 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/sql_instances_service.get_disk_shrink_config.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_GetDiskShrinkConfig_async + */ getDiskShrinkConfig( - request?: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | undefined + ), + {} | undefined, + ] + >; getDiskShrinkConfig( - request: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getDiskShrinkConfig( - request: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getDiskShrinkConfig( - request?: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getDiskShrinkConfig request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getDiskShrinkConfig response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getDiskShrinkConfig(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest|undefined, - {}|undefined - ]) => { - this._log.info('getDiskShrinkConfig 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); + return this.innerApiCalls + .getDiskShrinkConfig(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('getDiskShrinkConfig 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; }); } -/** - * Reset Replica Size to primary instance disk size. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.reset_replica_size.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ResetReplicaSize_async - */ + /** + * Reset Replica Size to primary instance disk size. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.reset_replica_size.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ResetReplicaSize_async + */ resetReplicaSize( - request?: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | undefined + ), + {} | undefined, + ] + >; resetReplicaSize( - request: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetReplicaSize( - request: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetReplicaSize( - request?: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('resetReplicaSize request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('resetReplicaSize response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.resetReplicaSize(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest|undefined, - {}|undefined - ]) => { - this._log.info('resetReplicaSize 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); + return this.innerApiCalls + .resetReplicaSize(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesResetReplicaSizeRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('resetReplicaSize 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; }); } -/** - * Get Latest Recovery Time for a given instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.protobuf.Timestamp} request.sourceInstanceDeletionTime - * The timestamp used to identify the time when the source instance is - * deleted. If this instance is deleted, then you must set the timestamp. - * @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.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeResponse|SqlInstancesGetLatestRecoveryTimeResponse}. - * 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/sql_instances_service.get_latest_recovery_time.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_GetLatestRecoveryTime_async - */ + /** + * Get Latest Recovery Time for a given instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.protobuf.Timestamp} request.sourceInstanceDeletionTime + * The timestamp used to identify the time when the source instance is + * deleted. If this instance is deleted, then you must set the timestamp. + * @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.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeResponse|SqlInstancesGetLatestRecoveryTimeResponse}. + * 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/sql_instances_service.get_latest_recovery_time.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_GetLatestRecoveryTime_async + */ getLatestRecoveryTime( - request?: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | undefined + ), + {} | undefined, + ] + >; getLatestRecoveryTime( - request: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getLatestRecoveryTime( - request: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getLatestRecoveryTime( - request?: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getLatestRecoveryTime request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getLatestRecoveryTime response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getLatestRecoveryTime(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest|undefined, - {}|undefined - ]) => { - this._log.info('getLatestRecoveryTime 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); + return this.innerApiCalls + .getLatestRecoveryTime(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('getLatestRecoveryTime 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; }); } -/** - * Execute SQL statements. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Database instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.ExecuteSqlPayload} request.body - * The request body. - * @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.cloud.sql.v1.SqlInstancesExecuteSqlResponse|SqlInstancesExecuteSqlResponse}. - * 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/sql_instances_service.execute_sql.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ExecuteSql_async - */ + /** + * Execute SQL statements. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Database instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.ExecuteSqlPayload} request.body + * The request body. + * @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.cloud.sql.v1.SqlInstancesExecuteSqlResponse|SqlInstancesExecuteSqlResponse}. + * 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/sql_instances_service.execute_sql.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ExecuteSql_async + */ executeSql( - request?: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest | undefined, + {} | undefined, + ] + >; executeSql( - request: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + ): void; executeSql( - request: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + ): void; executeSql( - request?: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('executeSql request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('executeSql response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.executeSql(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest|undefined, - {}|undefined - ]) => { - this._log.info('executeSql 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); + return this.innerApiCalls + .executeSql(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse, + protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlRequest | undefined, + {} | undefined, + ]) => { + this._log.info('executeSql 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; }); } -/** - * Acquire a lease for the setup of SQL Server Reporting Services (SSRS). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This doesn't include the project ID. It's - * composed of lowercase letters, numbers, and hyphens, and it must start with - * a letter. The total length must be 98 characters or less (Example: - * instance-id). - * @param {string} request.project - * Required. Project ID of the project that contains the instance (Example: - * project-id). - * @param {google.cloud.sql.v1.InstancesAcquireSsrsLeaseRequest} request.body - * Required. The request body. - * @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.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseResponse|SqlInstancesAcquireSsrsLeaseResponse}. - * 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/sql_instances_service.acquire_ssrs_lease.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_AcquireSsrsLease_async - */ + /** + * Acquire a lease for the setup of SQL Server Reporting Services (SSRS). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This doesn't include the project ID. It's + * composed of lowercase letters, numbers, and hyphens, and it must start with + * a letter. The total length must be 98 characters or less (Example: + * instance-id). + * @param {string} request.project + * Required. Project ID of the project that contains the instance (Example: + * project-id). + * @param {google.cloud.sql.v1.InstancesAcquireSsrsLeaseRequest} request.body + * Required. The request body. + * @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.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseResponse|SqlInstancesAcquireSsrsLeaseResponse}. + * 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/sql_instances_service.acquire_ssrs_lease.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_AcquireSsrsLease_async + */ acquireSsrsLease( - request?: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + >; acquireSsrsLease( - request: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; acquireSsrsLease( - request: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; acquireSsrsLease( - request?: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('acquireSsrsLease request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('acquireSsrsLease response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.acquireSsrsLease(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest|undefined, - {}|undefined - ]) => { - this._log.info('acquireSsrsLease 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); + return this.innerApiCalls + .acquireSsrsLease(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('acquireSsrsLease 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; }); } -/** - * Release a lease for the setup of SQL Server Reporting Services (SSRS). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. The Cloud SQL instance ID. This doesn't include the project ID. - * The instance ID contains lowercase letters, numbers, and hyphens, and it - * must start with a letter. This ID can have a maximum length of 98 - * characters. - * @param {string} request.project - * Required. The project ID that contains the instance. - * @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.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseResponse|SqlInstancesReleaseSsrsLeaseResponse}. - * 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/sql_instances_service.release_ssrs_lease.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_ReleaseSsrsLease_async - */ + /** + * Release a lease for the setup of SQL Server Reporting Services (SSRS). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. The Cloud SQL instance ID. This doesn't include the project ID. + * The instance ID contains lowercase letters, numbers, and hyphens, and it + * must start with a letter. This ID can have a maximum length of 98 + * characters. + * @param {string} request.project + * Required. The project ID that contains the instance. + * @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.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseResponse|SqlInstancesReleaseSsrsLeaseResponse}. + * 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/sql_instances_service.release_ssrs_lease.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_ReleaseSsrsLease_async + */ releaseSsrsLease( - request?: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + >; releaseSsrsLease( - request: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; releaseSsrsLease( - request: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; releaseSsrsLease( - request?: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('releaseSsrsLease request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('releaseSsrsLease response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.releaseSsrsLease(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest|undefined, - {}|undefined - ]) => { - this._log.info('releaseSsrsLease 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); + return this.innerApiCalls + .releaseSsrsLease(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('releaseSsrsLease 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; }); } -/** - * Execute MVU Pre-checks - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.InstancesPreCheckMajorVersionUpgradeRequest} request.body - * Required. The context for request to perform the pre-check major version - * upgrade operation. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.pre_check_major_version_upgrade.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_PreCheckMajorVersionUpgrade_async - */ + /** + * Execute MVU Pre-checks + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.InstancesPreCheckMajorVersionUpgradeRequest} request.body + * Required. The context for request to perform the pre-check major version + * upgrade operation. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.pre_check_major_version_upgrade.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_PreCheckMajorVersionUpgrade_async + */ preCheckMajorVersionUpgrade( - request?: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | undefined + ), + {} | undefined, + ] + >; preCheckMajorVersionUpgrade( - request: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; preCheckMajorVersionUpgrade( - request: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; preCheckMajorVersionUpgrade( - request?: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('preCheckMajorVersionUpgrade request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('preCheckMajorVersionUpgrade response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.preCheckMajorVersionUpgrade(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest|undefined, - {}|undefined - ]) => { - this._log.info('preCheckMajorVersionUpgrade 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); + return this.innerApiCalls + .preCheckMajorVersionUpgrade(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('preCheckMajorVersionUpgrade 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; }); } -/** - * Point in time restore for an instance managed by Google Cloud Backup and - * Disaster Recovery. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource where you created this instance. - * Format: projects/{project} - * @param {google.cloud.sql.v1.PointInTimeRestoreContext} request.context - * Required. The context for request to perform a PITR on a Google Cloud - * Backup and Disaster Recovery managed instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_instances_service.point_in_time_restore.js - * region_tag:sqladmin_v1_generated_SqlInstancesService_PointInTimeRestore_async - */ + /** + * Point in time restore for an instance managed by Google Cloud Backup and + * Disaster Recovery. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent resource where you created this instance. + * Format: projects/{project} + * @param {google.cloud.sql.v1.PointInTimeRestoreContext} request.context + * Required. The context for request to perform a PITR on a Google Cloud + * Backup and Disaster Recovery managed instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_instances_service.point_in_time_restore.js + * region_tag:sqladmin_v1_generated_SqlInstancesService_PointInTimeRestore_async + */ pointInTimeRestore( - request?: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | undefined + ), + {} | undefined, + ] + >; pointInTimeRestore( - request: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + ): void; pointInTimeRestore( - request: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + ): void; pointInTimeRestore( - request?: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'parent': request.parent ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('pointInTimeRestore request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('pointInTimeRestore response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.pointInTimeRestore(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest|undefined, - {}|undefined - ]) => { - this._log.info('pointInTimeRestore 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); + return this.innerApiCalls + .pointInTimeRestore(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + ( + | protos.google.cloud.sql.v1.ISqlInstancesPointInTimeRestoreRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('pointInTimeRestore 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -4712,12 +6642,11 @@ export class SqlInstancesServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -4750,7 +6679,7 @@ export class SqlInstancesServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -4769,7 +6698,13 @@ export class SqlInstancesServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,location:string,backupvault:string,datasource:string,backup:string) { + backupPath( + project: string, + location: string, + backupvault: string, + datasource: string, + backup: string, + ) { return this.pathTemplates.backupPathTemplate.render({ project: project, location: location, @@ -4841,7 +6776,7 @@ export class SqlInstancesServiceClient { * @param {string} network * @returns {string} Resource name string. */ - networkPath(project:string,network:string) { + networkPath(project: string, network: string) { return this.pathTemplates.networkPathTemplate.render({ project: project, network: network, @@ -4878,13 +6813,15 @@ export class SqlInstancesServiceClient { */ close(): Promise { if (this.sqlInstancesServiceStub && !this._terminated) { - return this.sqlInstancesServiceStub.then(stub => { + return this.sqlInstancesServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_operations_service_client.ts b/packages/google-cloud-sql/src/v1/sql_operations_service_client.ts index d027e27c654b..4d9599d37c13 100644 --- a/packages/google-cloud-sql/src/v1/sql_operations_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_operations_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlOperationsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlOperationsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlOperationsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlOperationsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlOperationsServiceClient. @@ -101,21 +108,42 @@ export class SqlOperationsServiceClient { * const client = new SqlOperationsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlOperationsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlOperationsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlOperationsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlOperationsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlOperationsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlOperationsService', + 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 @@ -222,36 +249,40 @@ export class SqlOperationsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlOperationsService. this.sqlOperationsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlOperationsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlOperationsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlOperationsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlOperationsServiceStubMethods = - ['get', 'list', 'cancel']; + const sqlOperationsServiceStubMethods = ['get', 'list', 'cancel']; for (const methodName of sqlOperationsServiceStubMethods) { const callPromise = this.sqlOperationsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +297,14 @@ export class SqlOperationsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +315,14 @@ export class SqlOperationsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +355,7 @@ export class SqlOperationsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +365,9 @@ export class SqlOperationsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,304 +378,406 @@ export class SqlOperationsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Retrieves an instance operation that has been performed on an instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.operation - * Required. Instance operation ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_operations_service.get.js - * region_tag:sqladmin_v1_generated_SqlOperationsService_Get_async - */ + /** + * Retrieves an instance operation that has been performed on an instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.operation + * Required. Instance operation ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_operations_service.get.js + * region_tag:sqladmin_v1_generated_SqlOperationsService_Get_async + */ get( - request?: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlOperationsGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlOperationsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlOperationsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlOperationsGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlOperationsGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlOperationsGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'operation': request.operation ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + operation: request.operation ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlOperationsGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlOperationsGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Lists all instance operations that have been performed on the given Cloud - * SQL instance in the reverse chronological order of the start time. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {number} request.maxResults - * Maximum number of operations per response. - * @param {string} request.pageToken - * A previously-returned page token representing part of the larger set of - * results to view. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.OperationsListResponse|OperationsListResponse}. - * 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/sql_operations_service.list.js - * region_tag:sqladmin_v1_generated_SqlOperationsService_List_async - */ + /** + * Lists all instance operations that have been performed on the given Cloud + * SQL instance in the reverse chronological order of the start time. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {number} request.maxResults + * Maximum number of operations per response. + * @param {string} request.pageToken + * A previously-returned page token representing part of the larger set of + * results to view. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.OperationsListResponse|OperationsListResponse}. + * 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/sql_operations_service.list.js + * region_tag:sqladmin_v1_generated_SqlOperationsService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlOperationsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlOperationsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperationsListResponse, + protos.google.cloud.sql.v1.ISqlOperationsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlOperationsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlOperationsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperationsListResponse, + protos.google.cloud.sql.v1.ISqlOperationsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlOperationsListRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlOperationsListRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperationsListResponse, + protos.google.cloud.sql.v1.ISqlOperationsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlOperationsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlOperationsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperationsListResponse, + protos.google.cloud.sql.v1.ISqlOperationsListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperationsListResponse, + protos.google.cloud.sql.v1.ISqlOperationsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperationsListResponse, + | protos.google.cloud.sql.v1.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperationsListResponse, - protos.google.cloud.sql.v1.ISqlOperationsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperationsListResponse, + protos.google.cloud.sql.v1.ISqlOperationsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Cancels an instance operation that has been performed on an instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.operation - * Instance operation ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.protobuf.Empty|Empty}. - * 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/sql_operations_service.cancel.js - * region_tag:sqladmin_v1_generated_SqlOperationsService_Cancel_async - */ + /** + * Cancels an instance operation that has been performed on an instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.operation + * Instance operation ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.protobuf.Empty|Empty}. + * 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/sql_operations_service.cancel.js + * region_tag:sqladmin_v1_generated_SqlOperationsService_Cancel_async + */ cancel( - request?: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1.ISqlOperationsCancelRequest | undefined, + {} | undefined, + ] + >; cancel( - request: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1.ISqlOperationsCancelRequest | null | undefined, + {} | null | undefined + >, + ): void; cancel( - request: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1.ISqlOperationsCancelRequest | null | undefined, + {} | null | undefined + >, + ): void; cancel( - request?: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlOperationsCancelRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1.ISqlOperationsCancelRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1.ISqlOperationsCancelRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'operation': request.operation ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + operation: request.operation ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('cancel request %j', request); - const wrappedCallback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.sql.v1.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('cancel response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.cancel(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1.ISqlOperationsCancelRequest|undefined, - {}|undefined - ]) => { - this._log.info('cancel 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); + return this.innerApiCalls + .cancel(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1.ISqlOperationsCancelRequest | undefined, + {} | undefined, + ]) => { + this._log.info('cancel 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -666,12 +812,11 @@ export class SqlOperationsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -704,7 +849,7 @@ export class SqlOperationsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -720,7 +865,7 @@ export class SqlOperationsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -757,13 +902,15 @@ export class SqlOperationsServiceClient { */ close(): Promise { if (this.sqlOperationsServiceStub && !this._terminated) { - return this.sqlOperationsServiceStub.then(stub => { + return this.sqlOperationsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_ssl_certs_service_client.ts b/packages/google-cloud-sql/src/v1/sql_ssl_certs_service_client.ts index df2bb53abd2d..e820b8c0dff9 100644 --- a/packages/google-cloud-sql/src/v1/sql_ssl_certs_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_ssl_certs_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlSslCertsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlSslCertsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlSslCertsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlSslCertsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlSslCertsServiceClient. @@ -101,21 +108,42 @@ export class SqlSslCertsServiceClient { * const client = new SqlSslCertsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlSslCertsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlSslCertsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlSslCertsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlSslCertsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlSslCertsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlSslCertsService', + 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 @@ -222,36 +249,40 @@ export class SqlSslCertsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlSslCertsService. this.sqlSslCertsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlSslCertsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlSslCertsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlSslCertsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlSslCertsServiceStubMethods = - ['delete', 'get', 'insert', 'list']; + const sqlSslCertsServiceStubMethods = ['delete', 'get', 'insert', 'list']; for (const methodName of sqlSslCertsServiceStubMethods) { const callPromise = this.sqlSslCertsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +297,14 @@ export class SqlSslCertsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +315,14 @@ export class SqlSslCertsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +355,7 @@ export class SqlSslCertsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +365,9 @@ export class SqlSslCertsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,408 +378,536 @@ export class SqlSslCertsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes the SSL certificate. For First Generation instances, the - * certificate remains valid until the instance is restarted. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.sha1Fingerprint - * Sha1 FingerPrint. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_ssl_certs_service.delete.js - * region_tag:sqladmin_v1_generated_SqlSslCertsService_Delete_async - */ + /** + * Deletes the SSL certificate. For First Generation instances, the + * certificate remains valid until the instance is restarted. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.sha1Fingerprint + * Sha1 FingerPrint. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_ssl_certs_service.delete.js + * region_tag:sqladmin_v1_generated_SqlSslCertsService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'sha1_fingerprint': request.sha1Fingerprint ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + sha1_fingerprint: request.sha1Fingerprint ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + | protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlSslCertsDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a particular SSL certificate. Does not include the private key - * (required for usage). The private key must be saved from the response to - * initial creation. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.sha1Fingerprint - * Sha1 FingerPrint. - * @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.cloud.sql.v1.SslCert|SslCert}. - * 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/sql_ssl_certs_service.get.js - * region_tag:sqladmin_v1_generated_SqlSslCertsService_Get_async - */ + /** + * Retrieves a particular SSL certificate. Does not include the private key + * (required for usage). The private key must be saved from the response to + * initial creation. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.sha1Fingerprint + * Sha1 FingerPrint. + * @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.cloud.sql.v1.SslCert|SslCert}. + * 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/sql_ssl_certs_service.get.js + * region_tag:sqladmin_v1_generated_SqlSslCertsService_Get_async + */ get( - request?: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlSslCertsGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'sha1_fingerprint': request.sha1Fingerprint ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + sha1_fingerprint: request.sha1Fingerprint ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISslCert, - protos.google.cloud.sql.v1.ISqlSslCertsGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISslCert, + protos.google.cloud.sql.v1.ISqlSslCertsGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Creates an SSL certificate and returns it along with the private key and - * server certificate authority. The new certificate will not be usable until - * the instance is restarted. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.SslCertsInsertRequest} request.body - * @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.cloud.sql.v1.SslCertsInsertResponse|SslCertsInsertResponse}. - * 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/sql_ssl_certs_service.insert.js - * region_tag:sqladmin_v1_generated_SqlSslCertsService_Insert_async - */ + /** + * Creates an SSL certificate and returns it along with the private key and + * server certificate authority. The new certificate will not be usable until + * the instance is restarted. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.SslCertsInsertRequest} request.body + * @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.cloud.sql.v1.SslCertsInsertResponse|SslCertsInsertResponse}. + * 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/sql_ssl_certs_service.insert.js + * region_tag:sqladmin_v1_generated_SqlSslCertsService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + | protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISslCertsInsertResponse, - protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISslCertsInsertResponse, + protos.google.cloud.sql.v1.ISqlSslCertsInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists all of the current SSL certificates for the instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.SslCertsListResponse|SslCertsListResponse}. - * 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/sql_ssl_certs_service.list.js - * region_tag:sqladmin_v1_generated_SqlSslCertsService_List_async - */ + /** + * Lists all of the current SSL certificates for the instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.SslCertsListResponse|SslCertsListResponse}. + * 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/sql_ssl_certs_service.list.js + * region_tag:sqladmin_v1_generated_SqlSslCertsService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, - callback: Callback< - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, + callback: Callback< + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlSslCertsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ISslCertsListResponse, - protos.google.cloud.sql.v1.ISqlSslCertsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ISslCertsListResponse, + protos.google.cloud.sql.v1.ISqlSslCertsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -770,12 +942,11 @@ export class SqlSslCertsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -808,7 +979,7 @@ export class SqlSslCertsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -824,7 +995,7 @@ export class SqlSslCertsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -861,13 +1032,15 @@ export class SqlSslCertsServiceClient { */ close(): Promise { if (this.sqlSslCertsServiceStub && !this._terminated) { - return this.sqlSslCertsServiceStub.then(stub => { + return this.sqlSslCertsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_tiers_service_client.ts b/packages/google-cloud-sql/src/v1/sql_tiers_service_client.ts index f8c5bac50336..559916f53617 100644 --- a/packages/google-cloud-sql/src/v1/sql_tiers_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_tiers_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlTiersServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlTiersServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlTiersServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlTiersServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlTiersServiceClient. @@ -101,21 +108,42 @@ export class SqlTiersServiceClient { * const client = new SqlTiersServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlTiersServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlTiersServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlTiersServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlTiersServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlTiersService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlTiersService', + 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 @@ -222,36 +249,40 @@ export class SqlTiersServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlTiersService. this.sqlTiersServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlTiersService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlTiersService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlTiersService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlTiersServiceStubMethods = - ['list']; + const sqlTiersServiceStubMethods = ['list']; for (const methodName of sqlTiersServiceStubMethods) { const callPromise = this.sqlTiersServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +297,14 @@ export class SqlTiersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +315,14 @@ export class SqlTiersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +355,7 @@ export class SqlTiersServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +365,9 @@ export class SqlTiersServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,104 +378,134 @@ export class SqlTiersServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Lists all available machine types (tiers) for Cloud SQL, for example, - * `db-custom-1-3840`. For more information, see - * https://cloud.google.com/sql/pricing. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Project ID of the project for which to list tiers. - * @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.cloud.sql.v1.TiersListResponse|TiersListResponse}. - * 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/sql_tiers_service.list.js - * region_tag:sqladmin_v1_generated_SqlTiersService_List_async - */ + /** + * Lists all available machine types (tiers) for Cloud SQL, for example, + * `db-custom-1-3840`. For more information, see + * https://cloud.google.com/sql/pricing. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Project ID of the project for which to list tiers. + * @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.cloud.sql.v1.TiersListResponse|TiersListResponse}. + * 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/sql_tiers_service.list.js + * region_tag:sqladmin_v1_generated_SqlTiersService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlTiersListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlTiersListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlTiersListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlTiersListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlTiersListRequest, - callback: Callback< - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlTiersListRequest, + callback: Callback< + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlTiersListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlTiersListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.ITiersListResponse, - protos.google.cloud.sql.v1.ISqlTiersListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.ITiersListResponse, + protos.google.cloud.sql.v1.ISqlTiersListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -466,12 +540,11 @@ export class SqlTiersServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -504,7 +577,7 @@ export class SqlTiersServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -520,7 +593,7 @@ export class SqlTiersServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -557,13 +630,15 @@ export class SqlTiersServiceClient { */ close(): Promise { if (this.sqlTiersServiceStub && !this._terminated) { - return this.sqlTiersServiceStub.then(stub => { + return this.sqlTiersServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1/sql_users_service_client.ts b/packages/google-cloud-sql/src/v1/sql_users_service_client.ts index 9550f405ca02..4ef6422ba951 100644 --- a/packages/google-cloud-sql/src/v1/sql_users_service_client.ts +++ b/packages/google-cloud-sql/src/v1/sql_users_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlUsersServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlUsersServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlUsersServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlUsersServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlUsersServiceClient. @@ -101,21 +108,42 @@ export class SqlUsersServiceClient { * const client = new SqlUsersServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlUsersServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlUsersServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlUsersServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlUsersServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1.SqlUsersService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1.SqlUsersService', + 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 @@ -222,36 +249,46 @@ export class SqlUsersServiceClient { // Put together the "service stub" for // google.cloud.sql.v1.SqlUsersService. this.sqlUsersServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1.SqlUsersService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1.SqlUsersService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1.SqlUsersService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlUsersServiceStubMethods = - ['delete', 'get', 'insert', 'list', 'update']; + const sqlUsersServiceStubMethods = [ + 'delete', + 'get', + 'insert', + 'list', + 'update', + ]; for (const methodName of sqlUsersServiceStubMethods) { const callPromise = this.sqlUsersServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +303,14 @@ export class SqlUsersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +321,14 @@ export class SqlUsersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +361,7 @@ export class SqlUsersServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +371,9 @@ export class SqlUsersServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,515 +384,665 @@ export class SqlUsersServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes a user from a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.host - * Host of the user in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.name - * Name of the user in the instance. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_users_service.delete.js - * region_tag:sqladmin_v1_generated_SqlUsersService_Delete_async - */ + /** + * Deletes a user from a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.host + * Host of the user in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.name + * Name of the user in the instance. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_users_service.delete.js + * region_tag:sqladmin_v1_generated_SqlUsersService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlUsersDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a resource containing information about a user. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.name - * User of the instance. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.host - * Host of a user of the instance. - * @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.cloud.sql.v1.User|User}. - * 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/sql_users_service.get.js - * region_tag:sqladmin_v1_generated_SqlUsersService_Get_async - */ + /** + * Retrieves a resource containing information about a user. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.name + * User of the instance. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.host + * Host of a user of the instance. + * @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.cloud.sql.v1.User|User}. + * 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/sql_users_service.get.js + * region_tag:sqladmin_v1_generated_SqlUsersService_Get_async + */ get( - request?: protos.google.cloud.sql.v1.ISqlUsersGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlUsersGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1.ISqlUsersGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1.ISqlUsersGetRequest, - callback: Callback< - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersGetRequest, + callback: Callback< + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1.ISqlUsersGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlUsersGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'name': request.name ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + name: request.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IUser, - protos.google.cloud.sql.v1.ISqlUsersGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IUser, + protos.google.cloud.sql.v1.ISqlUsersGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Creates a new user in a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1.User} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_users_service.insert.js - * region_tag:sqladmin_v1_generated_SqlUsersService_Insert_async - */ + /** + * Creates a new user in a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1.User} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_users_service.insert.js + * region_tag:sqladmin_v1_generated_SqlUsersService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlUsersInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists users in the specified Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1.UsersListResponse|UsersListResponse}. - * 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/sql_users_service.list.js - * region_tag:sqladmin_v1_generated_SqlUsersService_List_async - */ + /** + * Lists users in the specified Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1.UsersListResponse|UsersListResponse}. + * 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/sql_users_service.list.js + * region_tag:sqladmin_v1_generated_SqlUsersService_List_async + */ list( - request?: protos.google.cloud.sql.v1.ISqlUsersListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlUsersListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1.ISqlUsersListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1.ISqlUsersListRequest, - callback: Callback< - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersListRequest, + callback: Callback< + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1.ISqlUsersListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlUsersListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IUsersListResponse, - protos.google.cloud.sql.v1.ISqlUsersListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IUsersListResponse, + protos.google.cloud.sql.v1.ISqlUsersListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Updates an existing user in a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} [request.host] - * Optional. Host of the user in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.name - * Name of the user in the instance. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string[]} [request.databaseRoles] - * Optional. List of database roles to grant to the user. body.database_roles - * will be ignored for update request. - * @param {boolean} [request.revokeExistingRoles] - * Optional. Specifies whether to revoke existing roles that are not present - * in the `database_roles` field. If `false` or unset, the database roles - * specified in `database_roles` are added to the user's existing roles. - * @param {google.cloud.sql.v1.User} request.body - * @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.cloud.sql.v1.Operation|Operation}. - * 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/sql_users_service.update.js - * region_tag:sqladmin_v1_generated_SqlUsersService_Update_async - */ + /** + * Updates an existing user in a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} [request.host] + * Optional. Host of the user in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.name + * Name of the user in the instance. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string[]} [request.databaseRoles] + * Optional. List of database roles to grant to the user. body.database_roles + * will be ignored for update request. + * @param {boolean} [request.revokeExistingRoles] + * Optional. Specifies whether to revoke existing roles that are not present + * in the `database_roles` field. If `false` or unset, the database roles + * specified in `database_roles` are added to the user's existing roles. + * @param {google.cloud.sql.v1.User} request.body + * @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.cloud.sql.v1.Operation|Operation}. + * 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/sql_users_service.update.js + * region_tag:sqladmin_v1_generated_SqlUsersService_Update_async + */ update( - request?: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | undefined, + {} | undefined, + ] + >; update( - request: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request?: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1.ISqlUsersUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('update request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('update response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.update(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1.IOperation, - protos.google.cloud.sql.v1.ISqlUsersUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('update 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); + return this.innerApiCalls + .update(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1.IOperation, + protos.google.cloud.sql.v1.ISqlUsersUpdateRequest | undefined, + {} | undefined, + ]) => { + this._log.info('update 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -877,12 +1077,11 @@ export class SqlUsersServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -915,7 +1114,7 @@ export class SqlUsersServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -931,7 +1130,7 @@ export class SqlUsersServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -968,13 +1167,15 @@ export class SqlUsersServiceClient { */ close(): Promise { if (this.sqlUsersServiceStub && !this._terminated) { - return this.sqlUsersServiceStub.then(stub => { + return this.sqlUsersServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/index.ts b/packages/google-cloud-sql/src/v1beta4/index.ts index c1b5dcdaf6e0..d8f42f199ca2 100644 --- a/packages/google-cloud-sql/src/v1beta4/index.ts +++ b/packages/google-cloud-sql/src/v1beta4/index.ts @@ -16,14 +16,14 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -export {SqlBackupRunsServiceClient} from './sql_backup_runs_service_client'; -export {SqlBackupsServiceClient} from './sql_backups_service_client'; -export {SqlConnectServiceClient} from './sql_connect_service_client'; -export {SqlDatabasesServiceClient} from './sql_databases_service_client'; -export {SqlFlagsServiceClient} from './sql_flags_service_client'; - -export {SqlInstancesServiceClient} from './sql_instances_service_client'; -export {SqlOperationsServiceClient} from './sql_operations_service_client'; -export {SqlSslCertsServiceClient} from './sql_ssl_certs_service_client'; -export {SqlTiersServiceClient} from './sql_tiers_service_client'; -export {SqlUsersServiceClient} from './sql_users_service_client'; +export { SqlBackupRunsServiceClient } from './sql_backup_runs_service_client'; +export { SqlBackupsServiceClient } from './sql_backups_service_client'; +export { SqlConnectServiceClient } from './sql_connect_service_client'; +export { SqlDatabasesServiceClient } from './sql_databases_service_client'; +export { SqlFlagsServiceClient } from './sql_flags_service_client'; +export { SqlIamPoliciesServiceClient } from './sql_iam_policies_service_client'; +export { SqlInstancesServiceClient } from './sql_instances_service_client'; +export { SqlOperationsServiceClient } from './sql_operations_service_client'; +export { SqlSslCertsServiceClient } from './sql_ssl_certs_service_client'; +export { SqlTiersServiceClient } from './sql_tiers_service_client'; +export { SqlUsersServiceClient } from './sql_users_service_client'; diff --git a/packages/google-cloud-sql/src/v1beta4/sql_backup_runs_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_backup_runs_service_client.ts index 56b0124a7c70..1d8a6b7aca1a 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_backup_runs_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_backup_runs_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlBackupRunsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlBackupRunsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlBackupRunsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlBackupRunsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlBackupRunsServiceClient. @@ -100,21 +107,42 @@ export class SqlBackupRunsServiceClient { * const client = new SqlBackupRunsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlBackupRunsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlBackupRunsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlBackupRunsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlBackupRunsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlBackupRunsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlBackupRunsService', + 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 @@ -224,36 +251,40 @@ export class SqlBackupRunsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlBackupRunsService. this.sqlBackupRunsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlBackupRunsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlBackupRunsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlBackupRunsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlBackupRunsServiceStubMethods = - ['delete', 'get', 'insert', 'list']; + const sqlBackupRunsServiceStubMethods = ['delete', 'get', 'insert', 'list']; for (const methodName of sqlBackupRunsServiceStubMethods) { const callPromise = this.sqlBackupRunsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +299,14 @@ export class SqlBackupRunsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +317,14 @@ export class SqlBackupRunsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +357,7 @@ export class SqlBackupRunsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +367,9 @@ export class SqlBackupRunsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,413 +380,579 @@ export class SqlBackupRunsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes the backup taken by a backup run. - * - * @param {Object} request - * The request object that will be sent. - * @param {number} request.id - * The ID of the backup run to delete. To find a backup run ID, use the - * [list](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/backupRuns/list) - * method. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_backup_runs_service.delete.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_Delete_async - */ + /** + * Deletes the backup taken by a backup run. + * + * @param {Object} request + * The request object that will be sent. + * @param {number} request.id + * The ID of the backup run to delete. To find a backup run ID, use the + * [list](https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/backupRuns/list) + * method. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_backup_runs_service.delete.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'id': request.id?.toString() ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + id: request.id?.toString() ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsDeleteRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a resource containing information about a backup run. - * - * @param {Object} request - * The request object that will be sent. - * @param {number} request.id - * The ID of this backup run. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.BackupRun|BackupRun}. - * 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/v1beta4/sql_backup_runs_service.get.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_Get_async - */ + /** + * Retrieves a resource containing information about a backup run. + * + * @param {Object} request + * The request object that will be sent. + * @param {number} request.id + * The ID of this backup run. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.BackupRun|BackupRun}. + * 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/v1beta4/sql_backup_runs_service.get.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_Get_async + */ get( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackupRun, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IBackupRun, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IBackupRun, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IBackupRun, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackupRun, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'id': request.id?.toString() ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + id: request.id?.toString() ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IBackupRun, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IBackupRun, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IBackupRun, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Creates a new backup run on demand. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.BackupRun} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_backup_runs_service.insert.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_Insert_async - */ + /** + * Creates a new backup run on demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.BackupRun} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_backup_runs_service.insert.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsInsertRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists all backup runs associated with the project or a given instance and - * configuration in the reverse chronological order of the backup initiation - * time. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID, or "-" for all instances. This does not include - * the project ID. - * @param {number} request.maxResults - * Maximum number of backup runs per response. - * @param {string} request.pageToken - * A previously-returned page token representing part of the larger set of - * results to view. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.BackupRunsListResponse|BackupRunsListResponse}. - * 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/v1beta4/sql_backup_runs_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_List_async - */ + /** + * Lists all backup runs associated with the project or a given instance and + * configuration in the reverse chronological order of the backup initiation + * time. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID, or "-" for all instances. This does not include + * the project ID. + * @param {number} request.maxResults + * Maximum number of backup runs per response. + * @param {string} request.pageToken + * A previously-returned page token representing part of the larger set of + * results to view. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.BackupRunsListResponse|BackupRunsListResponse}. + * 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/v1beta4/sql_backup_runs_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupRunsService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, - protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IBackupRunsListResponse, + protos.google.cloud.sql.v1beta4.ISqlBackupRunsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -777,12 +987,11 @@ export class SqlBackupRunsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -815,7 +1024,7 @@ export class SqlBackupRunsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -831,7 +1040,7 @@ export class SqlBackupRunsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -866,7 +1075,7 @@ export class SqlBackupRunsServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -891,13 +1100,15 @@ export class SqlBackupRunsServiceClient { */ close(): Promise { if (this.sqlBackupRunsServiceStub && !this._terminated) { - return this.sqlBackupRunsServiceStub.then(stub => { + return this.sqlBackupRunsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_backups_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_backups_service_client.ts index 21c870f5d116..8c51bd7530ed 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_backups_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_backups_service_client.ts @@ -18,11 +18,20 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, LocationsClient, LocationProtos} from 'google-gax'; -import {Transform} from 'stream'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + PaginationCallback, + GaxCall, + 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'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +52,7 @@ export class SqlBackupsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +65,10 @@ export class SqlBackupsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlBackupsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlBackupsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlBackupsServiceClient. @@ -100,21 +109,42 @@ export class SqlBackupsServiceClient { * const client = new SqlBackupsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlBackupsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +169,7 @@ export class SqlBackupsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +183,11 @@ export class SqlBackupsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,10 +209,10 @@ export class SqlBackupsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; @@ -194,14 +220,20 @@ export class SqlBackupsServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this.descriptors.page = { - listBackups: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'backups') + listBackups: new this._gaxModule.PageDescriptor( + 'pageToken', + 'nextPageToken', + 'backups', + ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlBackupsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlBackupsService', + 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 @@ -232,37 +264,46 @@ export class SqlBackupsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlBackupsService. this.sqlBackupsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlBackupsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlBackupsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlBackupsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlBackupsServiceStubMethods = - ['createBackup', 'getBackup', 'listBackups', 'updateBackup', 'deleteBackup']; + const sqlBackupsServiceStubMethods = [ + 'createBackup', + 'getBackup', + 'listBackups', + 'updateBackup', + 'deleteBackup', + ]; for (const methodName of sqlBackupsServiceStubMethods) { const callPromise = this.sqlBackupsServiceStub.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) => () => { + (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 descriptor = this.descriptors.page[methodName] || undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -277,8 +318,14 @@ export class SqlBackupsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -289,8 +336,14 @@ export class SqlBackupsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -323,7 +376,7 @@ export class SqlBackupsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -333,8 +386,9 @@ export class SqlBackupsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -345,490 +399,641 @@ export class SqlBackupsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Creates a backup for a Cloud SQL instance. This API can be used only to - * create on-demand backups. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource where this backup is created. - * Format: projects/{project} - * @param {google.cloud.sql.v1beta4.Backup} request.backup - * Required. The Backup to create. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_backups_service.create_backup.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_CreateBackup_async - */ + /** + * Creates a backup for a Cloud SQL instance. This API can be used only to + * create on-demand backups. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent resource where this backup is created. + * Format: projects/{project} + * @param {google.cloud.sql.v1beta4.Backup} request.backup + * Required. The Backup to create. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_backups_service.create_backup.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_CreateBackup_async + */ createBackup( - request?: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ICreateBackupRequest | undefined, + {} | undefined, + ] + >; createBackup( - request: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; createBackup( - request: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; createBackup( - request?: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ICreateBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ICreateBackupRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ICreateBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ICreateBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'parent': request.parent ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('createBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ICreateBackupRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('createBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.createBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ICreateBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('createBackup 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); + return this.innerApiCalls + .createBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ICreateBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('createBackup 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; }); } -/** - * Retrieves a resource containing information about a backup. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the backup to retrieve. - * Format: projects/{project}/backups/{backup} - * @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.cloud.sql.v1beta4.Backup|Backup}. - * 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/v1beta4/sql_backups_service.get_backup.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_GetBackup_async - */ + /** + * Retrieves a resource containing information about a backup. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the backup to retrieve. + * Format: projects/{project}/backups/{backup} + * @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.cloud.sql.v1beta4.Backup|Backup}. + * 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/v1beta4/sql_backups_service.get_backup.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_GetBackup_async + */ getBackup( - request?: protos.google.cloud.sql.v1beta4.IGetBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.IGetBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | undefined, + {} | undefined, + ] + >; getBackup( - request: protos.google.cloud.sql.v1beta4.IGetBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IGetBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; getBackup( - request: protos.google.cloud.sql.v1beta4.IGetBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IGetBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; getBackup( - request?: protos.google.cloud.sql.v1beta4.IGetBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.IGetBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|undefined, {}|undefined - ]>|void { + protos.google.cloud.sql.v1beta4.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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 ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | null | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IBackup, - protos.google.cloud.sql.v1beta4.IGetBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('getBackup 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); + return this.innerApiCalls + .getBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IBackup, + protos.google.cloud.sql.v1beta4.IGetBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('getBackup 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; }); } -/** - * Updates the retention period and the description of the backup. You can use - * this API to update final backups only. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.cloud.sql.v1beta4.Backup} request.backup - * Required. The backup to update. - * The backup’s `name` field is used to identify the backup to update. - * Format: projects/{project}/backups/{backup} - * @param {google.protobuf.FieldMask} request.updateMask - * The list of fields that you can update. You can update only the description - * and retention period of the final backup. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_backups_service.update_backup.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_UpdateBackup_async - */ + /** + * Updates the retention period and the description of the backup. You can use + * this API to update final backups only. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.cloud.sql.v1beta4.Backup} request.backup + * Required. The backup to update. + * The backup’s `name` field is used to identify the backup to update. + * Format: projects/{project}/backups/{backup} + * @param {google.protobuf.FieldMask} request.updateMask + * The list of fields that you can update. You can update only the description + * and retention period of the final backup. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_backups_service.update_backup.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_UpdateBackup_async + */ updateBackup( - request?: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IUpdateBackupRequest | undefined, + {} | undefined, + ] + >; updateBackup( - request: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; updateBackup( - request: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; updateBackup( - request?: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.IUpdateBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.IUpdateBackupRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IUpdateBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IUpdateBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'backup.name': request.backup!.name ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + 'backup.name': request.backup!.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('updateBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.IUpdateBackupRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('updateBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.updateBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IUpdateBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('updateBackup 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); + return this.innerApiCalls + .updateBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IUpdateBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('updateBackup 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; }); } -/** - * Deletes the backup. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the backup to delete. - * Format: projects/{project}/backups/{backup} - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_backups_service.delete_backup.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_DeleteBackup_async - */ + /** + * Deletes the backup. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the backup to delete. + * Format: projects/{project}/backups/{backup} + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_backups_service.delete_backup.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_DeleteBackup_async + */ deleteBackup( - request?: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IDeleteBackupRequest | undefined, + {} | undefined, + ] + >; deleteBackup( - request: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; deleteBackup( - request: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + ): void; deleteBackup( - request?: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.IDeleteBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.IDeleteBackupRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IDeleteBackupRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IDeleteBackupRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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 ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('deleteBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.IDeleteBackupRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('deleteBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.deleteBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.IDeleteBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('deleteBackup 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); + return this.innerApiCalls + .deleteBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.IDeleteBackupRequest | undefined, + {} | undefined, + ]) => { + this._log.info('deleteBackup 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; }); } - /** - * Lists all backups associated with the project. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent that owns this collection of backups. - * Format: projects/{project} - * @param {number} request.pageSize - * The maximum number of backups to return per response. The service might - * return fewer backups than this value. If a value for this parameter isn't - * specified, then, at most, 500 backups are returned. The maximum value is - * 2,000. Any values that you set, which are greater than 2,000, are changed - * to 2,000. - * @param {string} request.pageToken - * A page token, received from a previous `ListBackups` call. - * Provide this to retrieve the subsequent page. - * - * When paginating, all other parameters provided to `ListBackups` must match - * the call that provided the page token. - * @param {string} request.filter - * Multiple filter queries are separated by spaces. For example, - * 'instance:abc AND type:FINAL, 'location:us', - * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by - * type, instance, backupInterval.startTime (creation time), or 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 Array of {@link protos.google.cloud.sql.v1beta4.Backup|Backup}. - * 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 `listBackupsAsync()` - * 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. - */ + /** + * Lists all backups associated with the project. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent that owns this collection of backups. + * Format: projects/{project} + * @param {number} request.pageSize + * The maximum number of backups to return per response. The service might + * return fewer backups than this value. If a value for this parameter isn't + * specified, then, at most, 500 backups are returned. The maximum value is + * 2,000. Any values that you set, which are greater than 2,000, are changed + * to 2,000. + * @param {string} request.pageToken + * A page token, received from a previous `ListBackups` call. + * Provide this to retrieve the subsequent page. + * + * When paginating, all other parameters provided to `ListBackups` must match + * the call that provided the page token. + * @param {string} request.filter + * Multiple filter queries are separated by spaces. For example, + * 'instance:abc AND type:FINAL, 'location:us', + * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by + * type, instance, backupInterval.startTime (creation time), or 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 Array of {@link protos.google.cloud.sql.v1beta4.Backup|Backup}. + * 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 `listBackupsAsync()` + * 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. + */ listBackups( - request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackup[], - protos.google.cloud.sql.v1beta4.IListBackupsRequest|null, - protos.google.cloud.sql.v1beta4.IListBackupsResponse - ]>; + request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackup[], + protos.google.cloud.sql.v1beta4.IListBackupsRequest | null, + protos.google.cloud.sql.v1beta4.IListBackupsResponse, + ] + >; listBackups( - request: protos.google.cloud.sql.v1beta4.IListBackupsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.sql.v1beta4.IListBackupsRequest, - protos.google.cloud.sql.v1beta4.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1beta4.IBackup>): void; + request: protos.google.cloud.sql.v1beta4.IListBackupsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.sql.v1beta4.IListBackupsRequest, + protos.google.cloud.sql.v1beta4.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1beta4.IBackup + >, + ): void; listBackups( - request: protos.google.cloud.sql.v1beta4.IListBackupsRequest, - callback: PaginationCallback< - protos.google.cloud.sql.v1beta4.IListBackupsRequest, - protos.google.cloud.sql.v1beta4.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1beta4.IBackup>): void; + request: protos.google.cloud.sql.v1beta4.IListBackupsRequest, + callback: PaginationCallback< + protos.google.cloud.sql.v1beta4.IListBackupsRequest, + protos.google.cloud.sql.v1beta4.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1beta4.IBackup + >, + ): void; listBackups( - request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.cloud.sql.v1beta4.IListBackupsRequest, - protos.google.cloud.sql.v1beta4.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1beta4.IBackup>, - callback?: PaginationCallback< + request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, + optionsOrCallback?: + | CallOptions + | PaginationCallback< protos.google.cloud.sql.v1beta4.IListBackupsRequest, - protos.google.cloud.sql.v1beta4.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1beta4.IBackup>): - Promise<[ - protos.google.cloud.sql.v1beta4.IBackup[], - protos.google.cloud.sql.v1beta4.IListBackupsRequest|null, - protos.google.cloud.sql.v1beta4.IListBackupsResponse - ]>|void { + | protos.google.cloud.sql.v1beta4.IListBackupsResponse + | null + | undefined, + protos.google.cloud.sql.v1beta4.IBackup + >, + callback?: PaginationCallback< + protos.google.cloud.sql.v1beta4.IListBackupsRequest, + protos.google.cloud.sql.v1beta4.IListBackupsResponse | null | undefined, + protos.google.cloud.sql.v1beta4.IBackup + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IBackup[], + protos.google.cloud.sql.v1beta4.IListBackupsRequest | null, + protos.google.cloud.sql.v1beta4.IListBackupsResponse, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'parent': request.parent ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); - const wrappedCallback: PaginationCallback< - protos.google.cloud.sql.v1beta4.IListBackupsRequest, - protos.google.cloud.sql.v1beta4.IListBackupsResponse|null|undefined, - protos.google.cloud.sql.v1beta4.IBackup>|undefined = callback + const wrappedCallback: + | PaginationCallback< + protos.google.cloud.sql.v1beta4.IListBackupsRequest, + | protos.google.cloud.sql.v1beta4.IListBackupsResponse + | null + | undefined, + protos.google.cloud.sql.v1beta4.IBackup + > + | undefined = callback ? (error, values, nextPageRequest, rawResponse) => { this._log.info('listBackups values %j', values); callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. @@ -837,137 +1042,142 @@ export class SqlBackupsServiceClient { this._log.info('listBackups request %j', request); return this.innerApiCalls .listBackups(request, options, wrappedCallback) - ?.then(([response, input, output]: [ - protos.google.cloud.sql.v1beta4.IBackup[], - protos.google.cloud.sql.v1beta4.IListBackupsRequest|null, - protos.google.cloud.sql.v1beta4.IListBackupsResponse - ]) => { - this._log.info('listBackups values %j', response); - return [response, input, output]; - }); + ?.then( + ([response, input, output]: [ + protos.google.cloud.sql.v1beta4.IBackup[], + protos.google.cloud.sql.v1beta4.IListBackupsRequest | null, + protos.google.cloud.sql.v1beta4.IListBackupsResponse, + ]) => { + this._log.info('listBackups values %j', response); + return [response, input, output]; + }, + ); } -/** - * Equivalent to `listBackups`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent that owns this collection of backups. - * Format: projects/{project} - * @param {number} request.pageSize - * The maximum number of backups to return per response. The service might - * return fewer backups than this value. If a value for this parameter isn't - * specified, then, at most, 500 backups are returned. The maximum value is - * 2,000. Any values that you set, which are greater than 2,000, are changed - * to 2,000. - * @param {string} request.pageToken - * A page token, received from a previous `ListBackups` call. - * Provide this to retrieve the subsequent page. - * - * When paginating, all other parameters provided to `ListBackups` must match - * the call that provided the page token. - * @param {string} request.filter - * Multiple filter queries are separated by spaces. For example, - * 'instance:abc AND type:FINAL, 'location:us', - * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by - * type, instance, backupInterval.startTime (creation time), or location. - * @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.sql.v1beta4.Backup|Backup} 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 `listBackupsAsync()` - * 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. - */ + /** + * Equivalent to `listBackups`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent that owns this collection of backups. + * Format: projects/{project} + * @param {number} request.pageSize + * The maximum number of backups to return per response. The service might + * return fewer backups than this value. If a value for this parameter isn't + * specified, then, at most, 500 backups are returned. The maximum value is + * 2,000. Any values that you set, which are greater than 2,000, are changed + * to 2,000. + * @param {string} request.pageToken + * A page token, received from a previous `ListBackups` call. + * Provide this to retrieve the subsequent page. + * + * When paginating, all other parameters provided to `ListBackups` must match + * the call that provided the page token. + * @param {string} request.filter + * Multiple filter queries are separated by spaces. For example, + * 'instance:abc AND type:FINAL, 'location:us', + * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by + * type, instance, backupInterval.startTime (creation time), or location. + * @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.sql.v1beta4.Backup|Backup} 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 `listBackupsAsync()` + * 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. + */ listBackupsStream( - request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, - options?: CallOptions): - Transform{ + request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, + 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({ - 'parent': request.parent ?? '', - }); + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); const defaultCallSettings = this._defaults['listBackups']; const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => {throw err}); + this.initialize().catch((err) => { + throw err; + }); this._log.info('listBackups stream %j', request); return this.descriptors.page.listBackups.createStream( this.innerApiCalls.listBackups as GaxCall, request, - callSettings + callSettings, ); } -/** - * Equivalent to `listBackups`, 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.parent - * Required. The parent that owns this collection of backups. - * Format: projects/{project} - * @param {number} request.pageSize - * The maximum number of backups to return per response. The service might - * return fewer backups than this value. If a value for this parameter isn't - * specified, then, at most, 500 backups are returned. The maximum value is - * 2,000. Any values that you set, which are greater than 2,000, are changed - * to 2,000. - * @param {string} request.pageToken - * A page token, received from a previous `ListBackups` call. - * Provide this to retrieve the subsequent page. - * - * When paginating, all other parameters provided to `ListBackups` must match - * the call that provided the page token. - * @param {string} request.filter - * Multiple filter queries are separated by spaces. For example, - * 'instance:abc AND type:FINAL, 'location:us', - * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by - * type, instance, backupInterval.startTime (creation time), or location. - * @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.sql.v1beta4.Backup|Backup}. 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/v1beta4/sql_backups_service.list_backups.js - * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_ListBackups_async - */ + /** + * Equivalent to `listBackups`, 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.parent + * Required. The parent that owns this collection of backups. + * Format: projects/{project} + * @param {number} request.pageSize + * The maximum number of backups to return per response. The service might + * return fewer backups than this value. If a value for this parameter isn't + * specified, then, at most, 500 backups are returned. The maximum value is + * 2,000. Any values that you set, which are greater than 2,000, are changed + * to 2,000. + * @param {string} request.pageToken + * A page token, received from a previous `ListBackups` call. + * Provide this to retrieve the subsequent page. + * + * When paginating, all other parameters provided to `ListBackups` must match + * the call that provided the page token. + * @param {string} request.filter + * Multiple filter queries are separated by spaces. For example, + * 'instance:abc AND type:FINAL, 'location:us', + * 'backupInterval.startTime>=1950-01-01T01:01:25.771Z'. You can filter by + * type, instance, backupInterval.startTime (creation time), or location. + * @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.sql.v1beta4.Backup|Backup}. 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/v1beta4/sql_backups_service.list_backups.js + * region_tag:sqladmin_v1beta4_generated_SqlBackupsService_ListBackups_async + */ listBackupsAsync( - request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, - options?: CallOptions): - AsyncIterable{ + request?: protos.google.cloud.sql.v1beta4.IListBackupsRequest, + 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({ - 'parent': request.parent ?? '', - }); + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); const defaultCallSettings = this._defaults['listBackups']; const callSettings = defaultCallSettings.merge(options); - this.initialize().catch(err => {throw err}); + this.initialize().catch((err) => { + throw err; + }); this._log.info('listBackups iterate %j', request); return this.descriptors.page.listBackups.asyncIterate( this.innerApiCalls['listBackups'] as GaxCall, request as {}, - callSettings + callSettings, ) as AsyncIterable; } -/** + + /** * Gets information about a location. * * @param {Object} request @@ -1002,12 +1212,11 @@ export class SqlBackupsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -1040,7 +1249,7 @@ export class SqlBackupsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -1056,7 +1265,7 @@ export class SqlBackupsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -1091,7 +1300,7 @@ export class SqlBackupsServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -1116,13 +1325,15 @@ export class SqlBackupsServiceClient { */ close(): Promise { if (this.sqlBackupsServiceStub && !this._terminated) { - return this.sqlBackupsServiceStub.then(stub => { + return this.sqlBackupsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_connect_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_connect_service_client.ts index 9dd0d4425b76..98f4fcbdfa17 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_connect_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_connect_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlConnectServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlConnectServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlConnectServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlConnectServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlConnectServiceClient. @@ -101,21 +108,42 @@ export class SqlConnectServiceClient { * const client = new SqlConnectServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlConnectServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlConnectServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlConnectServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlConnectServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlConnectService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlConnectService', + 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 @@ -222,36 +249,43 @@ export class SqlConnectServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlConnectService. this.sqlConnectServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlConnectService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlConnectService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlConnectService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlConnectServiceStubMethods = - ['getConnectSettings', 'generateEphemeralCert']; + const sqlConnectServiceStubMethods = [ + 'getConnectSettings', + 'generateEphemeralCert', + ]; for (const methodName of sqlConnectServiceStubMethods) { const callPromise = this.sqlConnectServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +300,14 @@ export class SqlConnectServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +318,14 @@ export class SqlConnectServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +358,7 @@ export class SqlConnectServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +368,9 @@ export class SqlConnectServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,217 +381,303 @@ export class SqlConnectServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Retrieves connect settings about a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.protobuf.Timestamp} [request.readTime] - * Optional. Optional snapshot read timestamp to trade freshness for - * performance. - * @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.cloud.sql.v1beta4.ConnectSettings|ConnectSettings}. - * 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/v1beta4/sql_connect_service.get_connect_settings.js - * region_tag:sqladmin_v1beta4_generated_SqlConnectService_GetConnectSettings_async - */ + /** + * Retrieves connect settings about a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.protobuf.Timestamp} [request.readTime] + * Optional. Optional snapshot read timestamp to trade freshness for + * performance. + * @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.cloud.sql.v1beta4.ConnectSettings|ConnectSettings}. + * 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/v1beta4/sql_connect_service.get_connect_settings.js + * region_tag:sqladmin_v1beta4_generated_SqlConnectService_GetConnectSettings_async + */ getConnectSettings( - request?: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IConnectSettings, + protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest | undefined, + {} | undefined, + ] + >; getConnectSettings( - request: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IConnectSettings, + | protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getConnectSettings( - request: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IConnectSettings, + | protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getConnectSettings( - request?: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IConnectSettings, + | protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IConnectSettings, + protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getConnectSettings request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IConnectSettings, + | protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getConnectSettings response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getConnectSettings(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IConnectSettings, - protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest|undefined, - {}|undefined - ]) => { - this._log.info('getConnectSettings 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); + return this.innerApiCalls + .getConnectSettings(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IConnectSettings, + ( + | protos.google.cloud.sql.v1beta4.IGetConnectSettingsRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('getConnectSettings 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; }); } -/** - * Generates a short-lived X509 certificate containing the provided public key - * and signed by a private key specific to the target instance. Users may use - * the certificate to authenticate as themselves when connecting to the - * database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.publicKey - * PEM encoded public key to include in the signed certificate. - * @param {string} [request.accessToken] - * Optional. Access token to include in the signed certificate. - * @param {google.protobuf.Timestamp} [request.readTime] - * Optional. Optional snapshot read timestamp to trade freshness for - * performance. - * @param {google.protobuf.Duration} [request.validDuration] - * Optional. If set, it will contain the cert valid duration. - * @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.cloud.sql.v1beta4.GenerateEphemeralCertResponse|GenerateEphemeralCertResponse}. - * 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/v1beta4/sql_connect_service.generate_ephemeral_cert.js - * region_tag:sqladmin_v1beta4_generated_SqlConnectService_GenerateEphemeralCert_async - */ + /** + * Generates a short-lived X509 certificate containing the provided public key + * and signed by a private key specific to the target instance. Users may use + * the certificate to authenticate as themselves when connecting to the + * database. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.publicKey + * PEM encoded public key to include in the signed certificate. + * @param {string} [request.accessToken] + * Optional. Access token to include in the signed certificate. + * @param {google.protobuf.Timestamp} [request.readTime] + * Optional. Optional snapshot read timestamp to trade freshness for + * performance. + * @param {google.protobuf.Duration} [request.validDuration] + * Optional. If set, it will contain the cert valid duration. + * @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.cloud.sql.v1beta4.GenerateEphemeralCertResponse|GenerateEphemeralCertResponse}. + * 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/v1beta4/sql_connect_service.generate_ephemeral_cert.js + * region_tag:sqladmin_v1beta4_generated_SqlConnectService_GenerateEphemeralCert_async + */ generateEphemeralCert( - request?: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest | undefined, + {} | undefined, + ] + >; generateEphemeralCert( - request: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; generateEphemeralCert( - request: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; generateEphemeralCert( - request?: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('generateEphemeralCert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + | protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('generateEphemeralCert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.generateEphemeralCert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, - protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest|undefined, - {}|undefined - ]) => { - this._log.info('generateEphemeralCert 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); + return this.innerApiCalls + .generateEphemeralCert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse, + ( + | protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('generateEphemeralCert 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -579,12 +712,11 @@ export class SqlConnectServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -617,7 +749,7 @@ export class SqlConnectServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -633,7 +765,7 @@ export class SqlConnectServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -670,13 +802,15 @@ export class SqlConnectServiceClient { */ close(): Promise { if (this.sqlConnectServiceStub && !this._terminated) { - return this.sqlConnectServiceStub.then(stub => { + return this.sqlConnectServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_databases_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_databases_service_client.ts index 8be5e2d2de26..acc2d5a1d7c3 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_databases_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_databases_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlDatabasesServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlDatabasesServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlDatabasesServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlDatabasesServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlDatabasesServiceClient. @@ -100,21 +107,42 @@ export class SqlDatabasesServiceClient { * const client = new SqlDatabasesServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlDatabasesServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlDatabasesServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlDatabasesServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlDatabasesServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlDatabasesService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlDatabasesService', + 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 @@ -224,36 +251,47 @@ export class SqlDatabasesServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlDatabasesService. this.sqlDatabasesServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlDatabasesService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlDatabasesService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlDatabasesService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlDatabasesServiceStubMethods = - ['delete', 'get', 'insert', 'list', 'patch', 'update']; + const sqlDatabasesServiceStubMethods = [ + 'delete', + 'get', + 'insert', + 'list', + 'patch', + 'update', + ]; for (const methodName of sqlDatabasesServiceStubMethods) { const callPromise = this.sqlDatabasesServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +306,14 @@ export class SqlDatabasesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +324,14 @@ export class SqlDatabasesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +364,7 @@ export class SqlDatabasesServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +374,9 @@ export class SqlDatabasesServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,611 +387,863 @@ export class SqlDatabasesServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes a database from a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database to be deleted in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_databases_service.delete.js - * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Delete_async - */ + /** + * Deletes a database from a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database to be deleted in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_databases_service.delete.js + * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlDatabasesDeleteRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a resource containing information about a database inside a Cloud - * SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Database|Database}. - * 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/v1beta4/sql_databases_service.get.js - * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Get_async - */ + /** + * Retrieves a resource containing information about a database inside a Cloud + * SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Database|Database}. + * 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/v1beta4/sql_databases_service.get.js + * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Get_async + */ get( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IDatabase, + protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IDatabase, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IDatabase, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IDatabase, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IDatabase, + protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IDatabase, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IDatabase, - protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IDatabase, + protos.google.cloud.sql.v1beta4.ISqlDatabasesGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Inserts a resource containing information about a database inside a Cloud - * SQL instance. - * - * **Note:** You can't modify the default character set and collation. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.Database} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_databases_service.insert.js - * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Insert_async - */ + /** + * Inserts a resource containing information about a database inside a Cloud + * SQL instance. + * + * **Note:** You can't modify the default character set and collation. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.Database} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_databases_service.insert.js + * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlDatabasesInsertRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists databases in the specified Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.DatabasesListResponse|DatabasesListResponse}. - * 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/v1beta4/sql_databases_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_List_async - */ + /** + * Lists databases in the specified Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.DatabasesListResponse|DatabasesListResponse}. + * 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/v1beta4/sql_databases_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IDatabasesListResponse, - protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IDatabasesListResponse, + protos.google.cloud.sql.v1beta4.ISqlDatabasesListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Partially updates a resource containing information about a database inside - * a Cloud SQL instance. This method supports patch semantics. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database to be updated in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.Database} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_databases_service.patch.js - * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Patch_async - */ + /** + * Partially updates a resource containing information about a database inside + * a Cloud SQL instance. This method supports patch semantics. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database to be updated in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.Database} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_databases_service.patch.js + * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Patch_async + */ patch( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + >; patch( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; patch( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; patch( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('patch request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('patch response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.patch(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('patch 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); + return this.innerApiCalls + .patch(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('patch 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; }); } -/** - * Updates a resource containing information about a database inside a Cloud - * SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.database - * Name of the database to be updated in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.Database} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_databases_service.update.js - * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Update_async - */ + /** + * Updates a resource containing information about a database inside a Cloud + * SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.database + * Name of the database to be updated in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.Database} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_databases_service.update.js + * region_tag:sqladmin_v1beta4_generated_SqlDatabasesService_Update_async + */ update( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + >; update( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; update( - request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; update( - request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'database': request.database ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + database: request.database ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('update request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('update response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.update(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('update 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); + return this.innerApiCalls + .update(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlDatabasesUpdateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('update 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -975,12 +1278,11 @@ export class SqlDatabasesServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -1013,7 +1315,7 @@ export class SqlDatabasesServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -1029,7 +1331,7 @@ export class SqlDatabasesServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -1064,7 +1366,7 @@ export class SqlDatabasesServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -1089,13 +1391,15 @@ export class SqlDatabasesServiceClient { */ close(): Promise { if (this.sqlDatabasesServiceStub && !this._terminated) { - return this.sqlDatabasesServiceStub.then(stub => { + return this.sqlDatabasesServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_flags_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_flags_service_client.ts index c8b765e7f710..2ada4fa5a4c1 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_flags_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_flags_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlFlagsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlFlagsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlFlagsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlFlagsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlFlagsServiceClient. @@ -100,21 +107,42 @@ export class SqlFlagsServiceClient { * const client = new SqlFlagsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlFlagsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlFlagsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlFlagsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlFlagsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlFlagsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlFlagsService', + 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 @@ -224,36 +251,40 @@ export class SqlFlagsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlFlagsService. this.sqlFlagsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlFlagsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlFlagsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlFlagsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlFlagsServiceStubMethods = - ['list']; + const sqlFlagsServiceStubMethods = ['list']; for (const methodName of sqlFlagsServiceStubMethods) { const callPromise = this.sqlFlagsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +299,14 @@ export class SqlFlagsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +317,14 @@ export class SqlFlagsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +357,7 @@ export class SqlFlagsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +367,9 @@ export class SqlFlagsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,101 +380,136 @@ export class SqlFlagsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Lists all available database flags for Cloud SQL instances. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.databaseVersion - * Database type and version you want to retrieve flags for. By default, this - * method returns flags for all database types and versions. - * @param {google.cloud.sql.v1beta4.SqlFlagScope} [request.flagScope] - * Optional. Specify the scope of flags to be returned by SqlFlagsListService. - * Return list of database flags if unspecified. - * @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.cloud.sql.v1beta4.FlagsListResponse|FlagsListResponse}. - * 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/v1beta4/sql_flags_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlFlagsService_List_async - */ + /** + * Lists all available database flags for Cloud SQL instances. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.databaseVersion + * Database type and version you want to retrieve flags for. By default, this + * method returns flags for all database types and versions. + * @param {google.cloud.sql.v1beta4.SqlFlagScope} [request.flagScope] + * Optional. Specify the scope of flags to be returned by SqlFlagsListService. + * Return list of database flags if unspecified. + * @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.cloud.sql.v1beta4.FlagsListResponse|FlagsListResponse}. + * 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/v1beta4/sql_flags_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlFlagsService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } else { options = optionsOrCallback as CallOptions; } options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - this.initialize().catch(err => {throw err}); + this.initialize().catch((err) => { + throw err; + }); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IFlagsListResponse, - protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IFlagsListResponse, + protos.google.cloud.sql.v1beta4.ISqlFlagsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -465,12 +544,11 @@ export class SqlFlagsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -503,7 +581,7 @@ export class SqlFlagsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -519,7 +597,7 @@ export class SqlFlagsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -554,7 +632,7 @@ export class SqlFlagsServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -579,13 +657,15 @@ export class SqlFlagsServiceClient { */ close(): Promise { if (this.sqlFlagsServiceStub && !this._terminated) { - return this.sqlFlagsServiceStub.then(stub => { + return this.sqlFlagsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_instances_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_instances_service_client.ts index dbfed12b86a9..a487606fd449 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_instances_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_instances_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlInstancesServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlInstancesServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlInstancesServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlInstancesServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlInstancesServiceClient. @@ -100,21 +107,42 @@ export class SqlInstancesServiceClient { * const client = new SqlInstancesServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlInstancesServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlInstancesServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlInstancesServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlInstancesServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlInstancesService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlInstancesService', + 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 @@ -224,36 +251,84 @@ export class SqlInstancesServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlInstancesService. this.sqlInstancesServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlInstancesService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlInstancesService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlInstancesService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlInstancesServiceStubMethods = - ['addServerCa', 'addServerCertificate', 'addEntraIdCertificate', 'clone', 'delete', 'demoteMaster', 'demote', 'export', 'failover', 'reencrypt', 'get', 'import', 'insert', 'list', 'listServerCas', 'listServerCertificates', 'listEntraIdCertificates', 'patch', 'promoteReplica', 'switchover', 'resetSslConfig', 'restart', 'restoreBackup', 'rotateServerCa', 'rotateServerCertificate', 'rotateEntraIdCertificate', 'startReplica', 'stopReplica', 'truncateLog', 'update', 'createEphemeral', 'rescheduleMaintenance', 'verifyExternalSyncSettings', 'startExternalSync', 'performDiskShrink', 'getDiskShrinkConfig', 'resetReplicaSize', 'getLatestRecoveryTime', 'executeSql', 'acquireSsrsLease', 'releaseSsrsLease', 'preCheckMajorVersionUpgrade', 'pointInTimeRestore']; + const sqlInstancesServiceStubMethods = [ + 'addServerCa', + 'addServerCertificate', + 'addEntraIdCertificate', + 'clone', + 'delete', + 'demoteMaster', + 'demote', + 'export', + 'failover', + 'reencrypt', + 'get', + 'import', + 'insert', + 'list', + 'listServerCas', + 'listServerCertificates', + 'listEntraIdCertificates', + 'patch', + 'promoteReplica', + 'switchover', + 'resetSslConfig', + 'restart', + 'restoreBackup', + 'rotateServerCa', + 'rotateServerCertificate', + 'rotateEntraIdCertificate', + 'startReplica', + 'stopReplica', + 'truncateLog', + 'update', + 'createEphemeral', + 'rescheduleMaintenance', + 'verifyExternalSyncSettings', + 'startExternalSync', + 'performDiskShrink', + 'getDiskShrinkConfig', + 'resetReplicaSize', + 'getLatestRecoveryTime', + 'executeSql', + 'acquireSsrsLease', + 'releaseSsrsLease', + 'preCheckMajorVersionUpgrade', + 'pointInTimeRestore', + ]; for (const methodName of sqlInstancesServiceStubMethods) { const callPromise = this.sqlInstancesServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +343,14 @@ export class SqlInstancesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +361,14 @@ export class SqlInstancesServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +401,7 @@ export class SqlInstancesServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +411,9 @@ export class SqlInstancesServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,4349 +424,6366 @@ export class SqlInstancesServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Add a new trusted Certificate Authority (CA) version for the specified - * instance. Required to prepare for a certificate rotation. If a CA version - * was previously added but never used in a certificate rotation, this - * operation replaces that version. There cannot be more than one CA version - * waiting to be rotated in. For instances that have enabled Certificate - * Authority Service (CAS) based server CA, use AddServerCertificate to add a - * new server certificate. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.add_server_ca.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AddServerCa_async - */ + /** + * Add a new trusted Certificate Authority (CA) version for the specified + * instance. Required to prepare for a certificate rotation. If a CA version + * was previously added but never used in a certificate rotation, this + * operation replaces that version. There cannot be more than one CA version + * waiting to be rotated in. For instances that have enabled Certificate + * Authority Service (CAS) based server CA, use AddServerCertificate to add a + * new server certificate. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.add_server_ca.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AddServerCa_async + */ addServerCa( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | undefined + ), + {} | undefined, + ] + >; addServerCa( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCa( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCa( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('addServerCa request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('addServerCa response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.addServerCa(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest|undefined, - {}|undefined - ]) => { - this._log.info('addServerCa 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); + return this.innerApiCalls + .addServerCa(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('addServerCa 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; }); } -/** - * Add a new trusted server certificate version for the specified instance - * using Certificate Authority Service (CAS) server CA. Required to prepare - * for a certificate rotation. If a server certificate version was previously - * added but never used in a certificate rotation, this operation replaces - * that version. There cannot be more than one certificate version waiting to - * be rotated in. For instances not using CAS server CA, use AddServerCa - * instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.add_server_certificate.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AddServerCertificate_async - */ + /** + * Add a new trusted server certificate version for the specified instance + * using Certificate Authority Service (CAS) server CA. Required to prepare + * for a certificate rotation. If a server certificate version was previously + * added but never used in a certificate rotation, this operation replaces + * that version. There cannot be more than one certificate version waiting to + * be rotated in. For instances not using CAS server CA, use AddServerCa + * instead. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.add_server_certificate.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AddServerCertificate_async + */ addServerCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | undefined + ), + {} | undefined, + ] + >; addServerCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addServerCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('addServerCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('addServerCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.addServerCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('addServerCertificate 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); + return this.innerApiCalls + .addServerCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddServerCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('addServerCertificate 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; }); } -/** - * Adds a new Entra ID certificate for the specified instance. If an Entra ID - * certificate was previously added but never used in a certificate rotation, - * this operation replaces that version. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.add_entra_id_certificate.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AddEntraIdCertificate_async - */ + /** + * Adds a new Entra ID certificate for the specified instance. If an Entra ID + * certificate was previously added but never used in a certificate rotation, + * this operation replaces that version. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.add_entra_id_certificate.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AddEntraIdCertificate_async + */ addEntraIdCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + >; addEntraIdCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addEntraIdCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; addEntraIdCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('addEntraIdCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('addEntraIdCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.addEntraIdCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('addEntraIdCertificate 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); + return this.innerApiCalls + .addEntraIdCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAddEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('addEntraIdCertificate 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; }); } -/** - * Creates a Cloud SQL instance as a clone of the source instance. Using this - * operation might cause your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * The ID of the Cloud SQL instance to be cloned (source). This does not - * include the project ID. - * @param {string} request.project - * Project ID of the source as well as the clone Cloud SQL instance. - * @param {google.cloud.sql.v1beta4.InstancesCloneRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.clone.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Clone_async - */ + /** + * Creates a Cloud SQL instance as a clone of the source instance. Using this + * operation might cause your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * The ID of the Cloud SQL instance to be cloned (source). This does not + * include the project ID. + * @param {string} request.project + * Project ID of the source as well as the clone Cloud SQL instance. + * @param {google.cloud.sql.v1beta4.InstancesCloneRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.clone.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Clone_async + */ clone( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest | undefined, + {} | undefined, + ] + >; clone( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + >, + ): void; clone( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + >, + ): void; clone( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('clone request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('clone response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.clone(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest|undefined, - {}|undefined - ]) => { - this._log.info('clone 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); + return this.innerApiCalls + .clone(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesCloneRequest | undefined, + {} | undefined, + ]) => { + this._log.info('clone 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; }); } -/** - * Deletes a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance to be deleted. - * @param {boolean} request.enableFinalBackup - * Flag to opt-in for final backup. By default, it is turned off. - * @param {number} [request.finalBackupTtlDays] - * Optional. Retention period of the final backup. - * @param {google.protobuf.Timestamp} [request.finalBackupExpiryTime] - * Optional. Final Backup expiration time. - * Timestamp in UTC of when this resource is considered expired. - * @param {string} [request.finalBackupDescription] - * Optional. The description of the final backup. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.delete.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Delete_async - */ + /** + * Deletes a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance to be deleted. + * @param {boolean} request.enableFinalBackup + * Flag to opt-in for final backup. By default, it is turned off. + * @param {number} [request.finalBackupTtlDays] + * Optional. Retention period of the final backup. + * @param {google.protobuf.Timestamp} [request.finalBackupExpiryTime] + * Optional. Final Backup expiration time. + * Timestamp in UTC of when this resource is considered expired. + * @param {string} [request.finalBackupDescription] + * Optional. The description of the final backup. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.delete.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesDeleteRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Demotes the stand-alone instance to be a Cloud SQL read replica for an - * external database server. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance name. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesDemoteMasterRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.demote_master.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_DemoteMaster_async - */ + /** + * Demotes the stand-alone instance to be a Cloud SQL read replica for an + * external database server. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance name. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesDemoteMasterRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.demote_master.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_DemoteMaster_async + */ demoteMaster( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | undefined + ), + {} | undefined, + ] + >; demoteMaster( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + ): void; demoteMaster( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + ): void; demoteMaster( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('demoteMaster request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('demoteMaster response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.demoteMaster(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest|undefined, - {}|undefined - ]) => { - this._log.info('demoteMaster 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); + return this.innerApiCalls + .demoteMaster(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteMasterRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('demoteMaster 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; }); } -/** - * Demotes an existing standalone instance to be a Cloud SQL read replica - * for an external database server. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. The name of the Cloud SQL instance. - * @param {string} request.project - * Required. The project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesDemoteRequest} request.body - * The request body. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.demote.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Demote_async - */ + /** + * Demotes an existing standalone instance to be a Cloud SQL read replica + * for an external database server. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. The name of the Cloud SQL instance. + * @param {string} request.project + * Required. The project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesDemoteRequest} request.body + * The request body. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.demote.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Demote_async + */ demote( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest | undefined, + {} | undefined, + ] + >; demote( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; demote( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; demote( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('demote request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('demote response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.demote(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest|undefined, - {}|undefined - ]) => { - this._log.info('demote 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); + return this.innerApiCalls + .demote(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesDemoteRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('demote 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; }); } -/** - * Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL - * dump or CSV file. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * The Cloud SQL instance ID. This doesn't include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance to be exported. - * @param {google.cloud.sql.v1beta4.InstancesExportRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.export.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Export_async - */ + /** + * Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL + * dump or CSV file. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * The Cloud SQL instance ID. This doesn't include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance to be exported. + * @param {google.cloud.sql.v1beta4.InstancesExportRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.export.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Export_async + */ export( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest | undefined, + {} | undefined, + ] + >; export( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + >, + ): void; export( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + >, + ): void; export( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('export request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('export response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.export(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest|undefined, - {}|undefined - ]) => { - this._log.info('export 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); + return this.innerApiCalls + .export(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesExportRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('export 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; }); } -/** - * Initiates a manual failover of a high availability (HA) primary instance - * to a standby instance, which becomes the primary instance. Users are - * then rerouted to the new primary. For more information, see the - * [Overview of high - * availability](https://cloud.google.com/sql/docs/mysql/high-availability) - * page in the Cloud SQL documentation. - * If using Legacy HA (MySQL only), this causes the instance to failover to - * its failover replica instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the read replica. - * @param {google.cloud.sql.v1beta4.InstancesFailoverRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.failover.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Failover_async - */ + /** + * Initiates a manual failover of a high availability (HA) primary instance + * to a standby instance, which becomes the primary instance. Users are + * then rerouted to the new primary. For more information, see the + * [Overview of high + * availability](https://cloud.google.com/sql/docs/mysql/high-availability) + * page in the Cloud SQL documentation. + * If using Legacy HA (MySQL only), this causes the instance to failover to + * its failover replica instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the read replica. + * @param {google.cloud.sql.v1beta4.InstancesFailoverRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.failover.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Failover_async + */ failover( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest | undefined, + {} | undefined, + ] + >; failover( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; failover( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; failover( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('failover request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('failover response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.failover(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest|undefined, - {}|undefined - ]) => { - this._log.info('failover 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); + return this.innerApiCalls + .failover(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesFailoverRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('failover 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; }); } -/** - * Reencrypt CMEK instance with latest key version. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesReencryptRequest} request.body - * Reencrypt body that users request - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.reencrypt.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Reencrypt_async - */ + /** + * Reencrypt CMEK instance with latest key version. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesReencryptRequest} request.body + * Reencrypt body that users request + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.reencrypt.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Reencrypt_async + */ reencrypt( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest | undefined, + {} | undefined, + ] + >; reencrypt( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + ): void; reencrypt( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + ): void; reencrypt( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('reencrypt request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('reencrypt response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.reencrypt(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest|undefined, - {}|undefined - ]) => { - this._log.info('reencrypt 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); + return this.innerApiCalls + .reencrypt(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesReencryptRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('reencrypt 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; }); } -/** - * Retrieves a resource containing information about a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.DatabaseInstance|DatabaseInstance}. - * 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/v1beta4/sql_instances_service.get.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Get_async - */ + /** + * Retrieves a resource containing information about a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.DatabaseInstance|DatabaseInstance}. + * 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/v1beta4/sql_instances_service.get.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Get_async + */ get( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IDatabaseInstance, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IDatabaseInstance, + protos.google.cloud.sql.v1beta4.ISqlInstancesGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Imports data into a Cloud SQL instance from a SQL dump or CSV file in - * Cloud Storage. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesImportRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.import.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Import_async - */ + /** + * Imports data into a Cloud SQL instance from a SQL dump or CSV file in + * Cloud Storage. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesImportRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.import.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Import_async + */ import( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest | undefined, + {} | undefined, + ] + >; import( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + >, + ): void; import( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + >, + ): void; import( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('import request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('import response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.import(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest|undefined, - {}|undefined - ]) => { - this._log.info('import 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); + return this.innerApiCalls + .import(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesImportRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('import 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; }); } -/** - * Creates a new Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Project ID of the project to which the newly created Cloud SQL instances - * should belong. - * @param {google.cloud.sql.v1beta4.DatabaseInstance} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.insert.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Insert_async - */ + /** + * Creates a new Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Project ID of the project to which the newly created Cloud SQL instances + * should belong. + * @param {google.cloud.sql.v1beta4.DatabaseInstance} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.insert.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesInsertRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists instances under a given project. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.filter - * A filter expression that filters resources listed in the response. - * The expression is in the form of field:value. For example, - * 'instanceType:CLOUD_SQL_INSTANCE'. Fields can be nested as needed as per - * their JSON representation, such as 'settings.userLabels.auto_start:true'. - * - * Multiple filter queries are space-separated. For example. - * 'state:RUNNABLE instanceType:CLOUD_SQL_INSTANCE'. By default, each - * expression is an AND expression. However, you can include AND and OR - * expressions explicitly. - * @param {number} request.maxResults - * The maximum number of instances to return. The service may return fewer - * than this value. - * If unspecified, at most 500 instances are returned. - * The maximum value is 1000; values above 1000 are coerced to 1000. - * @param {string} request.pageToken - * A previously-returned page token representing part of the larger set of - * results to view. - * @param {string} request.project - * Project ID of the project for which to list Cloud SQL instances. - * @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.cloud.sql.v1beta4.InstancesListResponse|InstancesListResponse}. - * 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/v1beta4/sql_instances_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_List_async - */ + /** + * Lists instances under a given project. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.filter + * A filter expression that filters resources listed in the response. + * The expression is in the form of field:value. For example, + * 'instanceType:CLOUD_SQL_INSTANCE'. Fields can be nested as needed as per + * their JSON representation, such as 'settings.userLabels.auto_start:true'. + * + * Multiple filter queries are space-separated. For example. + * 'state:RUNNABLE instanceType:CLOUD_SQL_INSTANCE'. By default, each + * expression is an AND expression. However, you can include AND and OR + * expressions explicitly. + * @param {number} request.maxResults + * The maximum number of instances to return. The service may return fewer + * than this value. + * If unspecified, at most 500 instances are returned. + * The maximum value is 1000; values above 1000 are coerced to 1000. + * @param {string} request.pageToken + * A previously-returned page token representing part of the larger set of + * results to view. + * @param {string} request.project + * Project ID of the project for which to list Cloud SQL instances. + * @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.cloud.sql.v1beta4.InstancesListResponse|InstancesListResponse}. + * 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/v1beta4/sql_instances_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IInstancesListResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IInstancesListResponse, + protos.google.cloud.sql.v1beta4.ISqlInstancesListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Lists all of the trusted Certificate Authorities (CAs) for the specified - * instance. There can be up to three CAs listed: the CA that was used to sign - * the certificate that is currently in use, a CA that has been added but not - * yet used to sign a certificate, and a CA used to sign a certificate that - * has previously rotated out. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.InstancesListServerCasResponse|InstancesListServerCasResponse}. - * 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/v1beta4/sql_instances_service.list_server_cas.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ListServerCas_async - */ + /** + * Lists all of the trusted Certificate Authorities (CAs) for the specified + * instance. There can be up to three CAs listed: the CA that was used to sign + * the certificate that is currently in use, a CA that has been added but not + * yet used to sign a certificate, and a CA used to sign a certificate that + * has previously rotated out. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.InstancesListServerCasResponse|InstancesListServerCasResponse}. + * 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/v1beta4/sql_instances_service.list_server_cas.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ListServerCas_async + */ listServerCas( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | undefined + ), + {} | undefined, + ] + >; listServerCas( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCas( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCas( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('listServerCas request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('listServerCas response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.listServerCas(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest|undefined, - {}|undefined - ]) => { - this._log.info('listServerCas 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); + return this.innerApiCalls + .listServerCas(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCasRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('listServerCas 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; }); } -/** - * Lists all versions of server certificates and certificate authorities (CAs) - * for the specified instance. There can be up to three sets of certs listed: - * the certificate that is currently in use, a future that has been added but - * not yet used to sign a certificate, and a certificate that has been rotated - * out. For instances not using Certificate Authority Service (CAS) server CA, - * use ListServerCas instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.InstancesListServerCertificatesResponse|InstancesListServerCertificatesResponse}. - * 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/v1beta4/sql_instances_service.list_server_certificates.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ListServerCertificates_async - */ + /** + * Lists all versions of server certificates and certificate authorities (CAs) + * for the specified instance. There can be up to three sets of certs listed: + * the certificate that is currently in use, a future that has been added but + * not yet used to sign a certificate, and a certificate that has been rotated + * out. For instances not using Certificate Authority Service (CAS) server CA, + * use ListServerCas instead. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.InstancesListServerCertificatesResponse|InstancesListServerCertificatesResponse}. + * 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/v1beta4/sql_instances_service.list_server_certificates.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ListServerCertificates_async + */ listServerCertificates( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | undefined + ), + {} | undefined, + ] + >; listServerCertificates( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCertificates( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listServerCertificates( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('listServerCertificates request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('listServerCertificates response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.listServerCertificates(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest|undefined, - {}|undefined - ]) => { - this._log.info('listServerCertificates 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); + return this.innerApiCalls + .listServerCertificates(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListServerCertificatesRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('listServerCertificates 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; }); } -/** - * Lists all versions of EntraID certificates for the specified instance. - * There can be up to three sets of certificates listed: the certificate that - * is currently in use, a future that has been added but not yet used to sign - * a certificate, and a certificate that has been rotated out. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.InstancesListEntraIdCertificatesResponse|InstancesListEntraIdCertificatesResponse}. - * 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/v1beta4/sql_instances_service.list_entra_id_certificates.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ListEntraIdCertificates_async - */ + /** + * Lists all versions of EntraID certificates for the specified instance. + * There can be up to three sets of certificates listed: the certificate that + * is currently in use, a future that has been added but not yet used to sign + * a certificate, and a certificate that has been rotated out. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.InstancesListEntraIdCertificatesResponse|InstancesListEntraIdCertificatesResponse}. + * 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/v1beta4/sql_instances_service.list_entra_id_certificates.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ListEntraIdCertificates_async + */ listEntraIdCertificates( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | undefined + ), + {} | undefined, + ] + >; listEntraIdCertificates( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listEntraIdCertificates( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): void; listEntraIdCertificates( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('listEntraIdCertificates request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('listEntraIdCertificates response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.listEntraIdCertificates(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest|undefined, - {}|undefined - ]) => { - this._log.info('listEntraIdCertificates 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); + return this.innerApiCalls + .listEntraIdCertificates(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesListEntraIdCertificatesRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('listEntraIdCertificates 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; }); } -/** - * Partially updates settings of a Cloud SQL instance by merging the request - * with the current configuration. This method supports patch semantics. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.DatabaseInstance} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.patch.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Patch_async - */ + /** + * Partially updates settings of a Cloud SQL instance by merging the request + * with the current configuration. This method supports patch semantics. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.DatabaseInstance} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.patch.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Patch_async + */ patch( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest | undefined, + {} | undefined, + ] + >; patch( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + >, + ): void; patch( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + >, + ): void; patch( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('patch request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('patch response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.patch(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest|undefined, - {}|undefined - ]) => { - this._log.info('patch 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); + return this.innerApiCalls + .patch(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesPatchRequest | undefined, + {} | undefined, + ]) => { + this._log.info('patch 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; }); } -/** - * Promotes the read replica instance to be an independent Cloud SQL - * primary instance. - * Using this operation might cause your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @param {boolean} request.failover - * Set to true to invoke a replica failover to the DR replica. - * As part of replica failover, the promote operation attempts - * to add the original primary instance as a replica of the promoted - * DR replica when the original primary instance comes back online. - * If set to false or not specified, then the original primary - * instance becomes an independent Cloud SQL primary instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.promote_replica.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PromoteReplica_async - */ + /** + * Promotes the read replica instance to be an independent Cloud SQL + * primary instance. + * Using this operation might cause your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @param {boolean} request.failover + * Set to true to invoke a replica failover to the DR replica. + * As part of replica failover, the promote operation attempts + * to add the original primary instance as a replica of the promoted + * DR replica when the original primary instance comes back online. + * If set to false or not specified, then the original primary + * instance becomes an independent Cloud SQL primary instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.promote_replica.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PromoteReplica_async + */ promoteReplica( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | undefined + ), + {} | undefined, + ] + >; promoteReplica( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; promoteReplica( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; promoteReplica( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('promoteReplica request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('promoteReplica response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.promoteReplica(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest|undefined, - {}|undefined - ]) => { - this._log.info('promoteReplica 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); + return this.innerApiCalls + .promoteReplica(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPromoteReplicaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('promoteReplica 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; }); } -/** - * Switches over from the primary instance to the DR replica - * instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the replica. - * @param {google.protobuf.Duration} [request.dbTimeout] - * Optional. (MySQL and PostgreSQL only) Cloud SQL instance operations - * timeout, which is a sum of all database operations. Default value is 10 - * minutes and can be modified to a maximum value of 24 hours. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.switchover.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Switchover_async - */ + /** + * Switches over from the primary instance to the DR replica + * instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the replica. + * @param {google.protobuf.Duration} [request.dbTimeout] + * Optional. (MySQL and PostgreSQL only) Cloud SQL instance operations + * timeout, which is a sum of all database operations. Default value is 10 + * minutes and can be modified to a maximum value of 24 hours. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.switchover.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Switchover_async + */ switchover( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | undefined + ), + {} | undefined, + ] + >; switchover( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; switchover( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + ): void; switchover( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('switchover request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('switchover response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.switchover(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest|undefined, - {}|undefined - ]) => { - this._log.info('switchover 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); + return this.innerApiCalls + .switchover(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesSwitchoverRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('switchover 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; }); } -/** - * Deletes all client certificates and generates a new server SSL certificate - * for the instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest.ResetSslMode} [request.mode] - * Optional. Reset SSL mode to use. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.reset_ssl_config.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ResetSslConfig_async - */ + /** + * Deletes all client certificates and generates a new server SSL certificate + * for the instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest.ResetSslMode} [request.mode] + * Optional. Reset SSL mode to use. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.reset_ssl_config.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ResetSslConfig_async + */ resetSslConfig( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | undefined + ), + {} | undefined, + ] + >; resetSslConfig( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetSslConfig( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetSslConfig( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('resetSslConfig request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('resetSslConfig response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.resetSslConfig(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest|undefined, - {}|undefined - ]) => { - this._log.info('resetSslConfig 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); + return this.innerApiCalls + .resetSslConfig(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetSslConfigRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('resetSslConfig 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; }); } -/** - * Restarts a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance to be restarted. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.restart.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Restart_async - */ + /** + * Restarts a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance to be restarted. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.restart.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Restart_async + */ restart( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest | undefined, + {} | undefined, + ] + >; restart( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + >, + ): void; restart( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + >, + ): void; restart( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('restart request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('restart response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.restart(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest|undefined, - {}|undefined - ]) => { - this._log.info('restart 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); + return this.innerApiCalls + .restart(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestartRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('restart 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; }); } -/** - * Restores a backup of a Cloud SQL instance. Using this operation might cause - * your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesRestoreBackupRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.restore_backup.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RestoreBackup_async - */ + /** + * Restores a backup of a Cloud SQL instance. Using this operation might cause + * your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesRestoreBackupRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.restore_backup.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RestoreBackup_async + */ restoreBackup( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | undefined + ), + {} | undefined, + ] + >; restoreBackup( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + ): void; restoreBackup( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + ): void; restoreBackup( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('restoreBackup request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('restoreBackup response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.restoreBackup(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest|undefined, - {}|undefined - ]) => { - this._log.info('restoreBackup 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); + return this.innerApiCalls + .restoreBackup(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRestoreBackupRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('restoreBackup 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; }); } -/** - * Rotates the server certificate to one signed by the Certificate Authority - * (CA) version previously added with the addServerCA method. For instances - * that have enabled Certificate Authority Service (CAS) based server CA, - * use RotateServerCertificate to rotate the server certificate. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesRotateServerCaRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.rotate_server_ca.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RotateServerCa_async - */ + /** + * Rotates the server certificate to one signed by the Certificate Authority + * (CA) version previously added with the addServerCA method. For instances + * that have enabled Certificate Authority Service (CAS) based server CA, + * use RotateServerCertificate to rotate the server certificate. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesRotateServerCaRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.rotate_server_ca.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RotateServerCa_async + */ rotateServerCa( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | undefined + ), + {} | undefined, + ] + >; rotateServerCa( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCa( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCa( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rotateServerCa request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rotateServerCa response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rotateServerCa(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest|undefined, - {}|undefined - ]) => { - this._log.info('rotateServerCa 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); + return this.innerApiCalls + .rotateServerCa(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rotateServerCa 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; }); } -/** - * Rotates the server certificate version to one previously added with the - * addServerCertificate method. For instances not using Certificate Authority - * Service (CAS) server CA, use RotateServerCa instead. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesRotateServerCertificateRequest} request.body - * Required. Rotate server certificate request body. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.rotate_server_certificate.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RotateServerCertificate_async - */ + /** + * Rotates the server certificate version to one previously added with the + * addServerCertificate method. For instances not using Certificate Authority + * Service (CAS) server CA, use RotateServerCa instead. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesRotateServerCertificateRequest} request.body + * Required. Rotate server certificate request body. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.rotate_server_certificate.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RotateServerCertificate_async + */ rotateServerCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | undefined + ), + {} | undefined, + ] + >; rotateServerCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateServerCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rotateServerCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rotateServerCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rotateServerCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('rotateServerCertificate 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); + return this.innerApiCalls + .rotateServerCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateServerCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rotateServerCertificate 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; }); } -/** - * Rotates the Entra Id certificate version to one previously added with the - * addEntraIdCertificate method. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesRotateEntraIdCertificateRequest} request.body - * Required. Rotate Entra ID certificate request body. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.rotate_entra_id_certificate.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RotateEntraIdCertificate_async - */ + /** + * Rotates the Entra Id certificate version to one previously added with the + * addEntraIdCertificate method. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesRotateEntraIdCertificateRequest} request.body + * Required. Rotate Entra ID certificate request body. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.rotate_entra_id_certificate.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RotateEntraIdCertificate_async + */ rotateEntraIdCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + >; rotateEntraIdCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateEntraIdCertificate( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rotateEntraIdCertificate( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rotateEntraIdCertificate request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rotateEntraIdCertificate response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rotateEntraIdCertificate(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest|undefined, - {}|undefined - ]) => { - this._log.info('rotateEntraIdCertificate 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); + return this.innerApiCalls + .rotateEntraIdCertificate(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRotateEntraIdCertificateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rotateEntraIdCertificate 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; }); } -/** - * Starts the replication in the read replica instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.start_replica.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_StartReplica_async - */ + /** + * Starts the replication in the read replica instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.start_replica.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_StartReplica_async + */ startReplica( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | undefined + ), + {} | undefined, + ] + >; startReplica( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startReplica( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startReplica( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('startReplica request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('startReplica response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.startReplica(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest|undefined, - {}|undefined - ]) => { - this._log.info('startReplica 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); + return this.innerApiCalls + .startReplica(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartReplicaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('startReplica 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; }); } -/** - * Stops the replication in the read replica instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.stop_replica.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_StopReplica_async - */ + /** + * Stops the replication in the read replica instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.stop_replica.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_StopReplica_async + */ stopReplica( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | undefined + ), + {} | undefined, + ] + >; stopReplica( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; stopReplica( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): void; stopReplica( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('stopReplica request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('stopReplica response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.stopReplica(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest|undefined, - {}|undefined - ]) => { - this._log.info('stopReplica 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); + return this.innerApiCalls + .stopReplica(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStopReplicaRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('stopReplica 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; }); } -/** - * Truncate MySQL general and slow query log tables - * MySQL only. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the Cloud SQL project. - * @param {google.cloud.sql.v1beta4.InstancesTruncateLogRequest} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.truncate_log.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_TruncateLog_async - */ + /** + * Truncate MySQL general and slow query log tables + * MySQL only. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the Cloud SQL project. + * @param {google.cloud.sql.v1beta4.InstancesTruncateLogRequest} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.truncate_log.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_TruncateLog_async + */ truncateLog( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | undefined + ), + {} | undefined, + ] + >; truncateLog( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + ): void; truncateLog( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + ): void; truncateLog( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('truncateLog request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('truncateLog response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.truncateLog(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest|undefined, - {}|undefined - ]) => { - this._log.info('truncateLog 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); + return this.innerApiCalls + .truncateLog(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesTruncateLogRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('truncateLog 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; }); } -/** - * Updates settings of a Cloud SQL instance. Using this operation might cause - * your instance to restart. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.DatabaseInstance} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.update.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Update_async - */ + /** + * Updates settings of a Cloud SQL instance. Using this operation might cause + * your instance to restart. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.DatabaseInstance} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.update.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_Update_async + */ update( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest | undefined, + {} | undefined, + ] + >; update( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; update( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): void; update( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('update request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('update response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.update(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('update 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); + return this.innerApiCalls + .update(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesUpdateRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('update 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; }); } -/** - * Generates a short-lived X509 certificate containing the provided public key - * and signed by a private key specific to the target instance. Users may use - * the certificate to authenticate as themselves when connecting to the - * database. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the Cloud SQL project. - * @param {google.cloud.sql.v1beta4.SslCertsCreateEphemeralRequest} request.body - * @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.cloud.sql.v1beta4.SslCert|SslCert}. - * 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/v1beta4/sql_instances_service.create_ephemeral.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_CreateEphemeral_async - */ + /** + * Generates a short-lived X509 certificate containing the provided public key + * and signed by a private key specific to the target instance. Users may use + * the certificate to authenticate as themselves when connecting to the + * database. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the Cloud SQL project. + * @param {google.cloud.sql.v1beta4.SslCertsCreateEphemeralRequest} request.body + * @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.cloud.sql.v1beta4.SslCert|SslCert}. + * 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/v1beta4/sql_instances_service.create_ephemeral.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_CreateEphemeral_async + */ createEphemeral( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCert, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | undefined + ), + {} | undefined, + ] + >; createEphemeral( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; createEphemeral( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; createEphemeral( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCert, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('createEphemeral request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('createEphemeral response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.createEphemeral(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest|undefined, - {}|undefined - ]) => { - this._log.info('createEphemeral 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); + return this.innerApiCalls + .createEphemeral(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISslCert, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesCreateEphemeralCertRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('createEphemeral 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; }); } -/** - * Reschedules the maintenance on the given instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequestBody} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.reschedule_maintenance.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RescheduleMaintenance_async - */ + /** + * Reschedules the maintenance on the given instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequestBody} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.reschedule_maintenance.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_RescheduleMaintenance_async + */ rescheduleMaintenance( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | undefined + ), + {} | undefined, + ] + >; rescheduleMaintenance( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rescheduleMaintenance( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + ): void; rescheduleMaintenance( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('rescheduleMaintenance request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('rescheduleMaintenance response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.rescheduleMaintenance(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest|undefined, - {}|undefined - ]) => { - this._log.info('rescheduleMaintenance 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); + return this.innerApiCalls + .rescheduleMaintenance(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesRescheduleMaintenanceRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('rescheduleMaintenance 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; }); } -/** - * Verify External primary instance external sync settings. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {boolean} request.verifyConnectionOnly - * Flag to enable verifying connection only - * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode - * External sync mode - * @param {boolean} [request.verifyReplicationOnly] - * Optional. Flag to verify settings required by replication setup only - * @param {google.cloud.sql.v1beta4.MySqlSyncConfig} [request.mysqlSyncConfig] - * Optional. MySQL-specific settings for start external sync. - * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] - * Optional. MigrationType configures the migration to use physical files or - * logical dump files. If not set, then the logical dump file configuration is - * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. - * @param {google.cloud.sql.v1beta4.ExternalSyncParallelLevel} [request.syncParallelLevel] - * Optional. Parallel level for initial data sync. Only applicable for - * PostgreSQL. - * @param {number[]} [request.selectedObjects] - * Optional. Migrate only the specified objects from the source instance. If - * this field is empty, then migrate all objects. - * @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.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsResponse|SqlInstancesVerifyExternalSyncSettingsResponse}. - * 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/v1beta4/sql_instances_service.verify_external_sync_settings.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_VerifyExternalSyncSettings_async - */ + /** + * Verify External primary instance external sync settings. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {boolean} request.verifyConnectionOnly + * Flag to enable verifying connection only + * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode + * External sync mode + * @param {boolean} [request.verifyReplicationOnly] + * Optional. Flag to verify settings required by replication setup only + * @param {google.cloud.sql.v1beta4.MySqlSyncConfig} [request.mysqlSyncConfig] + * Optional. MySQL-specific settings for start external sync. + * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] + * Optional. MigrationType configures the migration to use physical files or + * logical dump files. If not set, then the logical dump file configuration is + * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. + * @param {google.cloud.sql.v1beta4.ExternalSyncParallelLevel} [request.syncParallelLevel] + * Optional. Parallel level for initial data sync. Only applicable for + * PostgreSQL. + * @param {number[]} [request.selectedObjects] + * Optional. Migrate only the specified objects from the source instance. If + * this field is empty, then migrate all objects. + * @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.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsResponse|SqlInstancesVerifyExternalSyncSettingsResponse}. + * 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/v1beta4/sql_instances_service.verify_external_sync_settings.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_VerifyExternalSyncSettings_async + */ verifyExternalSyncSettings( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | undefined + ), + {} | undefined, + ] + >; verifyExternalSyncSettings( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): void; verifyExternalSyncSettings( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): void; verifyExternalSyncSettings( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('verifyExternalSyncSettings request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('verifyExternalSyncSettings response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.verifyExternalSyncSettings(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest|undefined, - {}|undefined - ]) => { - this._log.info('verifyExternalSyncSettings 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); + return this.innerApiCalls + .verifyExternalSyncSettings(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('verifyExternalSyncSettings 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; }); } -/** - * Start External primary instance migration. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode - * External sync mode. - * @param {boolean} request.skipVerification - * Whether to skip the verification step (VESS). - * @param {google.cloud.sql.v1beta4.MySqlSyncConfig} request.mysqlSyncConfig - * MySQL-specific settings for start external sync. - * @param {google.cloud.sql.v1beta4.ExternalSyncParallelLevel} [request.syncParallelLevel] - * Optional. Parallel level for initial data sync. Currently only applicable - * for MySQL. - * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] - * Optional. MigrationType configures the migration to use physical files or - * logical dump files. If not set, then the logical dump file configuration is - * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. - * @param {boolean} [request.replicaOverwriteEnabled] - * Optional. MySQL only. True if end-user has confirmed that this SES call - * will wipe replica databases overlapping with the proposed selected_objects. - * If this field is not set and there are both overlapping and additional - * databases proposed, an error will be returned. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.start_external_sync.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_StartExternalSync_async - */ + /** + * Start External primary instance migration. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.ExternalSyncMode} request.syncMode + * External sync mode. + * @param {boolean} request.skipVerification + * Whether to skip the verification step (VESS). + * @param {google.cloud.sql.v1beta4.MySqlSyncConfig} request.mysqlSyncConfig + * MySQL-specific settings for start external sync. + * @param {google.cloud.sql.v1beta4.ExternalSyncParallelLevel} [request.syncParallelLevel] + * Optional. Parallel level for initial data sync. Currently only applicable + * for MySQL. + * @param {google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest.MigrationType} [request.migrationType] + * Optional. MigrationType configures the migration to use physical files or + * logical dump files. If not set, then the logical dump file configuration is + * used. Valid values are `LOGICAL` or `PHYSICAL`. Only applicable to MySQL. + * @param {boolean} [request.replicaOverwriteEnabled] + * Optional. MySQL only. True if end-user has confirmed that this SES call + * will wipe replica databases overlapping with the proposed selected_objects. + * If this field is not set and there are both overlapping and additional + * databases proposed, an error will be returned. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.start_external_sync.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_StartExternalSync_async + */ startExternalSync( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | undefined + ), + {} | undefined, + ] + >; startExternalSync( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startExternalSync( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + ): void; startExternalSync( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('startExternalSync request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('startExternalSync response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.startExternalSync(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest|undefined, - {}|undefined - ]) => { - this._log.info('startExternalSync 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); + return this.innerApiCalls + .startExternalSync(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesStartExternalSyncRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('startExternalSync 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; }); } -/** - * Perform Disk Shrink on primary instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.PerformDiskShrinkContext} request.body - * Perform disk shrink context. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.perform_disk_shrink.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PerformDiskShrink_async - */ + /** + * Perform Disk Shrink on primary instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.PerformDiskShrinkContext} request.body + * Perform disk shrink context. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.perform_disk_shrink.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PerformDiskShrink_async + */ performDiskShrink( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | undefined + ), + {} | undefined, + ] + >; performDiskShrink( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + ): void; performDiskShrink( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + ): void; performDiskShrink( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('performDiskShrink request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('performDiskShrink response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.performDiskShrink(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest|undefined, - {}|undefined - ]) => { - this._log.info('performDiskShrink 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); + return this.innerApiCalls + .performDiskShrink(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPerformDiskShrinkRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('performDiskShrink 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; }); } -/** - * Get Disk Shrink Config for a given instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigResponse|SqlInstancesGetDiskShrinkConfigResponse}. - * 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/v1beta4/sql_instances_service.get_disk_shrink_config.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_GetDiskShrinkConfig_async - */ + /** + * Get Disk Shrink Config for a given instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigResponse|SqlInstancesGetDiskShrinkConfigResponse}. + * 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/v1beta4/sql_instances_service.get_disk_shrink_config.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_GetDiskShrinkConfig_async + */ getDiskShrinkConfig( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | undefined + ), + {} | undefined, + ] + >; getDiskShrinkConfig( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getDiskShrinkConfig( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getDiskShrinkConfig( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getDiskShrinkConfig request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getDiskShrinkConfig response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getDiskShrinkConfig(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest|undefined, - {}|undefined - ]) => { - this._log.info('getDiskShrinkConfig 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); + return this.innerApiCalls + .getDiskShrinkConfig(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('getDiskShrinkConfig 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; }); } -/** - * Reset Replica Size to primary instance disk size. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL read replica instance name. - * @param {string} request.project - * ID of the project that contains the read replica. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.reset_replica_size.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ResetReplicaSize_async - */ + /** + * Reset Replica Size to primary instance disk size. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL read replica instance name. + * @param {string} request.project + * ID of the project that contains the read replica. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.reset_replica_size.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ResetReplicaSize_async + */ resetReplicaSize( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | undefined + ), + {} | undefined, + ] + >; resetReplicaSize( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetReplicaSize( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; resetReplicaSize( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('resetReplicaSize request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('resetReplicaSize response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.resetReplicaSize(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest|undefined, - {}|undefined - ]) => { - this._log.info('resetReplicaSize 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); + return this.innerApiCalls + .resetReplicaSize(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesResetReplicaSizeRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('resetReplicaSize 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; }); } -/** - * Get Latest Recovery Time for a given instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.protobuf.Timestamp} request.sourceInstanceDeletionTime - * The timestamp used to identify the time when the source instance is - * deleted. If this instance is deleted, then you must set the timestamp. - * @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.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeResponse|SqlInstancesGetLatestRecoveryTimeResponse}. - * 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/v1beta4/sql_instances_service.get_latest_recovery_time.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_GetLatestRecoveryTime_async - */ + /** + * Get Latest Recovery Time for a given instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.protobuf.Timestamp} request.sourceInstanceDeletionTime + * The timestamp used to identify the time when the source instance is + * deleted. If this instance is deleted, then you must set the timestamp. + * @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.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeResponse|SqlInstancesGetLatestRecoveryTimeResponse}. + * 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/v1beta4/sql_instances_service.get_latest_recovery_time.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_GetLatestRecoveryTime_async + */ getLatestRecoveryTime( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | undefined + ), + {} | undefined, + ] + >; getLatestRecoveryTime( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getLatestRecoveryTime( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; getLatestRecoveryTime( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('getLatestRecoveryTime request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('getLatestRecoveryTime response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.getLatestRecoveryTime(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest|undefined, - {}|undefined - ]) => { - this._log.info('getLatestRecoveryTime 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); + return this.innerApiCalls + .getLatestRecoveryTime(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('getLatestRecoveryTime 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; }); } -/** - * Execute SQL statements. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Database instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.ExecuteSqlPayload} request.body - * The request body. - * @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.cloud.sql.v1beta4.SqlInstancesExecuteSqlResponse|SqlInstancesExecuteSqlResponse}. - * 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/v1beta4/sql_instances_service.execute_sql.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ExecuteSql_async - */ + /** + * Execute SQL statements. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Database instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.ExecuteSqlPayload} request.body + * The request body. + * @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.cloud.sql.v1beta4.SqlInstancesExecuteSqlResponse|SqlInstancesExecuteSqlResponse}. + * 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/v1beta4/sql_instances_service.execute_sql.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ExecuteSql_async + */ executeSql( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | undefined + ), + {} | undefined, + ] + >; executeSql( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + ): void; executeSql( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + ): void; executeSql( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('executeSql request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('executeSql response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.executeSql(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest|undefined, - {}|undefined - ]) => { - this._log.info('executeSql 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); + return this.innerApiCalls + .executeSql(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('executeSql 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; }); } -/** - * Acquire a lease for the setup of SQL Server Reporting Services (SSRS). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This doesn't include the project ID. It's - * composed of lowercase letters, numbers, and hyphens, and it must start with - * a letter. The total length must be 98 characters or less (Example: - * instance-id). - * @param {string} request.project - * Required. ID of the project that contains the instance (Example: - * project-id). - * @param {google.cloud.sql.v1beta4.InstancesAcquireSsrsLeaseRequest} request.body - * The body for request to acquire an SSRS lease. - * @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.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseResponse|SqlInstancesAcquireSsrsLeaseResponse}. - * 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/v1beta4/sql_instances_service.acquire_ssrs_lease.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AcquireSsrsLease_async - */ + /** + * Acquire a lease for the setup of SQL Server Reporting Services (SSRS). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This doesn't include the project ID. It's + * composed of lowercase letters, numbers, and hyphens, and it must start with + * a letter. The total length must be 98 characters or less (Example: + * instance-id). + * @param {string} request.project + * Required. ID of the project that contains the instance (Example: + * project-id). + * @param {google.cloud.sql.v1beta4.InstancesAcquireSsrsLeaseRequest} request.body + * The body for request to acquire an SSRS lease. + * @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.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseResponse|SqlInstancesAcquireSsrsLeaseResponse}. + * 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/v1beta4/sql_instances_service.acquire_ssrs_lease.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_AcquireSsrsLease_async + */ acquireSsrsLease( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + >; acquireSsrsLease( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; acquireSsrsLease( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; acquireSsrsLease( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('acquireSsrsLease request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('acquireSsrsLease response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.acquireSsrsLease(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest|undefined, - {}|undefined - ]) => { - this._log.info('acquireSsrsLease 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); + return this.innerApiCalls + .acquireSsrsLease(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('acquireSsrsLease 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; }); } -/** - * Release a lease for the setup of SQL Server Reporting Services (SSRS). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. The Cloud SQL instance ID. This doesn't include the project ID. - * It's composed of lowercase letters, numbers, and hyphens, and it must start - * with a letter. The total length must be 98 characters or less (Example: - * instance-id). - * @param {string} request.project - * Required. The ID of the project that contains the instance (Example: - * project-id). - * @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.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseResponse|SqlInstancesReleaseSsrsLeaseResponse}. - * 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/v1beta4/sql_instances_service.release_ssrs_lease.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ReleaseSsrsLease_async - */ + /** + * Release a lease for the setup of SQL Server Reporting Services (SSRS). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. The Cloud SQL instance ID. This doesn't include the project ID. + * It's composed of lowercase letters, numbers, and hyphens, and it must start + * with a letter. The total length must be 98 characters or less (Example: + * instance-id). + * @param {string} request.project + * Required. The ID of the project that contains the instance (Example: + * project-id). + * @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.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseResponse|SqlInstancesReleaseSsrsLeaseResponse}. + * 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/v1beta4/sql_instances_service.release_ssrs_lease.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_ReleaseSsrsLease_async + */ releaseSsrsLease( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + >; releaseSsrsLease( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; releaseSsrsLease( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): void; releaseSsrsLease( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('releaseSsrsLease request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('releaseSsrsLease response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.releaseSsrsLease(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, - protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest|undefined, - {}|undefined - ]) => { - this._log.info('releaseSsrsLease 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); + return this.innerApiCalls + .releaseSsrsLease(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('releaseSsrsLease 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; }); } -/** - * Execute MVU Pre-checks - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Required. Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Required. Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.InstancesPreCheckMajorVersionUpgradeRequest} request.body - * Required. The context for request to perform the pre-check major version - * upgrade operation. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.pre_check_major_version_upgrade.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PreCheckMajorVersionUpgrade_async - */ + /** + * Execute MVU Pre-checks + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Required. Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Required. Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.InstancesPreCheckMajorVersionUpgradeRequest} request.body + * Required. The context for request to perform the pre-check major version + * upgrade operation. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.pre_check_major_version_upgrade.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PreCheckMajorVersionUpgrade_async + */ preCheckMajorVersionUpgrade( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | undefined + ), + {} | undefined, + ] + >; preCheckMajorVersionUpgrade( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; preCheckMajorVersionUpgrade( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + ): void; preCheckMajorVersionUpgrade( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('preCheckMajorVersionUpgrade request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('preCheckMajorVersionUpgrade response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.preCheckMajorVersionUpgrade(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest|undefined, - {}|undefined - ]) => { - this._log.info('preCheckMajorVersionUpgrade 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); + return this.innerApiCalls + .preCheckMajorVersionUpgrade(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPreCheckMajorVersionUpgradeRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('preCheckMajorVersionUpgrade 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; }); } -/** - * Point in time restore for an instance managed by Google Cloud Backup and - * Disaster Recovery. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The parent resource where you created this instance. - * Format: projects/{project} - * @param {google.cloud.sql.v1beta4.PointInTimeRestoreContext} request.context - * Required. The context for request to perform a PITR on a Google Cloud - * Backup and Disaster Recovery managed instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_instances_service.point_in_time_restore.js - * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PointInTimeRestore_async - */ + /** + * Point in time restore for an instance managed by Google Cloud Backup and + * Disaster Recovery. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The parent resource where you created this instance. + * Format: projects/{project} + * @param {google.cloud.sql.v1beta4.PointInTimeRestoreContext} request.context + * Required. The context for request to perform a PITR on a Google Cloud + * Backup and Disaster Recovery managed instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_instances_service.point_in_time_restore.js + * region_tag:sqladmin_v1beta4_generated_SqlInstancesService_PointInTimeRestore_async + */ pointInTimeRestore( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | undefined + ), + {} | undefined, + ] + >; pointInTimeRestore( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + ): void; pointInTimeRestore( - request: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + ): void; pointInTimeRestore( - request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | undefined + ), + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'parent': request.parent ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + parent: request.parent ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('pointInTimeRestore request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('pointInTimeRestore response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.pointInTimeRestore(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest|undefined, - {}|undefined - ]) => { - this._log.info('pointInTimeRestore 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); + return this.innerApiCalls + .pointInTimeRestore(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + ( + | protos.google.cloud.sql.v1beta4.ISqlInstancesPointInTimeRestoreRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('pointInTimeRestore 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -4713,12 +6818,11 @@ export class SqlInstancesServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -4751,7 +6855,7 @@ export class SqlInstancesServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -4767,7 +6871,7 @@ export class SqlInstancesServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -4802,7 +6906,7 @@ export class SqlInstancesServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -4827,13 +6931,15 @@ export class SqlInstancesServiceClient { */ close(): Promise { if (this.sqlInstancesServiceStub && !this._terminated) { - return this.sqlInstancesServiceStub.then(stub => { + return this.sqlInstancesServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_operations_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_operations_service_client.ts index 8889aa76f6d8..ceb1fa381192 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_operations_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_operations_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlOperationsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlOperationsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlOperationsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlOperationsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlOperationsServiceClient. @@ -100,21 +107,42 @@ export class SqlOperationsServiceClient { * const client = new SqlOperationsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlOperationsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlOperationsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlOperationsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlOperationsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlOperationsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlOperationsService', + 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 @@ -224,36 +251,40 @@ export class SqlOperationsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlOperationsService. this.sqlOperationsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlOperationsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlOperationsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlOperationsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlOperationsServiceStubMethods = - ['get', 'list', 'cancel']; + const sqlOperationsServiceStubMethods = ['get', 'list', 'cancel']; for (const methodName of sqlOperationsServiceStubMethods) { const callPromise = this.sqlOperationsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +299,14 @@ export class SqlOperationsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +317,14 @@ export class SqlOperationsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +357,7 @@ export class SqlOperationsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +367,9 @@ export class SqlOperationsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,305 +380,428 @@ export class SqlOperationsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Retrieves an instance operation that has been performed on an instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.operation - * Instance operation ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_operations_service.get.js - * region_tag:sqladmin_v1beta4_generated_SqlOperationsService_Get_async - */ + /** + * Retrieves an instance operation that has been performed on an instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.operation + * Instance operation ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_operations_service.get.js + * region_tag:sqladmin_v1beta4_generated_SqlOperationsService_Get_async + */ get( - request?: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'operation': request.operation ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + operation: request.operation ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlOperationsGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Lists all instance operations that have been performed on the given Cloud - * SQL instance in the reverse chronological order of the start time. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {number} request.maxResults - * Maximum number of operations per response. - * @param {string} request.pageToken - * A previously-returned page token representing part of the larger set of - * results to view. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.OperationsListResponse|OperationsListResponse}. - * 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/v1beta4/sql_operations_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlOperationsService_List_async - */ + /** + * Lists all instance operations that have been performed on the given Cloud + * SQL instance in the reverse chronological order of the start time. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {number} request.maxResults + * Maximum number of operations per response. + * @param {string} request.pageToken + * A previously-returned page token representing part of the larger set of + * results to view. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.OperationsListResponse|OperationsListResponse}. + * 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/v1beta4/sql_operations_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlOperationsService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperationsListResponse, - protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperationsListResponse, + protos.google.cloud.sql.v1beta4.ISqlOperationsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Cancels an instance operation that has been performed on an instance. - * Ordinarily, this method name should be `CancelSqlOperation`. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.operation - * Instance operation ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.protobuf.Empty|Empty}. - * 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/v1beta4/sql_operations_service.cancel.js - * region_tag:sqladmin_v1beta4_generated_SqlOperationsService_Cancel_async - */ + /** + * Cancels an instance operation that has been performed on an instance. + * Ordinarily, this method name should be `CancelSqlOperation`. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.operation + * Instance operation ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.protobuf.Empty|Empty}. + * 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/v1beta4/sql_operations_service.cancel.js + * region_tag:sqladmin_v1beta4_generated_SqlOperationsService_Cancel_async + */ cancel( - request?: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest | undefined, + {} | undefined, + ] + >; cancel( - request: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + >, + ): void; cancel( - request: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + >, + ): void; cancel( - request?: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.protobuf.IEmpty, + protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'operation': request.operation ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + operation: request.operation ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('cancel request %j', request); - const wrappedCallback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('cancel response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.cancel(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.protobuf.IEmpty, - protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest|undefined, - {}|undefined - ]) => { - this._log.info('cancel 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); + return this.innerApiCalls + .cancel(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.protobuf.IEmpty, + ( + | protos.google.cloud.sql.v1beta4.ISqlOperationsCancelRequest + | undefined + ), + {} | undefined, + ]) => { + this._log.info('cancel 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -669,12 +836,11 @@ export class SqlOperationsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -707,7 +873,7 @@ export class SqlOperationsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -723,7 +889,7 @@ export class SqlOperationsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -758,7 +924,7 @@ export class SqlOperationsServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -783,13 +949,15 @@ export class SqlOperationsServiceClient { */ close(): Promise { if (this.sqlOperationsServiceStub && !this._terminated) { - return this.sqlOperationsServiceStub.then(stub => { + return this.sqlOperationsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_ssl_certs_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_ssl_certs_service_client.ts index 017e4fb36684..aeb3ba6c3aa3 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_ssl_certs_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_ssl_certs_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlSslCertsServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlSslCertsServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlSslCertsServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlSslCertsServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlSslCertsServiceClient. @@ -100,21 +107,42 @@ export class SqlSslCertsServiceClient { * const client = new SqlSslCertsServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlSslCertsServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlSslCertsServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlSslCertsServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,17 +207,20 @@ export class SqlSslCertsServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' + 'projects/{project}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlSslCertsService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlSslCertsService', + 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 @@ -224,36 +251,40 @@ export class SqlSslCertsServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlSslCertsService. this.sqlSslCertsServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlSslCertsService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlSslCertsService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlSslCertsService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlSslCertsServiceStubMethods = - ['delete', 'get', 'insert', 'list']; + const sqlSslCertsServiceStubMethods = ['delete', 'get', 'insert', 'list']; for (const methodName of sqlSslCertsServiceStubMethods) { const callPromise = this.sqlSslCertsServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -268,8 +299,14 @@ export class SqlSslCertsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -280,8 +317,14 @@ export class SqlSslCertsServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -314,7 +357,7 @@ export class SqlSslCertsServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -324,8 +367,9 @@ export class SqlSslCertsServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -336,408 +380,562 @@ export class SqlSslCertsServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes the SSL certificate. For First Generation instances, the - * certificate remains valid until the instance is restarted. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.sha1Fingerprint - * Sha1 FingerPrint. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_ssl_certs_service.delete.js - * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_Delete_async - */ + /** + * Deletes the SSL certificate. For First Generation instances, the + * certificate remains valid until the instance is restarted. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.sha1Fingerprint + * Sha1 FingerPrint. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_ssl_certs_service.delete.js + * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'sha1_fingerprint': request.sha1Fingerprint ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + sha1_fingerprint: request.sha1Fingerprint ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlSslCertsDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a particular SSL certificate. Does not include the private key - * (required for usage). The private key must be saved from the response to - * initial creation. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.sha1Fingerprint - * Sha1 FingerPrint. - * @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.cloud.sql.v1beta4.SslCert|SslCert}. - * 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/v1beta4/sql_ssl_certs_service.get.js - * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_Get_async - */ + /** + * Retrieves a particular SSL certificate. Does not include the private key + * (required for usage). The private key must be saved from the response to + * initial creation. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.sha1Fingerprint + * Sha1 FingerPrint. + * @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.cloud.sql.v1beta4.SslCert|SslCert}. + * 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/v1beta4/sql_ssl_certs_service.get.js + * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_Get_async + */ get( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCert, + protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCert, + protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'sha1_fingerprint': request.sha1Fingerprint ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + sha1_fingerprint: request.sha1Fingerprint ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISslCert, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISslCert, - protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISslCert, + protos.google.cloud.sql.v1beta4.ISqlSslCertsGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Creates an SSL certificate and returns it along with the private key and - * server certificate authority. The new certificate will not be usable until - * the instance is restarted. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.SslCertsInsertRequest} request.body - * @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.cloud.sql.v1beta4.SslCertsInsertResponse|SslCertsInsertResponse}. - * 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/v1beta4/sql_ssl_certs_service.insert.js - * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_Insert_async - */ + /** + * Creates an SSL certificate and returns it along with the private key and + * server certificate authority. The new certificate will not be usable until + * the instance is restarted. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.SslCertsInsertRequest} request.body + * @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.cloud.sql.v1beta4.SslCertsInsertResponse|SslCertsInsertResponse}. + * 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/v1beta4/sql_ssl_certs_service.insert.js + * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse, + protos.google.cloud.sql.v1beta4.ISqlSslCertsInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists all of the current SSL certificates for the instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Cloud SQL instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.SslCertsListResponse|SslCertsListResponse}. - * 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/v1beta4/sql_ssl_certs_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_List_async - */ + /** + * Lists all of the current SSL certificates for the instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Cloud SQL instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.SslCertsListResponse|SslCertsListResponse}. + * 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/v1beta4/sql_ssl_certs_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlSslCertsService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest + | null + | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest + | null + | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + | protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ISslCertsListResponse, - protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ISslCertsListResponse, + protos.google.cloud.sql.v1beta4.ISqlSslCertsListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -772,12 +970,11 @@ export class SqlSslCertsServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -810,7 +1007,7 @@ export class SqlSslCertsServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -826,7 +1023,7 @@ export class SqlSslCertsServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -861,7 +1058,7 @@ export class SqlSslCertsServiceClient { * @param {string} project * @returns {string} Resource name string. */ - projectPath(project:string) { + projectPath(project: string) { return this.pathTemplates.projectPathTemplate.render({ project: project, }); @@ -886,13 +1083,15 @@ export class SqlSslCertsServiceClient { */ close(): Promise { if (this.sqlSslCertsServiceStub && !this._terminated) { - return this.sqlSslCertsServiceStub.then(stub => { + return this.sqlSslCertsServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_tiers_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_tiers_service_client.ts index 3491ba057e4e..599f74109a04 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_tiers_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_tiers_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -44,7 +51,7 @@ export class SqlTiersServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -57,10 +64,10 @@ export class SqlTiersServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlTiersServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlTiersServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlTiersServiceClient. @@ -101,21 +108,42 @@ export class SqlTiersServiceClient { * const client = new SqlTiersServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlTiersServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -140,7 +168,7 @@ export class SqlTiersServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -154,15 +182,11 @@ export class SqlTiersServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -184,14 +208,17 @@ export class SqlTiersServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlTiersService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlTiersService', + 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 @@ -222,36 +249,40 @@ export class SqlTiersServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlTiersService. this.sqlTiersServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlTiersService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlTiersService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlTiersService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlTiersServiceStubMethods = - ['list']; + const sqlTiersServiceStubMethods = ['list']; for (const methodName of sqlTiersServiceStubMethods) { const callPromise = this.sqlTiersServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -266,8 +297,14 @@ export class SqlTiersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -278,8 +315,14 @@ export class SqlTiersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -312,7 +355,7 @@ export class SqlTiersServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -322,8 +365,9 @@ export class SqlTiersServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -334,103 +378,137 @@ export class SqlTiersServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Lists all available machine types (tiers) for Cloud SQL, for example, - * `db-custom-1-3840`. For related information, see [Pricing](/sql/pricing). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Project ID of the project for which to list tiers. - * @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.cloud.sql.v1beta4.TiersListResponse|TiersListResponse}. - * 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/v1beta4/sql_tiers_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlTiersService_List_async - */ + /** + * Lists all available machine types (tiers) for Cloud SQL, for example, + * `db-custom-1-3840`. For related information, see [Pricing](/sql/pricing). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Project ID of the project for which to list tiers. + * @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.cloud.sql.v1beta4.TiersListResponse|TiersListResponse}. + * 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/v1beta4/sql_tiers_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlTiersService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ITiersListResponse, + protos.google.cloud.sql.v1beta4.ISqlTiersListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.ITiersListResponse, + protos.google.cloud.sql.v1beta4.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.ITiersListResponse, + protos.google.cloud.sql.v1beta4.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlTiersListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlTiersListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.ITiersListResponse, + protos.google.cloud.sql.v1beta4.ISqlTiersListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.ITiersListResponse, + protos.google.cloud.sql.v1beta4.ISqlTiersListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.ITiersListResponse, + | protos.google.cloud.sql.v1beta4.ISqlTiersListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.ITiersListResponse, - protos.google.cloud.sql.v1beta4.ISqlTiersListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.ITiersListResponse, + protos.google.cloud.sql.v1beta4.ISqlTiersListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -465,12 +543,11 @@ export class SqlTiersServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -503,7 +580,7 @@ export class SqlTiersServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -519,7 +596,7 @@ export class SqlTiersServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -556,13 +633,15 @@ export class SqlTiersServiceClient { */ close(): Promise { if (this.sqlTiersServiceStub && !this._terminated) { - return this.sqlTiersServiceStub.then(stub => { + return this.sqlTiersServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/src/v1beta4/sql_users_service_client.ts b/packages/google-cloud-sql/src/v1beta4/sql_users_service_client.ts index 0f2b60605587..2f95c603fe50 100644 --- a/packages/google-cloud-sql/src/v1beta4/sql_users_service_client.ts +++ b/packages/google-cloud-sql/src/v1beta4/sql_users_service_client.ts @@ -18,11 +18,18 @@ /* global window */ import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, LocationsClient, LocationProtos} from 'google-gax'; +import type { + Callback, + CallOptions, + Descriptors, + ClientOptions, + LocationsClient, + LocationProtos, +} from 'google-gax'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); -import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +import { loggingUtils as logging, decodeAnyProtosInArray } from 'google-gax'; /** * Client JSON configuration object, loaded from @@ -43,7 +50,7 @@ export class SqlUsersServiceClient { private _gaxModule: typeof gax | typeof gax.fallback; private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; + private _defaults: { [method: string]: gax.CallSettings }; private _universeDomain: string; private _servicePath: string; private _log = logging.log('sql'); @@ -56,10 +63,10 @@ export class SqlUsersServiceClient { batching: {}, }; warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; + innerApiCalls: { [name: string]: Function }; locationsClient: LocationsClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - sqlUsersServiceStub?: Promise<{[name: string]: Function}>; + pathTemplates: { [name: string]: gax.PathTemplate }; + sqlUsersServiceStub?: Promise<{ [name: string]: Function }>; /** * Construct an instance of SqlUsersServiceClient. @@ -100,21 +107,42 @@ export class SqlUsersServiceClient { * const client = new SqlUsersServiceClient({fallback: true}, gax); * ``` */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + constructor( + opts?: ClientOptions, + gaxInstance?: typeof gax | typeof gax.fallback, + ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof SqlUsersServiceClient; - if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { - throw new Error('Please set either universe_domain or universeDomain, but not both.'); + 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'; + 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 = 'sqladmin.' + this._universeDomain; - const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + 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); + const fallback = + opts?.fallback ?? + (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); // Request numeric enum values if REST transport is used. opts.numericEnums = true; @@ -139,7 +167,7 @@ export class SqlUsersServiceClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Set useJWTAccessWithScope on the auth object. this.auth.useJWTAccessWithScope = true; @@ -153,15 +181,11 @@ export class SqlUsersServiceClient { } this.locationsClient = new this._gaxModule.LocationsClient( this._gaxGrpc, - opts + opts, ); - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process === 'object' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -183,14 +207,17 @@ export class SqlUsersServiceClient { // Create useful helper objects for these. this.pathTemplates = { backupPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/backups/{backup}' + 'projects/{project}/backups/{backup}', ), }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.sql.v1beta4.SqlUsersService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + 'google.cloud.sql.v1beta4.SqlUsersService', + 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 @@ -221,36 +248,46 @@ export class SqlUsersServiceClient { // Put together the "service stub" for // google.cloud.sql.v1beta4.SqlUsersService. this.sqlUsersServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.sql.v1beta4.SqlUsersService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( + 'google.cloud.sql.v1beta4.SqlUsersService', + ) + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.sql.v1beta4.SqlUsersService, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + 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 sqlUsersServiceStubMethods = - ['delete', 'get', 'insert', 'list', 'update']; + const sqlUsersServiceStubMethods = [ + 'delete', + 'get', + 'insert', + 'list', + 'update', + ]; for (const methodName of sqlUsersServiceStubMethods) { const callPromise = this.sqlUsersServiceStub.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) => () => { + (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 = - undefined; + const descriptor = undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], descriptor, - this._opts.fallback + this._opts.fallback, ); this.innerApiCalls[methodName] = apiCall; @@ -265,8 +302,14 @@ export class SqlUsersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -277,8 +320,14 @@ export class SqlUsersServiceClient { * @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'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning', + ); } return 'sqladmin.googleapis.com'; } @@ -311,7 +360,7 @@ export class SqlUsersServiceClient { static get scopes() { return [ 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/sqlservice.admin' + 'https://www.googleapis.com/auth/sqlservice.admin', ]; } @@ -321,8 +370,9 @@ export class SqlUsersServiceClient { * 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 { + getProjectId( + callback?: Callback, + ): Promise | void { if (callback) { this.auth.getProjectId(callback); return; @@ -333,515 +383,685 @@ export class SqlUsersServiceClient { // ------------------- // -- Service calls -- // ------------------- -/** - * Deletes a user from a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.host - * Host of the user in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.name - * Name of the user in the instance. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_users_service.delete.js - * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Delete_async - */ + /** + * Deletes a user from a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.host + * Host of the user in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.name + * Name of the user in the instance. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_users_service.delete.js + * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Delete_async + */ delete( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest | undefined, + {} | undefined, + ] + >; delete( - request: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + ): void; delete( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('delete request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('delete response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.delete(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest|undefined, - {}|undefined - ]) => { - this._log.info('delete 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); + return this.innerApiCalls + .delete(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersDeleteRequest | undefined, + {} | undefined, + ]) => { + this._log.info('delete 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; }); } -/** - * Retrieves a resource containing information about a user. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.name - * User of the instance. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string} request.host - * Host of a user of the instance. - * @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.cloud.sql.v1beta4.User|User}. - * 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/v1beta4/sql_users_service.get.js - * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Get_async - */ + /** + * Retrieves a resource containing information about a user. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.name + * User of the instance. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string} request.host + * Host of a user of the instance. + * @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.cloud.sql.v1beta4.User|User}. + * 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/v1beta4/sql_users_service.get.js + * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Get_async + */ get( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IUser, + protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest | undefined, + {} | undefined, + ] + >; get( - request: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IUser, + protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IUser, + protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + ): void; get( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IUser, + protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IUser, + protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', - 'name': request.name ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + name: request.name ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('get request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IUser, + | protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('get response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.get(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IUser, - protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest|undefined, - {}|undefined - ]) => { - this._log.info('get 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); + return this.innerApiCalls + .get(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IUser, + protos.google.cloud.sql.v1beta4.ISqlUsersGetRequest | undefined, + {} | undefined, + ]) => { + this._log.info('get 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; }); } -/** - * Creates a new user in a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {google.cloud.sql.v1beta4.User} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_users_service.insert.js - * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Insert_async - */ + /** + * Creates a new user in a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {google.cloud.sql.v1beta4.User} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_users_service.insert.js + * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Insert_async + */ insert( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest | undefined, + {} | undefined, + ] + >; insert( - request: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + ): void; insert( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('insert request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('insert response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.insert(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest|undefined, - {}|undefined - ]) => { - this._log.info('insert 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); + return this.innerApiCalls + .insert(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersInsertRequest | undefined, + {} | undefined, + ]) => { + this._log.info('insert 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; }); } -/** - * Lists users in the specified Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @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.cloud.sql.v1beta4.UsersListResponse|UsersListResponse}. - * 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/v1beta4/sql_users_service.list.js - * region_tag:sqladmin_v1beta4_generated_SqlUsersService_List_async - */ + /** + * Lists users in the specified Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @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.cloud.sql.v1beta4.UsersListResponse|UsersListResponse}. + * 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/v1beta4/sql_users_service.list.js + * region_tag:sqladmin_v1beta4_generated_SqlUsersService_List_async + */ list( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IUsersListResponse, + protos.google.cloud.sql.v1beta4.ISqlUsersListRequest | undefined, + {} | undefined, + ] + >; list( - request: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IUsersListResponse, + protos.google.cloud.sql.v1beta4.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IUsersListResponse, + protos.google.cloud.sql.v1beta4.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + ): void; list( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlUsersListRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlUsersListRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IUsersListResponse, + protos.google.cloud.sql.v1beta4.ISqlUsersListRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IUsersListResponse, + protos.google.cloud.sql.v1beta4.ISqlUsersListRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('list request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IUsersListResponse, + | protos.google.cloud.sql.v1beta4.ISqlUsersListRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('list response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.list(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IUsersListResponse, - protos.google.cloud.sql.v1beta4.ISqlUsersListRequest|undefined, - {}|undefined - ]) => { - this._log.info('list 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); + return this.innerApiCalls + .list(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IUsersListResponse, + protos.google.cloud.sql.v1beta4.ISqlUsersListRequest | undefined, + {} | undefined, + ]) => { + this._log.info('list 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; }); } -/** - * Updates an existing user in a Cloud SQL instance. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} [request.host] - * Optional. Host of the user in the instance. - * @param {string} request.instance - * Database instance ID. This does not include the project ID. - * @param {string} request.name - * Name of the user in the instance. - * @param {string} request.project - * Project ID of the project that contains the instance. - * @param {string[]} [request.databaseRoles] - * Optional. List of database roles to grant to the user. body.database_roles - * will be ignored for update request. - * @param {boolean} [request.revokeExistingRoles] - * Optional. Specifies whether to revoke existing roles that are not present - * in the `database_roles` field. If `false` or unset, the database roles - * specified in `database_roles` are added to the user's existing roles. - * @param {google.cloud.sql.v1beta4.User} request.body - * @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.cloud.sql.v1beta4.Operation|Operation}. - * 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/v1beta4/sql_users_service.update.js - * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Update_async - */ + /** + * Updates an existing user in a Cloud SQL instance. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} [request.host] + * Optional. Host of the user in the instance. + * @param {string} request.instance + * Database instance ID. This does not include the project ID. + * @param {string} request.name + * Name of the user in the instance. + * @param {string} request.project + * Project ID of the project that contains the instance. + * @param {string[]} [request.databaseRoles] + * Optional. List of database roles to grant to the user. body.database_roles + * will be ignored for update request. + * @param {boolean} [request.revokeExistingRoles] + * Optional. Specifies whether to revoke existing roles that are not present + * in the `database_roles` field. If `false` or unset, the database roles + * specified in `database_roles` are added to the user's existing roles. + * @param {google.cloud.sql.v1beta4.User} request.body + * @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.cloud.sql.v1beta4.Operation|Operation}. + * 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/v1beta4/sql_users_service.update.js + * region_tag:sqladmin_v1beta4_generated_SqlUsersService_Update_async + */ update( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|undefined, {}|undefined - ]>; + request?: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, + options?: CallOptions, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest | undefined, + {} | undefined, + ] + >; update( - request: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, - callback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>): void; + request: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, + callback: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + ): void; update( - request?: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< + request?: protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest, + optionsOrCallback?: + | CallOptions + | Callback< protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|undefined, {}|undefined - ]>|void { + | protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest | null | undefined, + {} | null | undefined + >, + ): Promise< + [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest | undefined, + {} | undefined, + ] + > | void { request = request || {}; let options: CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } - else { + } 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({ - 'project': request.project ?? '', - 'instance': request.instance ?? '', + options.otherArgs.headers['x-goog-request-params'] = + this._gaxModule.routingHeader.fromParams({ + project: request.project ?? '', + instance: request.instance ?? '', + }); + this.initialize().catch((err) => { + throw err; }); - this.initialize().catch(err => {throw err}); this._log.info('update request %j', request); - const wrappedCallback: Callback< - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|null|undefined, - {}|null|undefined>|undefined = callback + const wrappedCallback: + | Callback< + protos.google.cloud.sql.v1beta4.IOperation, + | protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest + | null + | undefined, + {} | null | undefined + > + | undefined = callback ? (error, response, options, rawResponse) => { this._log.info('update response %j', response); callback!(error, response, options, rawResponse); // We verified callback above. } : undefined; - return this.innerApiCalls.update(request, options, wrappedCallback) - ?.then(([response, options, rawResponse]: [ - protos.google.cloud.sql.v1beta4.IOperation, - protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest|undefined, - {}|undefined - ]) => { - this._log.info('update 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); + return this.innerApiCalls + .update(request, options, wrappedCallback) + ?.then( + ([response, options, rawResponse]: [ + protos.google.cloud.sql.v1beta4.IOperation, + protos.google.cloud.sql.v1beta4.ISqlUsersUpdateRequest | undefined, + {} | undefined, + ]) => { + this._log.info('update 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; }); } -/** + /** * Gets information about a location. * * @param {Object} request @@ -876,12 +1096,11 @@ export class SqlUsersServiceClient { | null | undefined, {} | null | undefined - > + >, ): Promise { return this.locationsClient.getLocation(request, options, callback); } - -/** + /** * Lists information about the supported locations for this service. Returns an iterable object. * * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. @@ -914,7 +1133,7 @@ export class SqlUsersServiceClient { */ listLocationsAsync( request: LocationProtos.google.cloud.location.IListLocationsRequest, - options?: CallOptions + options?: CallOptions, ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } @@ -930,7 +1149,7 @@ export class SqlUsersServiceClient { * @param {string} backup * @returns {string} Resource name string. */ - backupPath(project:string,backup:string) { + backupPath(project: string, backup: string) { return this.pathTemplates.backupPathTemplate.render({ project: project, backup: backup, @@ -967,13 +1186,15 @@ export class SqlUsersServiceClient { */ close(): Promise { if (this.sqlUsersServiceStub && !this._terminated) { - return this.sqlUsersServiceStub.then(stub => { + return this.sqlUsersServiceStub.then((stub) => { this._log.info('ending gRPC channel'); this._terminated = true; stub.close(); - this.locationsClient.close().catch(err => {throw err}); + this.locationsClient.close().catch((err) => { + throw err; + }); }); } return Promise.resolve(); } -} \ No newline at end of file +} diff --git a/packages/google-cloud-sql/system-test/install.ts b/packages/google-cloud-sql/system-test/install.ts index f66069aa3940..ccf167042d2e 100644 --- a/packages/google-cloud-sql/system-test/install.ts +++ b/packages/google-cloud-sql/system-test/install.ts @@ -16,34 +16,36 @@ // ** 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'; +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() { + 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() - } + ts: readFileSync( + './system-test/fixtures/sample/src/index.ts', + ).toString(), + }, }; await packNTest(options); }); - it('JavaScript code', async function() { + it('JavaScript code', async function () { this.timeout(300000); const options = { packageDir: process.cwd(), sample: { description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } + cjs: readFileSync( + './system-test/fixtures/sample/src/index.js', + ).toString(), + }, }; await packNTest(options); }); - }); diff --git a/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1.ts index ef97c1615c76..39a4cbb474bb 100644 --- a/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1.ts @@ -19,927 +19,1174 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlbackuprunsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlBackupRunsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); - 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 = sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + it('has universeDomain', () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); + 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 = + sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('has port', () => { - const port = sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); - assert(client); + 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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('should create a client with gRPC fallback', () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - fallback: true, + 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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + universeDomain: 'configured.example.com', }); - assert(client); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); - await client.initialize(); - assert(client.sqlBackupRunsServiceStub); + it('has port', () => { + const port = + sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlBackupRunsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); + await client.initialize(); + assert(client.sqlBackupRunsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlBackupRunsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; + }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - 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); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + 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()); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); - }); - - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.BackupRun() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.BackupRun() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IBackupRun|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.BackupRunsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.BackupRunsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IBackupRunsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - 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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - 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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - 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)); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + 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('delete', () => { + it('invokes delete without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes delete without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes delete with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes delete with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); + + describe('get', () => { + it('invokes get without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.BackupRun(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.BackupRun(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IBackupRun | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); + + describe('insert', () => { + it('invokes insert without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.BackupRunsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.BackupRunsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IBackupRunsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + 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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + 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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlbackuprunsserviceModule.v1.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1beta4.ts index e6f331aed7d4..31018716d40f 100644 --- a/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_backup_runs_service_v1beta4.ts @@ -19,957 +19,1215 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlbackuprunsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlBackupRunsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); - 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 = sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + it('has universeDomain', () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); + 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 = + sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient + .servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('has port', () => { - const port = sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); - assert(client); + 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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('should create a client with gRPC fallback', () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - fallback: true, + 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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + universeDomain: 'configured.example.com', }); - assert(client); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); - await client.initialize(); - assert(client.sqlBackupRunsServiceStub); + it('has port', () => { + const port = + sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlBackupRunsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); + await client.initialize(); + assert(client.sqlBackupRunsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlBackupRunsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlBackupRunsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; + }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - 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); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + 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()); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', ['id']); - request.id = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); - }); - - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.BackupRun() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.BackupRun() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IBackupRun|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', ['id']); - request.id = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.BackupRunsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.BackupRunsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IBackupRunsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with closed client', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - 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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - 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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - 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)); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + 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('delete', () => { + it('invokes delete without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes delete without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes delete with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes delete with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsDeleteRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + describe('get', () => { + it('invokes get without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.BackupRun(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes get without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.BackupRun(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IBackupRun | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&id=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsGetRequest', + ['id'], + ); + request.id = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); + + describe('insert', () => { + it('invokes insert without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.BackupRunsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list without error using callback', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.BackupRunsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IBackupRunsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with closed client', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlBackupRunsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlBackupRunsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + 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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + 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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); + + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = + new sqlbackuprunsserviceModule.v1beta4.SqlBackupRunsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_backups_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_backups_service_v1.ts index 7cd5fd683143..e0e3601d826c 100644 --- a/packages/google-cloud-sql/test/gapic_sql_backups_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_backups_service_v1.ts @@ -19,1161 +19,1417 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlbackupsserviceModule from '../src'; -import {PassThrough} from 'stream'; +import { PassThrough } from 'stream'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 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]); - } +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(); }); + } + 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({}); + }); } - return sinon.stub().returns(mockStream); + 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); +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.SqlBackupsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); - 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 = sqlbackupsserviceModule.v1.SqlBackupsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlbackupsserviceModule.v1.SqlBackupsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('has universeDomain', () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlbackupsserviceModule.v1.SqlBackupsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - 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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlbackupsserviceModule.v1.SqlBackupsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('has port', () => { - const port = sqlbackupsserviceModule.v1.SqlBackupsServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); - assert(client); + 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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('should create a client with gRPC fallback', () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - fallback: true, - }); - assert(client); + 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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient( + { universeDomain: 'configured.example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupsServiceStub, undefined); - await client.initialize(); - assert(client.sqlBackupsServiceStub); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('has close method for the initialized client', done => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlBackupsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has port', () => { + const port = sqlbackupsserviceModule.v1.SqlBackupsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('should create a client with no option', () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient(); + assert(client); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - 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('should create a client with gRPC fallback', () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - 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); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlBackupsServiceStub, undefined); + await client.initialize(); + assert(client.sqlBackupsServiceStub); }); - describe('createBackup', () => { - it('invokes createBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.createBackup = stubSimpleCall(expectedResponse); - const [response] = await client.createBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has close method for the initialized client', (done) => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlBackupsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('invokes createBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.createBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has close method for the non-initialized client', (done) => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlBackupsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('invokes createBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + 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('invokes createBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBackup(request), expectedError); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + 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('getBackup', () => { - it('invokes getBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Backup() - ); - client.innerApiCalls.getBackup = stubSimpleCall(expectedResponse); - const [response] = await client.getBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('createBackup', () => { + it('invokes createBackup without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.createBackup = stubSimpleCall(expectedResponse); + const [response] = await client.createBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Backup() - ); - client.innerApiCalls.getBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IBackup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes createBackup without error using callback', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.createBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes createBackup with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.createBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBackup(request), expectedError); - }); + it('invokes createBackup with closed client', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.createBackup(request), expectedError); }); + }); - describe('updateBackup', () => { - it('invokes updateBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.updateBackup = stubSimpleCall(expectedResponse); - const [response] = await client.updateBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('getBackup', () => { + it('invokes getBackup without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Backup(), + ); + client.innerApiCalls.getBackup = stubSimpleCall(expectedResponse); + const [response] = await client.getBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes updateBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.updateBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getBackup without error using callback', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Backup(), + ); + client.innerApiCalls.getBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IBackup | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes updateBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getBackup with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getBackup = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes updateBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBackup(request), expectedError); - }); + it('invokes getBackup with closed client', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.getBackup(request), expectedError); }); + }); - describe('deleteBackup', () => { - it('invokes deleteBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.deleteBackup = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('updateBackup', () => { + it('invokes updateBackup without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.updateBackup = stubSimpleCall(expectedResponse); + const [response] = await client.updateBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes deleteBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.deleteBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes updateBackup without error using callback', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.updateBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes deleteBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes updateBackup with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.updateBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes deleteBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBackup(request), expectedError); - }); + it('invokes updateBackup with closed client', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.updateBackup(request), expectedError); }); + }); - describe('listBackups', () => { - it('invokes listBackups without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - ]; - client.innerApiCalls.listBackups = stubSimpleCall(expectedResponse); - const [response] = await client.listBackups(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('deleteBackup', () => { + it('invokes deleteBackup without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.deleteBackup = stubSimpleCall(expectedResponse); + const [response] = await client.deleteBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listBackups without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - ]; - client.innerApiCalls.listBackups = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBackups( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IBackup[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes deleteBackup without error using callback', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.deleteBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listBackups with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBackups = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBackups(request), expectedError); - const actualRequest = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes deleteBackup with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.deleteBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listBackupsStream without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - ]; - client.descriptors.page.listBackups.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBackupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.sql.v1.Backup[] = []; - stream.on('data', (response: protos.google.cloud.sql.v1.Backup) => { - 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.listBackups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBackups, request)); - assert( - (client.descriptors.page.listBackups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + it('invokes deleteBackup with closed client', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.deleteBackup(request), expectedError); + }); + }); - it('invokes listBackupsStream with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBackups.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBackupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.sql.v1.Backup[] = []; - stream.on('data', (response: protos.google.cloud.sql.v1.Backup) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBackups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBackups, request)); - assert( - (client.descriptors.page.listBackups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + describe('listBackups', () => { + it('invokes listBackups without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + ]; + client.innerApiCalls.listBackups = stubSimpleCall(expectedResponse); + const [response] = await client.listBackups(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('uses async iteration with listBackups without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), - ]; - client.descriptors.page.listBackups.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.sql.v1.IBackup[] = []; - const iterable = client.listBackupsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes listBackups without error using callback', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + ]; + client.innerApiCalls.listBackups = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listBackups( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IBackup[] | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('uses async iteration with listBackups with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBackups.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBackupsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.sql.v1.IBackup[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + it('invokes listBackups with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listBackups = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.listBackups(request), expectedError); + const actualRequest = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - 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 listBackupsStream without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + ]; + client.descriptors.page.listBackups.createStream = + stubPageStreamingCall(expectedResponse); + const stream = client.listBackupsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.sql.v1.Backup[] = []; + stream.on('data', (response: protos.google.cloud.sql.v1.Backup) => { + responses.push(response); }); - it('invokes getLocation without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - 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)); + stream.on('end', () => { + resolve(responses); }); - it('invokes getLocation with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - 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)); + stream.on('error', (err: Error) => { + reject(err); }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listBackups, request), + ); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + + it('invokes listBackupsStream with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.descriptors.page.listBackups.createStream = stubPageStreamingCall( + undefined, + expectedError, + ); + const stream = client.listBackupsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.sql.v1.Backup[] = []; + stream.on('data', (response: protos.google.cloud.sql.v1.Backup) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); }); - it('uses async iteration with listLocations with error', async () => { - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + stream.on('error', (err: Error) => { + reject(err); }); + }); + await assert.rejects(promise, expectedError); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listBackups, request), + ); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); }); - describe('Path templates', () => { + it('uses async iteration with listBackups without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1.Backup()), + ]; + client.descriptors.page.listBackups.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.sql.v1.IBackup[] = []; + const iterable = client.listBackupsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listBackups.asyncIterate as SinonStub).getCall( + 0, + ).args[1], + request, + ); + assert( + (client.descriptors.page.listBackups.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); + }); - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + it('uses async iteration with listBackups with error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.descriptors.page.listBackups.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError, + ); + const iterable = client.listBackupsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.sql.v1.IBackup[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listBackups.asyncIterate as SinonStub).getCall( + 0, + ).args[1], + request, + ); + assert( + (client.descriptors.page.listBackups.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + 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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + 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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = new sqlbackupsserviceModule.v1.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_backups_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_backups_service_v1beta4.ts index 7284e1063b10..b2fece3336d8 100644 --- a/packages/google-cloud-sql/test/gapic_sql_backups_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_backups_service_v1beta4.ts @@ -19,1161 +19,1465 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlbackupsserviceModule from '../src'; -import {PassThrough} from 'stream'; +import { PassThrough } from 'stream'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 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]); - } +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(); }); + } + 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({}); + }); } - return sinon.stub().returns(mockStream); + 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); +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('v1beta4.SqlBackupsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); + 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 = sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + 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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - fallback: true, - }); - assert(client); + it('should create a client with no option', () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + fallback: true, }); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupsServiceStub, undefined); - await client.initialize(); - assert(client.sqlBackupsServiceStub); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlBackupsServiceStub, undefined); + await client.initialize(); + assert(client.sqlBackupsServiceStub); + }); - it('has close method for the initialized client', done => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlBackupsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlBackupsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; + }); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlBackupsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the non-initialized client', (done) => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlBackupsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - 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', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + 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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - 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); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + 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('createBackup', () => { - it('invokes createBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.createBackup = stubSimpleCall(expectedResponse); - const [response] = await client.createBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('createBackup', () => { + it('invokes createBackup without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.createBackup = stubSimpleCall(expectedResponse); + const [response] = await client.createBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes createBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.createBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes createBackup without error using callback', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.createBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes createBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes createBackup with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.createBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes createBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.CreateBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.CreateBackupRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBackup(request), expectedError); + it('invokes createBackup with closed client', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.CreateBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.CreateBackupRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.createBackup(request), expectedError); }); + }); - describe('getBackup', () => { - it('invokes getBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Backup() - ); - client.innerApiCalls.getBackup = stubSimpleCall(expectedResponse); - const [response] = await client.getBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('getBackup', () => { + it('invokes getBackup without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Backup(), + ); + client.innerApiCalls.getBackup = stubSimpleCall(expectedResponse); + const [response] = await client.getBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Backup() - ); - client.innerApiCalls.getBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IBackup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes getBackup without error using callback', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Backup(), + ); + client.innerApiCalls.getBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IBackup | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes getBackup with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getBackup = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetBackupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBackup(request), expectedError); + it('invokes getBackup with closed client', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.getBackup(request), expectedError); }); + }); - describe('updateBackup', () => { - it('invokes updateBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.updateBackup = stubSimpleCall(expectedResponse); - const [response] = await client.updateBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('updateBackup', () => { + it('invokes updateBackup without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.updateBackup = stubSimpleCall(expectedResponse); + const [response] = await client.updateBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes updateBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.updateBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes updateBackup without error using callback', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.updateBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes updateBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes updateBackup with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedHeaderRequestParams = `backup.name=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.updateBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes updateBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.UpdateBackupRequest() - ); - request.backup ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.UpdateBackupRequest', ['backup', 'name']); - request.backup.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBackup(request), expectedError); + it('invokes updateBackup with closed client', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.UpdateBackupRequest(), + ); + request.backup ??= {}; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.UpdateBackupRequest', + ['backup', 'name'], + ); + request.backup.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.updateBackup(request), expectedError); }); + }); - describe('deleteBackup', () => { - it('invokes deleteBackup without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.deleteBackup = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('deleteBackup', () => { + it('invokes deleteBackup without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.deleteBackup = stubSimpleCall(expectedResponse); + const [response] = await client.deleteBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes deleteBackup without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.deleteBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes deleteBackup without error using callback', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.deleteBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes deleteBackup with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes deleteBackup with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.deleteBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes deleteBackup with closed client', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DeleteBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.DeleteBackupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBackup(request), expectedError); + it('invokes deleteBackup with closed client', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DeleteBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.DeleteBackupRequest', + ['name'], + ); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.deleteBackup(request), expectedError); }); + }); - describe('listBackups', () => { - it('invokes listBackups without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - ]; - client.innerApiCalls.listBackups = stubSimpleCall(expectedResponse); - const [response] = await client.listBackups(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('listBackups', () => { + it('invokes listBackups without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + ]; + client.innerApiCalls.listBackups = stubSimpleCall(expectedResponse); + const [response] = await client.listBackups(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listBackups without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - ]; - client.innerApiCalls.listBackups = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBackups( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IBackup[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes listBackups without error using callback', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + ]; + client.innerApiCalls.listBackups = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listBackups( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IBackup[] | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listBackups with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBackups = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBackups(request), expectedError); - const actualRequest = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBackups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes listBackups with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listBackups = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.listBackups(request), expectedError); + const actualRequest = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listBackups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listBackupsStream without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - ]; - client.descriptors.page.listBackups.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBackupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.sql.v1beta4.Backup[] = []; - stream.on('data', (response: protos.google.cloud.sql.v1beta4.Backup) => { - 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.listBackups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBackups, request)); - assert( - (client.descriptors.page.listBackups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + it('invokes listBackupsStream without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + ]; + client.descriptors.page.listBackups.createStream = + stubPageStreamingCall(expectedResponse); + const stream = client.listBackupsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.sql.v1beta4.Backup[] = []; + stream.on( + 'data', + (response: protos.google.cloud.sql.v1beta4.Backup) => { + 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.listBackups.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listBackups, request), + ); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); + }); - it('invokes listBackupsStream with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBackups.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBackupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.sql.v1beta4.Backup[] = []; - stream.on('data', (response: protos.google.cloud.sql.v1beta4.Backup) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBackups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBackups, request)); - assert( - (client.descriptors.page.listBackups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + it('invokes listBackupsStream with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.descriptors.page.listBackups.createStream = stubPageStreamingCall( + undefined, + expectedError, + ); + const stream = client.listBackupsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.sql.v1beta4.Backup[] = []; + stream.on( + 'data', + (response: protos.google.cloud.sql.v1beta4.Backup) => { + responses.push(response); + }, + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); }); + }); + await assert.rejects(promise, expectedError); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listBackups, request), + ); + assert( + (client.descriptors.page.listBackups.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); + }); - it('uses async iteration with listBackups without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), - ]; - client.descriptors.page.listBackups.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.sql.v1beta4.IBackup[] = []; - const iterable = client.listBackupsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + it('uses async iteration with listBackups without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + generateSampleMessage(new protos.google.cloud.sql.v1beta4.Backup()), + ]; + client.descriptors.page.listBackups.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.sql.v1beta4.IBackup[] = []; + const iterable = client.listBackupsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listBackups.asyncIterate as SinonStub).getCall( + 0, + ).args[1], + request, + ); + assert( + (client.descriptors.page.listBackups.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); + }); - it('uses async iteration with listBackups with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ListBackupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.ListBackupsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBackups.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBackupsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.sql.v1beta4.IBackup[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBackups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + it('uses async iteration with listBackups with error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ListBackupsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.ListBackupsRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.descriptors.page.listBackups.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError, + ); + const iterable = client.listBackupsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.sql.v1beta4.IBackup[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listBackups.asyncIterate as SinonStub).getCall( + 0, + ).args[1], + request, + ); + assert( + (client.descriptors.page.listBackups.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers[ + 'x-goog-request-params' + ].includes(expectedHeaderRequestParams), + ); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - 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)); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('invokes getLocation without error using callback', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - 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)); + 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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('invokes getLocation with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - 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)); + 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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('uses async iteration with listLocations with error', async () => { - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); }); + }); - describe('Path templates', () => { + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = + new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqlbackupsserviceModule.v1beta4.SqlBackupsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_connect_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_connect_service_v1.ts index 6871c0b454df..b60949338fd6 100644 --- a/packages/google-cloud-sql/test/gapic_sql_connect_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_connect_service_v1.ts @@ -19,663 +19,823 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlconnectserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlConnectServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient(); + 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 = sqlconnectserviceModule.v1.SqlConnectServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlconnectserviceModule.v1.SqlConnectServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.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 = + sqlconnectserviceModule.v1.SqlConnectServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlconnectserviceModule.v1.SqlConnectServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlconnectserviceModule.v1.SqlConnectServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlconnectserviceModule.v1.SqlConnectServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlconnectserviceModule.v1.SqlConnectServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + 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 sqlconnectserviceModule.v1.SqlConnectServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('has port', () => { - const port = sqlconnectserviceModule.v1.SqlConnectServiceClient.port; - assert(port); - assert(typeof port === 'number'); + 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 sqlconnectserviceModule.v1.SqlConnectServiceClient( + { universeDomain: 'configured.example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('should create a client with no option', () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient(); - assert(client); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - fallback: true, - }); - assert(client); - }); + it('has port', () => { + const port = sqlconnectserviceModule.v1.SqlConnectServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlConnectServiceStub, undefined); - await client.initialize(); - assert(client.sqlConnectServiceStub); - }); + it('should create a client with no option', () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient(); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlConnectServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlConnectServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlConnectServiceStub, undefined); + await client.initialize(); + assert(client.sqlConnectServiceStub); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - 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 close method for the initialized client', (done) => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlConnectServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - 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); + it('has close method for the non-initialized client', (done) => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlConnectServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); }); - describe('getConnectSettings', () => { - it('invokes getConnectSettings without error', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.ConnectSettings() - ); - client.innerApiCalls.getConnectSettings = stubSimpleCall(expectedResponse); - const [response] = await client.getConnectSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + 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('invokes getConnectSettings without error using callback', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.ConnectSettings() - ); - client.innerApiCalls.getConnectSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getConnectSettings( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IConnectSettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + 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('getConnectSettings', () => { + it('invokes getConnectSettings without error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.ConnectSettings(), + ); + client.innerApiCalls.getConnectSettings = + stubSimpleCall(expectedResponse); + const [response] = await client.getConnectSettings(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getConnectSettings with error', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getConnectSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getConnectSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getConnectSettings without error using callback', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.ConnectSettings(), + ); + client.innerApiCalls.getConnectSettings = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getConnectSettings( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IConnectSettings | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getConnectSettings with closed client', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getConnectSettings(request), expectedError); - }); + it('invokes getConnectSettings with error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getConnectSettings = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.getConnectSettings(request), expectedError); + const actualRequest = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('generateEphemeralCert', () => { - it('invokes generateEphemeralCert without error', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.GenerateEphemeralCertResponse() - ); - client.innerApiCalls.generateEphemeralCert = stubSimpleCall(expectedResponse); - const [response] = await client.generateEphemeralCert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getConnectSettings with closed client', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.getConnectSettings(request), expectedError); + }); + }); + + describe('generateEphemeralCert', () => { + it('invokes generateEphemeralCert without error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.GenerateEphemeralCertResponse(), + ); + client.innerApiCalls.generateEphemeralCert = + stubSimpleCall(expectedResponse); + const [response] = await client.generateEphemeralCert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes generateEphemeralCert without error using callback', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.GenerateEphemeralCertResponse() - ); - client.innerApiCalls.generateEphemeralCert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.generateEphemeralCert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes generateEphemeralCert without error using callback', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.GenerateEphemeralCertResponse(), + ); + client.innerApiCalls.generateEphemeralCert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.generateEphemeralCert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IGenerateEphemeralCertResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes generateEphemeralCert with error', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.generateEphemeralCert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.generateEphemeralCert(request), expectedError); - const actualRequest = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes generateEphemeralCert with error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.generateEphemeralCert = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.generateEphemeralCert(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes generateEphemeralCert with closed client', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.generateEphemeralCert(request), expectedError); - }); + it('invokes generateEphemeralCert with closed client', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.generateEphemeralCert(request), + expectedError, + ); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - 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 sqlconnectserviceModule.v1.SqlConnectServiceClient({ - 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 sqlconnectserviceModule.v1.SqlConnectServiceClient({ - 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)); - }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.locationsClient.getLocation as SinonStub).getCall(0)); }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes getLocation with error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlconnectserviceModule.v1.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_connect_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_connect_service_v1beta4.ts index cf1df12ba74f..7a26e7c169f0 100644 --- a/packages/google-cloud-sql/test/gapic_sql_connect_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_connect_service_v1beta4.ts @@ -19,663 +19,849 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlconnectserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlConnectServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); + 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 = sqlconnectserviceModule.v1beta4.SqlConnectServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlconnectserviceModule.v1beta4.SqlConnectServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlconnectserviceModule.v1beta4.SqlConnectServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlconnectserviceModule.v1beta4.SqlConnectServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - 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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqlconnectserviceModule.v1beta4.SqlConnectServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqlconnectserviceModule.v1beta4.SqlConnectServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlConnectServiceStub, undefined); - await client.initialize(); - assert(client.sqlConnectServiceStub); + it('should create a client with gRPC fallback', () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlConnectServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlConnectServiceStub, undefined); + await client.initialize(); + assert(client.sqlConnectServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlConnectServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - 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()); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlConnectServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - 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); + it('has close method for the non-initialized client', (done) => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlConnectServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); }); - describe('getConnectSettings', () => { - it('invokes getConnectSettings without error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ConnectSettings() - ); - client.innerApiCalls.getConnectSettings = stubSimpleCall(expectedResponse); - const [response] = await client.getConnectSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + 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('invokes getConnectSettings without error using callback', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.ConnectSettings() - ); - client.innerApiCalls.getConnectSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getConnectSettings( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IConnectSettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + 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('getConnectSettings', () => { + it('invokes getConnectSettings without error', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ConnectSettings(), + ); + client.innerApiCalls.getConnectSettings = + stubSimpleCall(expectedResponse); + const [response] = await client.getConnectSettings(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getConnectSettings with error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getConnectSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getConnectSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getConnectSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes getConnectSettings without error using callback', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.ConnectSettings(), + ); + client.innerApiCalls.getConnectSettings = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getConnectSettings( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IConnectSettings | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getConnectSettings with closed client', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GetConnectSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getConnectSettings(request), expectedError); + it('invokes getConnectSettings with error', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getConnectSettings = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.getConnectSettings(request), expectedError); + const actualRequest = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getConnectSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('generateEphemeralCert', () => { - it('invokes generateEphemeralCert without error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertResponse() - ); - client.innerApiCalls.generateEphemeralCert = stubSimpleCall(expectedResponse); - const [response] = await client.generateEphemeralCert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes getConnectSettings with closed client', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GetConnectSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GetConnectSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.getConnectSettings(request), expectedError); + }); + }); + + describe('generateEphemeralCert', () => { + it('invokes generateEphemeralCert without error', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertResponse(), + ); + client.innerApiCalls.generateEphemeralCert = + stubSimpleCall(expectedResponse); + const [response] = await client.generateEphemeralCert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes generateEphemeralCert without error using callback', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertResponse() - ); - client.innerApiCalls.generateEphemeralCert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.generateEphemeralCert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes generateEphemeralCert without error using callback', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertResponse(), + ); + client.innerApiCalls.generateEphemeralCert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.generateEphemeralCert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IGenerateEphemeralCertResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes generateEphemeralCert with error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.generateEphemeralCert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.generateEphemeralCert(request), expectedError); - const actualRequest = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.generateEphemeralCert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes generateEphemeralCert with error', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.generateEphemeralCert = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.generateEphemeralCert(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.generateEphemeralCert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes generateEphemeralCert with closed client', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.generateEphemeralCert(request), expectedError); + it('invokes generateEphemeralCert with closed client', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.GenerateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.generateEphemeralCert(request), + expectedError, + ); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - 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)); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('invokes getLocation without error using callback', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - 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)); + 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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('invokes getLocation with error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - 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)); + 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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('uses async iteration with listLocations with error', async () => { - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlconnectserviceModule.v1beta4.SqlConnectServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_databases_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_databases_service_v1.ts index cca0b07a3c6e..15097fddb205 100644 --- a/packages/google-cloud-sql/test/gapic_sql_databases_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_databases_service_v1.ts @@ -19,1191 +19,1549 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqldatabasesserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlDatabasesServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = + new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); + 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 = sqldatabasesserviceModule.v1.SqlDatabasesServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqldatabasesserviceModule.v1.SqlDatabasesServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqldatabasesserviceModule.v1.SqlDatabasesServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqldatabasesserviceModule.v1.SqlDatabasesServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { universeDomain: 'example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { universe_domain: 'example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + 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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqldatabasesserviceModule.v1.SqlDatabasesServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqldatabasesserviceModule.v1.SqlDatabasesServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlDatabasesServiceStub, undefined); - await client.initialize(); - assert(client.sqlDatabasesServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + fallback: true, + }, + ); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlDatabasesServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + assert.strictEqual(client.sqlDatabasesServiceStub, undefined); + await client.initialize(); + assert(client.sqlDatabasesServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlDatabasesServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlDatabasesServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + assert.strictEqual(client.sqlDatabasesServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + 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()); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + 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); + }); + }); - it('invokes delete without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('delete', () => { + it('invokes delete without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete without error using callback', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with closed client', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); + it('invokes delete with error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Database() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with closed client', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); - it('invokes get without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Database() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IDatabase|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('get', () => { + it('invokes get without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Database(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get without error using callback', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Database(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IDatabase | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with closed client', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); + it('invokes get with error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get with closed client', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); - it('invokes insert without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('insert', () => { + it('invokes insert without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert without error using callback', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with closed client', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); + it('invokes insert with error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.DatabasesListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with closed client', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); - it('invokes list without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.DatabasesListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IDatabasesListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('list', () => { + it('invokes list without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.DatabasesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list without error using callback', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.DatabasesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IDatabasesListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('patch', () => { - it('invokes patch without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.patch = stubSimpleCall(expectedResponse); - const [response] = await client.patch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with closed client', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); - it('invokes patch without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patch( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('patch', () => { + it('invokes patch without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCall(expectedResponse); + const [response] = await client.patch(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes patch with error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patch(request), expectedError); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes patch without error using callback', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.patch( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes patch with closed client', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patch(request), expectedError); - }); + it('invokes patch with error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.patch(request), expectedError); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('update', () => { - it('invokes update without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.update = stubSimpleCall(expectedResponse); - const [response] = await client.update(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes patch with closed client', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.patch(request), expectedError); + }); + }); - it('invokes update without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.update = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.update( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('update', () => { + it('invokes update without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.update = stubSimpleCall(expectedResponse); + const [response] = await client.update(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.update(request), expectedError); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes update without error using callback', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.update = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.update( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with closed client', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.update(request), expectedError); - }); + it('invokes update with error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.update(request), expectedError); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - 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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - 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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - 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)); - }); + + it('invokes update with closed client', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.update(request), expectedError); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + 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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqldatabasesserviceModule.v1.SqlDatabasesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_databases_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_databases_service_v1beta4.ts index 888634ab0244..3f9edfa33005 100644 --- a/packages/google-cloud-sql/test/gapic_sql_databases_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_databases_service_v1beta4.ts @@ -19,1221 +19,1557 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqldatabasesserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlDatabasesServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); + 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 = sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient + .servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + 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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); - assert(client); - }); + it('has port', () => { + const port = + sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - fallback: true, - }); - assert(client); + it('should create a client with no option', () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + fallback: true, }); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlDatabasesServiceStub, undefined); - await client.initialize(); - assert(client.sqlDatabasesServiceStub); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlDatabasesServiceStub, undefined); + await client.initialize(); + assert(client.sqlDatabasesServiceStub); + }); - it('has close method for the initialized client', done => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlDatabasesServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlDatabasesServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; + }); + }); - it('has close method for the non-initialized client', done => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlDatabasesServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the non-initialized client', (done) => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlDatabasesServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; + }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - 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', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + 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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - 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); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + 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('delete', () => { - it('invokes delete without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('delete', () => { + it('invokes delete without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes delete without error using callback', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes delete with error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with closed client', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); + it('invokes delete with closed client', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesDeleteRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); }); + }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Database() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('get', () => { + it('invokes get without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Database(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Database() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IDatabase|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes get without error using callback', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Database(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IDatabase | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes get with error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with closed client', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); + it('invokes get with closed client', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesGetRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); }); + }); - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('insert', () => { + it('invokes insert without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes insert without error using callback', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes insert with error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with closed client', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); + it('invokes insert with closed client', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); }); + }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DatabasesListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DatabasesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DatabasesListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IDatabasesListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes list without error using callback', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DatabasesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IDatabasesListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes list with error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); + it('invokes list with closed client', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); }); + }); - describe('patch', () => { - it('invokes patch without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.patch = stubSimpleCall(expectedResponse); - const [response] = await client.patch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('patch', () => { + it('invokes patch without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCall(expectedResponse); + const [response] = await client.patch(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes patch without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patch( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes patch without error using callback', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.patch( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes patch with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patch(request), expectedError); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes patch with error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.patch(request), expectedError); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes patch with closed client', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patch(request), expectedError); + it('invokes patch with closed client', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.patch(request), expectedError); }); + }); - describe('update', () => { - it('invokes update without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.update = stubSimpleCall(expectedResponse); - const [response] = await client.update(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + describe('update', () => { + it('invokes update without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.update = stubSimpleCall(expectedResponse); + const [response] = await client.update(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.update = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.update( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes update without error using callback', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.update = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.update( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&database=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.update(request), expectedError); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('invokes update with error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&database=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.update(request), expectedError); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with closed client', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', ['database']); - request.database = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.update(request), expectedError); + it('invokes update with closed client', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlDatabasesUpdateRequest', + ['database'], + ); + request.database = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.update(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - 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)); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('invokes getLocation without error using callback', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - 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)); + 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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('invokes getLocation with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - 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)); + 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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); - it('uses async iteration with listLocations with error', async () => { - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); }); + }); - describe('Path templates', () => { + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = + new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqldatabasesserviceModule.v1beta4.SqlDatabasesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_feature_eligibility_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_feature_eligibility_service_v1.ts index 1b943f35d8e6..b8f469f7bc39 100644 --- a/packages/google-cloud-sql/test/gapic_sql_feature_eligibility_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_feature_eligibility_service_v1.ts @@ -19,419 +19,547 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlfeatureeligibilityserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); } -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); +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.SqlFeatureEligibilityServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); + 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 = sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlfeatureeligibilityserviceModule.v1 + .SqlFeatureEligibilityServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlfeatureeligibilityserviceModule.v1 + .SqlFeatureEligibilityServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { universeDomain: 'example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { universe_domain: 'example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('has port', () => { - const port = sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient.port; - assert(port); - assert(typeof port === 'number'); + 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { universeDomain: 'configured.example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { universe_domain: 'example.com', universeDomain: 'example.net' }, + ); + }); + }); - it('should create a client with no option', () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); - assert(client); - }); + it('has port', () => { + const port = + sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient + .port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlFeatureEligibilityServiceStub, undefined); - await client.initialize(); - assert(client.sqlFeatureEligibilityServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + fallback: true, + }, + ); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlFeatureEligibilityServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + assert.strictEqual(client.sqlFeatureEligibilityServiceStub, undefined); + await client.initialize(); + assert(client.sqlFeatureEligibilityServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlFeatureEligibilityServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlFeatureEligibilityServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + assert.strictEqual(client.sqlFeatureEligibilityServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + 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()); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - 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)); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + 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('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlfeatureeligibilityserviceModule.v1.SqlFeatureEligibilityServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_flags_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_flags_service_v1.ts index be1385ccd329..09b5fbd0667f 100644 --- a/packages/google-cloud-sql/test/gapic_sql_flags_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_flags_service_v1.ts @@ -19,498 +19,591 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlflagsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlFlagsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient(); + 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 = sqlflagsserviceModule.v1.SqlFlagsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlflagsserviceModule.v1.SqlFlagsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlflagsserviceModule.v1.SqlFlagsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlflagsserviceModule.v1.SqlFlagsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlflagsserviceModule.v1.SqlFlagsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - 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 sqlflagsserviceModule.v1.SqlFlagsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + 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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqlflagsserviceModule.v1.SqlFlagsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqlflagsserviceModule.v1.SqlFlagsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlFlagsServiceStub, undefined); - await client.initialize(); - assert(client.sqlFlagsServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlFlagsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlFlagsServiceStub, undefined); + await client.initialize(); + assert(client.sqlFlagsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlFlagsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlFlagsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlFlagsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + 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()); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlFlagsListRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.FlagsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + 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('list', () => { + it('invokes list without error', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlFlagsListRequest(), + ); + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.FlagsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + }); - it('invokes list without error using callback', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlFlagsListRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.FlagsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IFlagsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); + it('invokes list without error using callback', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlFlagsListRequest(), + ); + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.FlagsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IFlagsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); - it('invokes list with error', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlFlagsListRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with error', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlFlagsListRequest(), + ); + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + }); - it('invokes list with closed client', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlFlagsListRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with closed client', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlFlagsListRequest(), + ); + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - 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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - 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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - 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)); - }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.locationsClient.getLocation as SinonStub).getCall(0)); }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes getLocation with error', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlflagsserviceModule.v1.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_flags_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_flags_service_v1beta4.ts index 0d1278673ccd..4e37b9e1b3e7 100644 --- a/packages/google-cloud-sql/test/gapic_sql_flags_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_flags_service_v1beta4.ts @@ -19,528 +19,631 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlflagsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlFlagsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); + 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 = sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - 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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlFlagsServiceStub, undefined); - await client.initialize(); - assert(client.sqlFlagsServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlFlagsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlFlagsServiceStub, undefined); + await client.initialize(); + assert(client.sqlFlagsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlFlagsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlFlagsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlFlagsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + 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()); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.FlagsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + 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('list', () => { + it('invokes list without error', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest(), + ); + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.FlagsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + }); - it('invokes list without error using callback', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.FlagsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IFlagsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); + it('invokes list without error using callback', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest(), + ); + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.FlagsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IFlagsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); - it('invokes list with error', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with error', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest(), + ); + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + }); - it('invokes list with closed client', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with closed client', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlFlagsListRequest(), + ); + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - 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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - 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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - 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)); - }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = new sqlflagsserviceModule.v1beta4.SqlFlagsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_instances_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_instances_service_v1.ts index 3e9991b4257f..03dbe2acbf28 100644 --- a/packages/google-cloud-sql/test/gapic_sql_instances_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_instances_service_v1.ts @@ -19,5609 +19,7460 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlinstancesserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlInstancesServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = + new sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); + 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 = sqlinstancesserviceModule.v1.SqlInstancesServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlinstancesserviceModule.v1.SqlInstancesServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlinstancesserviceModule.v1.SqlInstancesServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { universeDomain: 'example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlinstancesserviceModule.v1.SqlInstancesServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { universe_domain: 'example.com' }, + ); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - 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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); + it('has port', () => { + const port = sqlinstancesserviceModule.v1.SqlInstancesServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('has port', () => { - const port = sqlinstancesserviceModule.v1.SqlInstancesServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); + it('should create a client with no option', () => { + const client = + new sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); + assert(client); + }); - it('should create a client with no option', () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient(); - assert(client); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + fallback: true, + }, + ); + assert(client); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - fallback: true, - }); - assert(client); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + assert.strictEqual(client.sqlInstancesServiceStub, undefined); + await client.initialize(); + assert(client.sqlInstancesServiceStub); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlInstancesServiceStub, undefined); - await client.initialize(); - assert(client.sqlInstancesServiceStub); + it('has close method for the initialized client', (done) => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlInstancesServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has close method for the initialized client', done => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlInstancesServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the non-initialized client', (done) => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + assert.strictEqual(client.sqlInstancesServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlInstancesServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + 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', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - 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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + 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('addServerCa', () => { + it('invokes addServerCa without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.addServerCa = stubSimpleCall(expectedResponse); + const [response] = await client.addServerCa(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - 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); - }); + it('invokes addServerCa without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.addServerCa = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.addServerCa( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('addServerCa', () => { - it('invokes addServerCa without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.addServerCa = stubSimpleCall(expectedResponse); - const [response] = await client.addServerCa(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes addServerCa with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.addServerCa = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.addServerCa(request), expectedError); + const actualRequest = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addServerCa without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.addServerCa = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addServerCa( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes addServerCa with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.addServerCa(request), expectedError); + }); + }); + + describe('addServerCertificate', () => { + it('invokes addServerCertificate without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.addServerCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.addServerCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addServerCa with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addServerCa = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addServerCa(request), expectedError); - const actualRequest = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes addServerCertificate without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.addServerCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.addServerCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addServerCa with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addServerCa(request), expectedError); - }); + it('invokes addServerCertificate with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.addServerCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.addServerCertificate(request), expectedError); + const actualRequest = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('addServerCertificate', () => { - it('invokes addServerCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.addServerCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.addServerCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes addServerCertificate with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.addServerCertificate(request), expectedError); + }); + }); + + describe('addEntraIdCertificate', () => { + it('invokes addEntraIdCertificate without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.addEntraIdCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.addEntraIdCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addServerCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.addServerCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addServerCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes addEntraIdCertificate without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.addEntraIdCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.addEntraIdCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addServerCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addServerCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addServerCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes addEntraIdCertificate with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.addEntraIdCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.addEntraIdCertificate(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addServerCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addServerCertificate(request), expectedError); - }); + it('invokes addEntraIdCertificate with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.addEntraIdCertificate(request), + expectedError, + ); + }); + }); + + describe('clone', () => { + it('invokes clone without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.clone = stubSimpleCall(expectedResponse); + const [response] = await client.clone(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.clone as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.clone as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('addEntraIdCertificate', () => { - it('invokes addEntraIdCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.addEntraIdCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.addEntraIdCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes clone without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.clone = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.clone( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.clone as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.clone as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addEntraIdCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.addEntraIdCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addEntraIdCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes clone with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.clone = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.clone(request), expectedError); + const actualRequest = (client.innerApiCalls.clone as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.clone as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addEntraIdCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addEntraIdCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addEntraIdCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes clone with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.clone(request), expectedError); + }); + }); + + describe('delete', () => { + it('invokes delete without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes addEntraIdCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addEntraIdCertificate(request), expectedError); - }); + it('invokes delete without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('clone', () => { - it('invokes clone without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.clone = stubSimpleCall(expectedResponse); - const [response] = await client.clone(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes clone without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.clone = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.clone( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); + + describe('demoteMaster', () => { + it('invokes demoteMaster without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.demoteMaster = stubSimpleCall(expectedResponse); + const [response] = await client.demoteMaster(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes clone with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.clone = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.clone(request), expectedError); - const actualRequest = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes demoteMaster without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.demoteMaster = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.demoteMaster( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes clone with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.clone(request), expectedError); - }); + it('invokes demoteMaster with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.demoteMaster = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.demoteMaster(request), expectedError); + const actualRequest = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes demoteMaster with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.demoteMaster(request), expectedError); + }); + }); + + describe('demote', () => { + it('invokes demote without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.demote = stubSimpleCall(expectedResponse); + const [response] = await client.demote(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.demote as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes demote without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.demote = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.demote( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.demote as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes demote with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.demote = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.demote(request), expectedError); + const actualRequest = (client.innerApiCalls.demote as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); + it('invokes demote with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.demote(request), expectedError); + }); + }); + + describe('export', () => { + it('invokes export without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.export = stubSimpleCall(expectedResponse); + const [response] = await client.export(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.export as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.export as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('demoteMaster', () => { - it('invokes demoteMaster without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.demoteMaster = stubSimpleCall(expectedResponse); - const [response] = await client.demoteMaster(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes export without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.export = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.export( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.export as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.export as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes demoteMaster without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.demoteMaster = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.demoteMaster( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes export with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.export = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.export(request), expectedError); + const actualRequest = (client.innerApiCalls.export as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.export as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes demoteMaster with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.demoteMaster = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.demoteMaster(request), expectedError); - const actualRequest = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes export with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.export(request), expectedError); + }); + }); + + describe('failover', () => { + it('invokes failover without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.failover = stubSimpleCall(expectedResponse); + const [response] = await client.failover(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes demoteMaster with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.demoteMaster(request), expectedError); - }); + it('invokes failover without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.failover = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.failover( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('demote', () => { - it('invokes demote without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.demote = stubSimpleCall(expectedResponse); - const [response] = await client.demote(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes failover with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.failover = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.failover(request), expectedError); + const actualRequest = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes demote without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.demote = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.demote( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes failover with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.failover(request), expectedError); + }); + }); + + describe('reencrypt', () => { + it('invokes reencrypt without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.reencrypt = stubSimpleCall(expectedResponse); + const [response] = await client.reencrypt(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes demote with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.demote = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.demote(request), expectedError); - const actualRequest = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes reencrypt without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.reencrypt = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.reencrypt( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes demote with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.demote(request), expectedError); - }); + it('invokes reencrypt with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.reencrypt = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.reencrypt(request), expectedError); + const actualRequest = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('export', () => { - it('invokes export without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.export = stubSimpleCall(expectedResponse); - const [response] = await client.export(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes reencrypt with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.reencrypt(request), expectedError); + }); + }); + + describe('get', () => { + it('invokes get without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.DatabaseInstance(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes export without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.export = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.export( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.DatabaseInstance(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IDatabaseInstance | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes export with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.export = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.export(request), expectedError); - const actualRequest = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes export with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.export(request), expectedError); - }); + it('invokes get with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); + + describe('import', () => { + it('invokes import without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.import = stubSimpleCall(expectedResponse); + const [response] = await client.import(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.import as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.import as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('failover', () => { - it('invokes failover without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.failover = stubSimpleCall(expectedResponse); - const [response] = await client.failover(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes import without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.import = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.import( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.import as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.import as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes failover without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.failover = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.failover( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes import with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.import = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.import(request), expectedError); + const actualRequest = (client.innerApiCalls.import as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.import as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes failover with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.failover = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.failover(request), expectedError); - const actualRequest = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes import with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.import(request), expectedError); + }); + }); + + describe('insert', () => { + it('invokes insert without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes failover with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.failover(request), expectedError); - }); + it('invokes insert without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('reencrypt', () => { - it('invokes reencrypt without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.reencrypt = stubSimpleCall(expectedResponse); - const [response] = await client.reencrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes reencrypt without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.reencrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reencrypt( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes reencrypt with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reencrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reencrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IInstancesListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes reencrypt with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reencrypt(request), expectedError); - }); + it('invokes list with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.DatabaseInstance() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + + describe('listServerCas', () => { + it('invokes listServerCas without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListServerCasResponse(), + ); + client.innerApiCalls.listServerCas = stubSimpleCall(expectedResponse); + const [response] = await client.listServerCas(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.DatabaseInstance() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IDatabaseInstance|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listServerCas without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListServerCasResponse(), + ); + client.innerApiCalls.listServerCas = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listServerCas( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IInstancesListServerCasResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listServerCas with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listServerCas = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.listServerCas(request), expectedError); + const actualRequest = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); + it('invokes listServerCas with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.listServerCas(request), expectedError); + }); + }); + + describe('listServerCertificates', () => { + it('invokes listServerCertificates without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListServerCertificatesResponse(), + ); + client.innerApiCalls.listServerCertificates = + stubSimpleCall(expectedResponse); + const [response] = await client.listServerCertificates(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('import', () => { - it('invokes import without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.import = stubSimpleCall(expectedResponse); - const [response] = await client.import(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listServerCertificates without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListServerCertificatesResponse(), + ); + client.innerApiCalls.listServerCertificates = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listServerCertificates( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes import without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.import = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.import( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listServerCertificates with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listServerCertificates = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.listServerCertificates(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes import with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.import = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.import(request), expectedError); - const actualRequest = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listServerCertificates with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.listServerCertificates(request), + expectedError, + ); + }); + }); + + describe('listEntraIdCertificates', () => { + it('invokes listEntraIdCertificates without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListEntraIdCertificatesResponse(), + ); + client.innerApiCalls.listEntraIdCertificates = + stubSimpleCall(expectedResponse); + const [response] = await client.listEntraIdCertificates(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes import with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.import(request), expectedError); - }); + it('invokes listEntraIdCertificates without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.InstancesListEntraIdCertificatesResponse(), + ); + client.innerApiCalls.listEntraIdCertificates = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listEntraIdCertificates( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listEntraIdCertificates with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listEntraIdCertificates = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.listEntraIdCertificates(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes listEntraIdCertificates with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.listEntraIdCertificates(request), + expectedError, + ); + }); + }); + + describe('patch', () => { + it('invokes patch without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCall(expectedResponse); + const [response] = await client.patch(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes patch without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.patch( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); + it('invokes patch with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.patch(request), expectedError); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes patch with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.patch(request), expectedError); + }); + }); + + describe('promoteReplica', () => { + it('invokes promoteReplica without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.promoteReplica = stubSimpleCall(expectedResponse); + const [response] = await client.promoteReplica(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IInstancesListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes promoteReplica without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.promoteReplica = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.promoteReplica( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes promoteReplica with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.promoteReplica = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.promoteReplica(request), expectedError); + const actualRequest = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes promoteReplica with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.promoteReplica(request), expectedError); + }); + }); + + describe('switchover', () => { + it('invokes switchover without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.switchover = stubSimpleCall(expectedResponse); + const [response] = await client.switchover(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('listServerCas', () => { - it('invokes listServerCas without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListServerCasResponse() - ); - client.innerApiCalls.listServerCas = stubSimpleCall(expectedResponse); - const [response] = await client.listServerCas(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes switchover without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.switchover = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.switchover( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listServerCas without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListServerCasResponse() - ); - client.innerApiCalls.listServerCas = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServerCas( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IInstancesListServerCasResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes switchover with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.switchover = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.switchover(request), expectedError); + const actualRequest = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes listServerCas with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServerCas = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServerCas(request), expectedError); - const actualRequest = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCas with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listServerCas(request), expectedError); - }); + it('invokes switchover with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.switchover(request), expectedError); }); - - describe('listServerCertificates', () => { - it('invokes listServerCertificates without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListServerCertificatesResponse() - ); - client.innerApiCalls.listServerCertificates = stubSimpleCall(expectedResponse); - const [response] = await client.listServerCertificates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCertificates without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListServerCertificatesResponse() - ); - client.innerApiCalls.listServerCertificates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServerCertificates( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IInstancesListServerCertificatesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCertificates with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServerCertificates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServerCertificates(request), expectedError); - const actualRequest = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCertificates with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listServerCertificates(request), expectedError); - }); + }); + + describe('resetSslConfig', () => { + it('invokes resetSslConfig without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.resetSslConfig = stubSimpleCall(expectedResponse); + const [response] = await client.resetSslConfig(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('listEntraIdCertificates', () => { - it('invokes listEntraIdCertificates without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListEntraIdCertificatesResponse() - ); - client.innerApiCalls.listEntraIdCertificates = stubSimpleCall(expectedResponse); - const [response] = await client.listEntraIdCertificates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEntraIdCertificates without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.InstancesListEntraIdCertificatesResponse() - ); - client.innerApiCalls.listEntraIdCertificates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listEntraIdCertificates( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IInstancesListEntraIdCertificatesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEntraIdCertificates with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listEntraIdCertificates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listEntraIdCertificates(request), expectedError); - const actualRequest = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEntraIdCertificates with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listEntraIdCertificates(request), expectedError); - }); + it('invokes resetSslConfig without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.resetSslConfig = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.resetSslConfig( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('patch', () => { - it('invokes patch without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.patch = stubSimpleCall(expectedResponse); - const [response] = await client.patch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patch without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patch( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patch with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patch(request), expectedError); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patch with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patch(request), expectedError); - }); + it('invokes resetSslConfig with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.resetSslConfig = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.resetSslConfig(request), expectedError); + const actualRequest = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('promoteReplica', () => { - it('invokes promoteReplica without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.promoteReplica = stubSimpleCall(expectedResponse); - const [response] = await client.promoteReplica(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes promoteReplica without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.promoteReplica = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.promoteReplica( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes promoteReplica with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.promoteReplica = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.promoteReplica(request), expectedError); - const actualRequest = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes promoteReplica with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.promoteReplica(request), expectedError); - }); + it('invokes resetSslConfig with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.resetSslConfig(request), expectedError); }); - - describe('switchover', () => { - it('invokes switchover without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.switchover = stubSimpleCall(expectedResponse); - const [response] = await client.switchover(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes switchover without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.switchover = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.switchover( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes switchover with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.switchover = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.switchover(request), expectedError); - const actualRequest = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes switchover with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.switchover(request), expectedError); - }); + }); + + describe('restart', () => { + it('invokes restart without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.restart = stubSimpleCall(expectedResponse); + const [response] = await client.restart(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.restart as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restart as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('resetSslConfig', () => { - it('invokes resetSslConfig without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.resetSslConfig = stubSimpleCall(expectedResponse); - const [response] = await client.resetSslConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetSslConfig without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.resetSslConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resetSslConfig( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetSslConfig with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resetSslConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resetSslConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetSslConfig with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resetSslConfig(request), expectedError); - }); + it('invokes restart without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.restart = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.restart( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.restart as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restart as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('restart', () => { - it('invokes restart without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.restart = stubSimpleCall(expectedResponse); - const [response] = await client.restart(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restart without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.restart = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restart( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restart with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.restart = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.restart(request), expectedError); - const actualRequest = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restart with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.restart(request), expectedError); - }); + it('invokes restart with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.restart = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.restart(request), expectedError); + const actualRequest = (client.innerApiCalls.restart as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restart as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('restoreBackup', () => { - it('invokes restoreBackup without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.restoreBackup = stubSimpleCall(expectedResponse); - const [response] = await client.restoreBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreBackup without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.restoreBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restoreBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreBackup with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.restoreBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.restoreBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreBackup with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.restoreBackup(request), expectedError); - }); + it('invokes restart with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.restart(request), expectedError); }); - - describe('rotateServerCa', () => { - it('invokes rotateServerCa without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rotateServerCa = stubSimpleCall(expectedResponse); - const [response] = await client.rotateServerCa(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCa without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rotateServerCa = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rotateServerCa( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCa with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rotateServerCa = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rotateServerCa(request), expectedError); - const actualRequest = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCa with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rotateServerCa(request), expectedError); - }); + }); + + describe('restoreBackup', () => { + it('invokes restoreBackup without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.restoreBackup = stubSimpleCall(expectedResponse); + const [response] = await client.restoreBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('rotateServerCertificate', () => { - it('invokes rotateServerCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rotateServerCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.rotateServerCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rotateServerCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rotateServerCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rotateServerCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rotateServerCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rotateServerCertificate(request), expectedError); - }); + it('invokes restoreBackup without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.restoreBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.restoreBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('rotateEntraIdCertificate', () => { - it('invokes rotateEntraIdCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.rotateEntraIdCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateEntraIdCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rotateEntraIdCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateEntraIdCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rotateEntraIdCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateEntraIdCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rotateEntraIdCertificate(request), expectedError); - }); + it('invokes restoreBackup with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.restoreBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.restoreBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('startReplica', () => { - it('invokes startReplica without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.startReplica = stubSimpleCall(expectedResponse); - const [response] = await client.startReplica(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startReplica without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.startReplica = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.startReplica( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startReplica with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.startReplica = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.startReplica(request), expectedError); - const actualRequest = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startReplica with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.startReplica(request), expectedError); - }); + it('invokes restoreBackup with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.restoreBackup(request), expectedError); }); - - describe('stopReplica', () => { - it('invokes stopReplica without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.stopReplica = stubSimpleCall(expectedResponse); - const [response] = await client.stopReplica(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes stopReplica without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.stopReplica = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.stopReplica( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes stopReplica with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.stopReplica = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.stopReplica(request), expectedError); - const actualRequest = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes stopReplica with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.stopReplica(request), expectedError); - }); + }); + + describe('rotateServerCa', () => { + it('invokes rotateServerCa without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rotateServerCa = stubSimpleCall(expectedResponse); + const [response] = await client.rotateServerCa(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('truncateLog', () => { - it('invokes truncateLog without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.truncateLog = stubSimpleCall(expectedResponse); - const [response] = await client.truncateLog(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateServerCa without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rotateServerCa = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rotateServerCa( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes truncateLog without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.truncateLog = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.truncateLog( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateServerCa with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rotateServerCa = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.rotateServerCa(request), expectedError); + const actualRequest = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes truncateLog with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.truncateLog = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.truncateLog(request), expectedError); - const actualRequest = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateServerCa with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.rotateServerCa(request), expectedError); + }); + }); + + describe('rotateServerCertificate', () => { + it('invokes rotateServerCertificate without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rotateServerCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.rotateServerCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes truncateLog with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.truncateLog(request), expectedError); - }); + it('invokes rotateServerCertificate without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rotateServerCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rotateServerCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('update', () => { - it('invokes update without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.update = stubSimpleCall(expectedResponse); - const [response] = await client.update(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateServerCertificate with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rotateServerCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.rotateServerCertificate(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.update = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.update( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateServerCertificate with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.rotateServerCertificate(request), + expectedError, + ); + }); + }); + + describe('rotateEntraIdCertificate', () => { + it('invokes rotateEntraIdCertificate without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rotateEntraIdCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.rotateEntraIdCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.update(request), expectedError); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateEntraIdCertificate without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rotateEntraIdCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rotateEntraIdCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.update(request), expectedError); - }); + it('invokes rotateEntraIdCertificate with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.rotateEntraIdCertificate(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('createEphemeral', () => { - it('invokes createEphemeral without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCert() - ); - client.innerApiCalls.createEphemeral = stubSimpleCall(expectedResponse); - const [response] = await client.createEphemeral(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rotateEntraIdCertificate with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.rotateEntraIdCertificate(request), + expectedError, + ); + }); + }); + + describe('startReplica', () => { + it('invokes startReplica without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.startReplica = stubSimpleCall(expectedResponse); + const [response] = await client.startReplica(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes createEphemeral without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCert() - ); - client.innerApiCalls.createEphemeral = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createEphemeral( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISslCert|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes startReplica without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.startReplica = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.startReplica( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes createEphemeral with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createEphemeral = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createEphemeral(request), expectedError); - const actualRequest = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes startReplica with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.startReplica = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.startReplica(request), expectedError); + const actualRequest = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes createEphemeral with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createEphemeral(request), expectedError); - }); + it('invokes startReplica with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.startReplica(request), expectedError); + }); + }); + + describe('stopReplica', () => { + it('invokes stopReplica without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.stopReplica = stubSimpleCall(expectedResponse); + const [response] = await client.stopReplica(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('rescheduleMaintenance', () => { - it('invokes rescheduleMaintenance without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rescheduleMaintenance = stubSimpleCall(expectedResponse); - const [response] = await client.rescheduleMaintenance(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes stopReplica without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.stopReplica = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.stopReplica( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes rescheduleMaintenance without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.rescheduleMaintenance = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rescheduleMaintenance( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes stopReplica with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.stopReplica = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.stopReplica(request), expectedError); + const actualRequest = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes rescheduleMaintenance with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rescheduleMaintenance = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rescheduleMaintenance(request), expectedError); - const actualRequest = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes stopReplica with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.stopReplica(request), expectedError); + }); + }); + + describe('truncateLog', () => { + it('invokes truncateLog without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.truncateLog = stubSimpleCall(expectedResponse); + const [response] = await client.truncateLog(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes rescheduleMaintenance with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rescheduleMaintenance(request), expectedError); - }); + it('invokes truncateLog without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.truncateLog = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.truncateLog( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('verifyExternalSyncSettings', () => { - it('invokes verifyExternalSyncSettings without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsResponse() - ); - client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCall(expectedResponse); - const [response] = await client.verifyExternalSyncSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes truncateLog with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.truncateLog = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.truncateLog(request), expectedError); + const actualRequest = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes verifyExternalSyncSettings without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsResponse() - ); - client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyExternalSyncSettings( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes truncateLog with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.truncateLog(request), expectedError); + }); + }); + + describe('update', () => { + it('invokes update without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.update = stubSimpleCall(expectedResponse); + const [response] = await client.update(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes verifyExternalSyncSettings with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyExternalSyncSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes update without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.update = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.update( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes verifyExternalSyncSettings with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyExternalSyncSettings(request), expectedError); - }); + it('invokes update with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.update(request), expectedError); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('startExternalSync', () => { - it('invokes startExternalSync without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.startExternalSync = stubSimpleCall(expectedResponse); - const [response] = await client.startExternalSync(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes update with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.update(request), expectedError); + }); + }); + + describe('createEphemeral', () => { + it('invokes createEphemeral without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCert(), + ); + client.innerApiCalls.createEphemeral = stubSimpleCall(expectedResponse); + const [response] = await client.createEphemeral(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes startExternalSync without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.startExternalSync = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.startExternalSync( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes createEphemeral without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCert(), + ); + client.innerApiCalls.createEphemeral = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createEphemeral( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISslCert | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes startExternalSync with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.startExternalSync = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.startExternalSync(request), expectedError); - const actualRequest = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes createEphemeral with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createEphemeral = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.createEphemeral(request), expectedError); + const actualRequest = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes startExternalSync with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.startExternalSync(request), expectedError); - }); + it('invokes createEphemeral with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.createEphemeral(request), expectedError); + }); + }); + + describe('rescheduleMaintenance', () => { + it('invokes rescheduleMaintenance without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rescheduleMaintenance = + stubSimpleCall(expectedResponse); + const [response] = await client.rescheduleMaintenance(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('performDiskShrink', () => { - it('invokes performDiskShrink without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.performDiskShrink = stubSimpleCall(expectedResponse); - const [response] = await client.performDiskShrink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rescheduleMaintenance without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.rescheduleMaintenance = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rescheduleMaintenance( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes performDiskShrink without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.performDiskShrink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.performDiskShrink( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rescheduleMaintenance with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rescheduleMaintenance = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.rescheduleMaintenance(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes performDiskShrink with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.performDiskShrink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.performDiskShrink(request), expectedError); - const actualRequest = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes rescheduleMaintenance with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.rescheduleMaintenance(request), + expectedError, + ); + }); + }); + + describe('verifyExternalSyncSettings', () => { + it('invokes verifyExternalSyncSettings without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsResponse(), + ); + client.innerApiCalls.verifyExternalSyncSettings = + stubSimpleCall(expectedResponse); + const [response] = await client.verifyExternalSyncSettings(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes performDiskShrink with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.performDiskShrink(request), expectedError); - }); + it('invokes verifyExternalSyncSettings without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsResponse(), + ); + client.innerApiCalls.verifyExternalSyncSettings = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.verifyExternalSyncSettings( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISqlInstancesVerifyExternalSyncSettingsResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getDiskShrinkConfig', () => { - it('invokes getDiskShrinkConfig without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigResponse() - ); - client.innerApiCalls.getDiskShrinkConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getDiskShrinkConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes verifyExternalSyncSettings with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.verifyExternalSyncSettings(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getDiskShrinkConfig without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigResponse() - ); - client.innerApiCalls.getDiskShrinkConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDiskShrinkConfig( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes verifyExternalSyncSettings with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.verifyExternalSyncSettings(request), + expectedError, + ); + }); + }); + + describe('startExternalSync', () => { + it('invokes startExternalSync without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.startExternalSync = stubSimpleCall(expectedResponse); + const [response] = await client.startExternalSync(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getDiskShrinkConfig with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDiskShrinkConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDiskShrinkConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes startExternalSync without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.startExternalSync = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.startExternalSync( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getDiskShrinkConfig with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDiskShrinkConfig(request), expectedError); - }); + it('invokes startExternalSync with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.startExternalSync = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.startExternalSync(request), expectedError); + const actualRequest = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('resetReplicaSize', () => { - it('invokes resetReplicaSize without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.resetReplicaSize = stubSimpleCall(expectedResponse); - const [response] = await client.resetReplicaSize(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes startExternalSync with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.startExternalSync(request), expectedError); + }); + }); + + describe('performDiskShrink', () => { + it('invokes performDiskShrink without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.performDiskShrink = stubSimpleCall(expectedResponse); + const [response] = await client.performDiskShrink(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes resetReplicaSize without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.resetReplicaSize = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resetReplicaSize( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes performDiskShrink without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.performDiskShrink = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.performDiskShrink( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes resetReplicaSize with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resetReplicaSize = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resetReplicaSize(request), expectedError); - const actualRequest = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes performDiskShrink with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.performDiskShrink = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.performDiskShrink(request), expectedError); + const actualRequest = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes resetReplicaSize with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resetReplicaSize(request), expectedError); - }); + it('invokes performDiskShrink with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.performDiskShrink(request), expectedError); + }); + }); + + describe('getDiskShrinkConfig', () => { + it('invokes getDiskShrinkConfig without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigResponse(), + ); + client.innerApiCalls.getDiskShrinkConfig = + stubSimpleCall(expectedResponse); + const [response] = await client.getDiskShrinkConfig(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getLatestRecoveryTime', () => { - it('invokes getLatestRecoveryTime without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeResponse() - ); - client.innerApiCalls.getLatestRecoveryTime = stubSimpleCall(expectedResponse); - const [response] = await client.getLatestRecoveryTime(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getDiskShrinkConfig without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigResponse(), + ); + client.innerApiCalls.getDiskShrinkConfig = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getDiskShrinkConfig( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISqlInstancesGetDiskShrinkConfigResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getLatestRecoveryTime without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeResponse() - ); - client.innerApiCalls.getLatestRecoveryTime = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLatestRecoveryTime( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getDiskShrinkConfig with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getDiskShrinkConfig = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.getDiskShrinkConfig(request), expectedError); + const actualRequest = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getLatestRecoveryTime with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getLatestRecoveryTime = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getLatestRecoveryTime(request), expectedError); - const actualRequest = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getDiskShrinkConfig with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.getDiskShrinkConfig(request), expectedError); + }); + }); + + describe('resetReplicaSize', () => { + it('invokes resetReplicaSize without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.resetReplicaSize = stubSimpleCall(expectedResponse); + const [response] = await client.resetReplicaSize(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes getLatestRecoveryTime with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getLatestRecoveryTime(request), expectedError); - }); + it('invokes resetReplicaSize without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.resetReplicaSize = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.resetReplicaSize( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('executeSql', () => { - it('invokes executeSql without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlResponse() - ); - client.innerApiCalls.executeSql = stubSimpleCall(expectedResponse); - const [response] = await client.executeSql(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes resetReplicaSize with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.resetReplicaSize = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.resetReplicaSize(request), expectedError); + const actualRequest = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes executeSql without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlResponse() - ); - client.innerApiCalls.executeSql = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.executeSql( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes resetReplicaSize with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.resetReplicaSize(request), expectedError); + }); + }); + + describe('getLatestRecoveryTime', () => { + it('invokes getLatestRecoveryTime without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeResponse(), + ); + client.innerApiCalls.getLatestRecoveryTime = + stubSimpleCall(expectedResponse); + const [response] = await client.getLatestRecoveryTime(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes executeSql with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.executeSql = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.executeSql(request), expectedError); - const actualRequest = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getLatestRecoveryTime without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeResponse(), + ); + client.innerApiCalls.getLatestRecoveryTime = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getLatestRecoveryTime( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISqlInstancesGetLatestRecoveryTimeResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes executeSql with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.executeSql(request), expectedError); - }); + it('invokes getLatestRecoveryTime with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getLatestRecoveryTime = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.getLatestRecoveryTime(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('acquireSsrsLease', () => { - it('invokes acquireSsrsLease without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseResponse() - ); - client.innerApiCalls.acquireSsrsLease = stubSimpleCall(expectedResponse); - const [response] = await client.acquireSsrsLease(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes getLatestRecoveryTime with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.getLatestRecoveryTime(request), + expectedError, + ); + }); + }); + + describe('executeSql', () => { + it('invokes executeSql without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlResponse(), + ); + client.innerApiCalls.executeSql = stubSimpleCall(expectedResponse); + const [response] = await client.executeSql(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes acquireSsrsLease without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseResponse() - ); - client.innerApiCalls.acquireSsrsLease = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.acquireSsrsLease( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes executeSql without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlResponse(), + ); + client.innerApiCalls.executeSql = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.executeSql( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISqlInstancesExecuteSqlResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes acquireSsrsLease with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.acquireSsrsLease = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.acquireSsrsLease(request), expectedError); - const actualRequest = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes executeSql with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.executeSql = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.executeSql(request), expectedError); + const actualRequest = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes acquireSsrsLease with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.acquireSsrsLease(request), expectedError); - }); + it('invokes executeSql with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.executeSql(request), expectedError); + }); + }); + + describe('acquireSsrsLease', () => { + it('invokes acquireSsrsLease without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseResponse(), + ); + client.innerApiCalls.acquireSsrsLease = stubSimpleCall(expectedResponse); + const [response] = await client.acquireSsrsLease(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('releaseSsrsLease', () => { - it('invokes releaseSsrsLease without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseResponse() - ); - client.innerApiCalls.releaseSsrsLease = stubSimpleCall(expectedResponse); - const [response] = await client.releaseSsrsLease(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes acquireSsrsLease without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseResponse(), + ); + client.innerApiCalls.acquireSsrsLease = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.acquireSsrsLease( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISqlInstancesAcquireSsrsLeaseResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes releaseSsrsLease without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseResponse() - ); - client.innerApiCalls.releaseSsrsLease = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.releaseSsrsLease( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes acquireSsrsLease with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.acquireSsrsLease = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.acquireSsrsLease(request), expectedError); + const actualRequest = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes releaseSsrsLease with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.releaseSsrsLease = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.releaseSsrsLease(request), expectedError); - const actualRequest = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes acquireSsrsLease with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.acquireSsrsLease(request), expectedError); + }); + }); + + describe('releaseSsrsLease', () => { + it('invokes releaseSsrsLease without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseResponse(), + ); + client.innerApiCalls.releaseSsrsLease = stubSimpleCall(expectedResponse); + const [response] = await client.releaseSsrsLease(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes releaseSsrsLease with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.releaseSsrsLease(request), expectedError); - }); + it('invokes releaseSsrsLease without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseResponse(), + ); + client.innerApiCalls.releaseSsrsLease = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.releaseSsrsLease( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISqlInstancesReleaseSsrsLeaseResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('preCheckMajorVersionUpgrade', () => { - it('invokes preCheckMajorVersionUpgrade without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCall(expectedResponse); - const [response] = await client.preCheckMajorVersionUpgrade(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes releaseSsrsLease with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.releaseSsrsLease = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.releaseSsrsLease(request), expectedError); + const actualRequest = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes preCheckMajorVersionUpgrade without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.preCheckMajorVersionUpgrade( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes releaseSsrsLease with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.releaseSsrsLease(request), expectedError); + }); + }); + + describe('preCheckMajorVersionUpgrade', () => { + it('invokes preCheckMajorVersionUpgrade without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.preCheckMajorVersionUpgrade = + stubSimpleCall(expectedResponse); + const [response] = await client.preCheckMajorVersionUpgrade(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes preCheckMajorVersionUpgrade with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.preCheckMajorVersionUpgrade(request), expectedError); - const actualRequest = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes preCheckMajorVersionUpgrade without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.preCheckMajorVersionUpgrade = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.preCheckMajorVersionUpgrade( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes preCheckMajorVersionUpgrade with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.preCheckMajorVersionUpgrade(request), expectedError); - }); + it('invokes preCheckMajorVersionUpgrade with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.preCheckMajorVersionUpgrade(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('pointInTimeRestore', () => { - it('invokes pointInTimeRestore without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.pointInTimeRestore = stubSimpleCall(expectedResponse); - const [response] = await client.pointInTimeRestore(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes preCheckMajorVersionUpgrade with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.preCheckMajorVersionUpgrade(request), + expectedError, + ); + }); + }); + + describe('pointInTimeRestore', () => { + it('invokes pointInTimeRestore without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.pointInTimeRestore = + stubSimpleCall(expectedResponse); + const [response] = await client.pointInTimeRestore(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes pointInTimeRestore without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.pointInTimeRestore = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pointInTimeRestore( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes pointInTimeRestore without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.pointInTimeRestore = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.pointInTimeRestore( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes pointInTimeRestore with error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.pointInTimeRestore = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pointInTimeRestore(request), expectedError); - const actualRequest = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes pointInTimeRestore with error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.pointInTimeRestore = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.pointInTimeRestore(request), expectedError); + const actualRequest = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes pointInTimeRestore with closed client', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pointInTimeRestore(request), expectedError); - }); + it('invokes pointInTimeRestore with closed client', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.pointInTimeRestore(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - 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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - 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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - 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)); - }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + backupvault: 'backupvaultValue', + datasource: 'datasourceValue', + backup: 'backupValue', + }; + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath( + 'projectValue', + 'locationValue', + 'backupvaultValue', + 'datasourceValue', + 'backupValue', + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchLocationFromBackupName', () => { + const result = client.matchLocationFromBackupName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupvaultFromBackupName', () => { + const result = client.matchBackupvaultFromBackupName(fakePath); + assert.strictEqual(result, 'backupvaultValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchDatasourceFromBackupName', () => { + const result = client.matchDatasourceFromBackupName(fakePath); + assert.strictEqual(result, 'datasourceValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - backupvault: "backupvaultValue", - datasource: "datasourceValue", - backup: "backupValue", - }; - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "locationValue", "backupvaultValue", "datasourceValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBackupName', () => { - const result = client.matchLocationFromBackupName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupvaultFromBackupName', () => { - const result = client.matchBackupvaultFromBackupName(fakePath); - assert.strictEqual(result, "backupvaultValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDatasourceFromBackupName', () => { - const result = client.matchDatasourceFromBackupName(fakePath); - assert.strictEqual(result, "datasourceValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('network', async () => { - const fakePath = "/rendered/path/network"; - const expectedParameters = { - project: "projectValue", - network: "networkValue", - }; - const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.networkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.networkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('networkPath', () => { - const result = client.networkPath("projectValue", "networkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.networkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromNetworkName', () => { - const result = client.matchProjectFromNetworkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.networkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNetworkFromNetworkName', () => { - const result = client.matchNetworkFromNetworkName(fakePath); - assert.strictEqual(result, "networkValue"); - assert((client.pathTemplates.networkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + describe('network', async () => { + const fakePath = '/rendered/path/network'; + const expectedParameters = { + project: 'projectValue', + network: 'networkValue', + }; + const client = new sqlinstancesserviceModule.v1.SqlInstancesServiceClient( + { + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }, + ); + await client.initialize(); + client.pathTemplates.networkPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.networkPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('networkPath', () => { + const result = client.networkPath('projectValue', 'networkValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.networkPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromNetworkName', () => { + const result = client.matchProjectFromNetworkName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.networkPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchNetworkFromNetworkName', () => { + const result = client.matchNetworkFromNetworkName(fakePath); + assert.strictEqual(result, 'networkValue'); + assert( + (client.pathTemplates.networkPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_instances_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_instances_service_v1beta4.ts index 5a2dbf876691..57ac7bbd95ca 100644 --- a/packages/google-cloud-sql/test/gapic_sql_instances_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_instances_service_v1beta4.ts @@ -19,5577 +19,7230 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlinstancesserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlInstancesServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); - 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 = sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); + it('has universeDomain', () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); - it('has port', () => { - const port = sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient.port; - assert(port); - assert(typeof port === 'number'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient + .servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); - assert(client); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - fallback: true, - }); - assert(client); + 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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlInstancesServiceStub, undefined); - await client.initialize(); - assert(client.sqlInstancesServiceStub); - }); + it('has port', () => { + const port = + sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('has close method for the initialized client', done => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlInstancesServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('should create a client with no option', () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlInstancesServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlInstancesServiceStub, undefined); + await client.initialize(); + assert(client.sqlInstancesServiceStub); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - 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 close method for the initialized client', (done) => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlInstancesServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - 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); + it('has close method for the non-initialized client', (done) => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlInstancesServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); }); - describe('addServerCa', () => { - it('invokes addServerCa without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.addServerCa = stubSimpleCall(expectedResponse); - const [response] = await client.addServerCa(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addServerCa without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.addServerCa = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addServerCa( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addServerCa with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addServerCa = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addServerCa(request), expectedError); - const actualRequest = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addServerCa with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addServerCa(request), expectedError); - }); - }); - - describe('addServerCertificate', () => { - it('invokes addServerCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.addServerCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.addServerCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addServerCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.addServerCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addServerCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addServerCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addServerCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addServerCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addServerCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addServerCertificate(request), expectedError); - }); - }); - - describe('addEntraIdCertificate', () => { - it('invokes addEntraIdCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.addEntraIdCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.addEntraIdCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addEntraIdCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.addEntraIdCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addEntraIdCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addEntraIdCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addEntraIdCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addEntraIdCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addEntraIdCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addEntraIdCertificate(request), expectedError); - }); - }); - - describe('clone', () => { - it('invokes clone without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.clone = stubSimpleCall(expectedResponse); - const [response] = await client.clone(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes clone without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.clone = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.clone( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes clone with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.clone = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.clone(request), expectedError); - const actualRequest = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.clone as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes clone with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.clone(request), expectedError); - }); - }); - - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); - }); - - describe('demoteMaster', () => { - it('invokes demoteMaster without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.demoteMaster = stubSimpleCall(expectedResponse); - const [response] = await client.demoteMaster(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes demoteMaster without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.demoteMaster = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.demoteMaster( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes demoteMaster with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.demoteMaster = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.demoteMaster(request), expectedError); - const actualRequest = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demoteMaster as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes demoteMaster with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.demoteMaster(request), expectedError); - }); - }); - - describe('demote', () => { - it('invokes demote without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.demote = stubSimpleCall(expectedResponse); - const [response] = await client.demote(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes demote without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.demote = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.demote( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes demote with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.demote = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.demote(request), expectedError); - const actualRequest = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.demote as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes demote with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.demote(request), expectedError); - }); - }); - - describe('export', () => { - it('invokes export without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.export = stubSimpleCall(expectedResponse); - const [response] = await client.export(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes export without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.export = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.export( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes export with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.export = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.export(request), expectedError); - const actualRequest = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.export as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes export with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExportRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.export(request), expectedError); - }); - }); - - describe('failover', () => { - it('invokes failover without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.failover = stubSimpleCall(expectedResponse); - const [response] = await client.failover(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failover without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.failover = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.failover( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failover with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.failover = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.failover(request), expectedError); - const actualRequest = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failover with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.failover(request), expectedError); - }); - }); - - describe('reencrypt', () => { - it('invokes reencrypt without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.reencrypt = stubSimpleCall(expectedResponse); - const [response] = await client.reencrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reencrypt without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.reencrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reencrypt( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reencrypt with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reencrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reencrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reencrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reencrypt with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reencrypt(request), expectedError); - }); - }); - - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DatabaseInstance() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.DatabaseInstance() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IDatabaseInstance|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('import', () => { - it('invokes import without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.import = stubSimpleCall(expectedResponse); - const [response] = await client.import(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes import without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.import = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.import( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes import with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.import = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.import(request), expectedError); - const actualRequest = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.import as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes import with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesImportRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.import(request), expectedError); - }); - }); - - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IInstancesListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); - }); - - describe('listServerCas', () => { - it('invokes listServerCas without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListServerCasResponse() - ); - client.innerApiCalls.listServerCas = stubSimpleCall(expectedResponse); - const [response] = await client.listServerCas(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCas without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListServerCasResponse() - ); - client.innerApiCalls.listServerCas = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServerCas( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCas with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServerCas = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServerCas(request), expectedError); - const actualRequest = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCas with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listServerCas(request), expectedError); - }); - }); - - describe('listServerCertificates', () => { - it('invokes listServerCertificates without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListServerCertificatesResponse() - ); - client.innerApiCalls.listServerCertificates = stubSimpleCall(expectedResponse); - const [response] = await client.listServerCertificates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCertificates without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListServerCertificatesResponse() - ); - client.innerApiCalls.listServerCertificates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServerCertificates( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCertificates with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServerCertificates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServerCertificates(request), expectedError); - const actualRequest = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServerCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServerCertificates with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listServerCertificates(request), expectedError); - }); - }); - - describe('listEntraIdCertificates', () => { - it('invokes listEntraIdCertificates without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListEntraIdCertificatesResponse() - ); - client.innerApiCalls.listEntraIdCertificates = stubSimpleCall(expectedResponse); - const [response] = await client.listEntraIdCertificates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEntraIdCertificates without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.InstancesListEntraIdCertificatesResponse() - ); - client.innerApiCalls.listEntraIdCertificates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listEntraIdCertificates( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEntraIdCertificates with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listEntraIdCertificates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listEntraIdCertificates(request), expectedError); - const actualRequest = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEntraIdCertificates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEntraIdCertificates with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listEntraIdCertificates(request), expectedError); - }); - }); - - describe('patch', () => { - it('invokes patch without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.patch = stubSimpleCall(expectedResponse); - const [response] = await client.patch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patch without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patch( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patch with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patch(request), expectedError); - const actualRequest = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patch with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patch(request), expectedError); - }); - }); - - describe('promoteReplica', () => { - it('invokes promoteReplica without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.promoteReplica = stubSimpleCall(expectedResponse); - const [response] = await client.promoteReplica(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes promoteReplica without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.promoteReplica = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.promoteReplica( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes promoteReplica with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.promoteReplica = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.promoteReplica(request), expectedError); - const actualRequest = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.promoteReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes promoteReplica with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.promoteReplica(request), expectedError); - }); - }); - - describe('switchover', () => { - it('invokes switchover without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.switchover = stubSimpleCall(expectedResponse); - const [response] = await client.switchover(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes switchover without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.switchover = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.switchover( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes switchover with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.switchover = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.switchover(request), expectedError); - const actualRequest = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.switchover as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes switchover with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.switchover(request), expectedError); - }); - }); - - describe('resetSslConfig', () => { - it('invokes resetSslConfig without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.resetSslConfig = stubSimpleCall(expectedResponse); - const [response] = await client.resetSslConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetSslConfig without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.resetSslConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resetSslConfig( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetSslConfig with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resetSslConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resetSslConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetSslConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetSslConfig with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resetSslConfig(request), expectedError); - }); - }); - - describe('restart', () => { - it('invokes restart without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.restart = stubSimpleCall(expectedResponse); - const [response] = await client.restart(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restart without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.restart = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restart( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restart with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.restart = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.restart(request), expectedError); - const actualRequest = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restart as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restart with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.restart(request), expectedError); - }); - }); - - describe('restoreBackup', () => { - it('invokes restoreBackup without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.restoreBackup = stubSimpleCall(expectedResponse); - const [response] = await client.restoreBackup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreBackup without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.restoreBackup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restoreBackup( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreBackup with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.restoreBackup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.restoreBackup(request), expectedError); - const actualRequest = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreBackup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreBackup with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.restoreBackup(request), expectedError); - }); - }); - - describe('rotateServerCa', () => { - it('invokes rotateServerCa without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rotateServerCa = stubSimpleCall(expectedResponse); - const [response] = await client.rotateServerCa(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCa without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rotateServerCa = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rotateServerCa( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCa with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rotateServerCa = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rotateServerCa(request), expectedError); - const actualRequest = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCa as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCa with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rotateServerCa(request), expectedError); - }); - }); - - describe('rotateServerCertificate', () => { - it('invokes rotateServerCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rotateServerCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.rotateServerCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rotateServerCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rotateServerCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rotateServerCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rotateServerCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateServerCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateServerCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rotateServerCertificate(request), expectedError); - }); - }); - - describe('rotateEntraIdCertificate', () => { - it('invokes rotateEntraIdCertificate without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCall(expectedResponse); - const [response] = await client.rotateEntraIdCertificate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateEntraIdCertificate without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rotateEntraIdCertificate( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateEntraIdCertificate with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rotateEntraIdCertificate(request), expectedError); - const actualRequest = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rotateEntraIdCertificate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rotateEntraIdCertificate with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rotateEntraIdCertificate(request), expectedError); - }); - }); - - describe('startReplica', () => { - it('invokes startReplica without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.startReplica = stubSimpleCall(expectedResponse); - const [response] = await client.startReplica(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startReplica without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.startReplica = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.startReplica( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startReplica with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.startReplica = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.startReplica(request), expectedError); - const actualRequest = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startReplica with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.startReplica(request), expectedError); - }); - }); - - describe('stopReplica', () => { - it('invokes stopReplica without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.stopReplica = stubSimpleCall(expectedResponse); - const [response] = await client.stopReplica(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes stopReplica without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.stopReplica = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.stopReplica( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes stopReplica with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.stopReplica = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.stopReplica(request), expectedError); - const actualRequest = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.stopReplica as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes stopReplica with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.stopReplica(request), expectedError); - }); - }); - - describe('truncateLog', () => { - it('invokes truncateLog without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.truncateLog = stubSimpleCall(expectedResponse); - const [response] = await client.truncateLog(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes truncateLog without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.truncateLog = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.truncateLog( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes truncateLog with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.truncateLog = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.truncateLog(request), expectedError); - const actualRequest = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.truncateLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes truncateLog with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.truncateLog(request), expectedError); - }); - }); - - describe('update', () => { - it('invokes update without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.update = stubSimpleCall(expectedResponse); - const [response] = await client.update(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes update without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.update = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.update( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes update with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.update(request), expectedError); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes update with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.update(request), expectedError); - }); - }); - - describe('createEphemeral', () => { - it('invokes createEphemeral without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCert() - ); - client.innerApiCalls.createEphemeral = stubSimpleCall(expectedResponse); - const [response] = await client.createEphemeral(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createEphemeral without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCert() - ); - client.innerApiCalls.createEphemeral = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createEphemeral( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISslCert|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createEphemeral with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createEphemeral = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createEphemeral(request), expectedError); - const actualRequest = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createEphemeral as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createEphemeral with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createEphemeral(request), expectedError); - }); - }); - - describe('rescheduleMaintenance', () => { - it('invokes rescheduleMaintenance without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rescheduleMaintenance = stubSimpleCall(expectedResponse); - const [response] = await client.rescheduleMaintenance(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rescheduleMaintenance without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.rescheduleMaintenance = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rescheduleMaintenance( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rescheduleMaintenance with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rescheduleMaintenance = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rescheduleMaintenance(request), expectedError); - const actualRequest = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rescheduleMaintenance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rescheduleMaintenance with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.rescheduleMaintenance(request), expectedError); - }); - }); - - describe('verifyExternalSyncSettings', () => { - it('invokes verifyExternalSyncSettings without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsResponse() - ); - client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCall(expectedResponse); - const [response] = await client.verifyExternalSyncSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyExternalSyncSettings without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsResponse() - ); - client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyExternalSyncSettings( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyExternalSyncSettings with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyExternalSyncSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyExternalSyncSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyExternalSyncSettings with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyExternalSyncSettings(request), expectedError); - }); - }); - - describe('startExternalSync', () => { - it('invokes startExternalSync without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.startExternalSync = stubSimpleCall(expectedResponse); - const [response] = await client.startExternalSync(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startExternalSync without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.startExternalSync = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.startExternalSync( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startExternalSync with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.startExternalSync = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.startExternalSync(request), expectedError); - const actualRequest = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.startExternalSync as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes startExternalSync with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.startExternalSync(request), expectedError); - }); - }); - - describe('performDiskShrink', () => { - it('invokes performDiskShrink without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.performDiskShrink = stubSimpleCall(expectedResponse); - const [response] = await client.performDiskShrink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes performDiskShrink without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.performDiskShrink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.performDiskShrink( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes performDiskShrink with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.performDiskShrink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.performDiskShrink(request), expectedError); - const actualRequest = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.performDiskShrink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes performDiskShrink with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.performDiskShrink(request), expectedError); - }); - }); - - describe('getDiskShrinkConfig', () => { - it('invokes getDiskShrinkConfig without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigResponse() - ); - client.innerApiCalls.getDiskShrinkConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getDiskShrinkConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDiskShrinkConfig without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigResponse() - ); - client.innerApiCalls.getDiskShrinkConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDiskShrinkConfig( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDiskShrinkConfig with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDiskShrinkConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDiskShrinkConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDiskShrinkConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDiskShrinkConfig with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDiskShrinkConfig(request), expectedError); - }); - }); - - describe('resetReplicaSize', () => { - it('invokes resetReplicaSize without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.resetReplicaSize = stubSimpleCall(expectedResponse); - const [response] = await client.resetReplicaSize(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetReplicaSize without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.resetReplicaSize = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resetReplicaSize( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetReplicaSize with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resetReplicaSize = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resetReplicaSize(request), expectedError); - const actualRequest = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resetReplicaSize as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resetReplicaSize with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resetReplicaSize(request), expectedError); - }); - }); - - describe('getLatestRecoveryTime', () => { - it('invokes getLatestRecoveryTime without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeResponse() - ); - client.innerApiCalls.getLatestRecoveryTime = stubSimpleCall(expectedResponse); - const [response] = await client.getLatestRecoveryTime(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLatestRecoveryTime without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeResponse() - ); - client.innerApiCalls.getLatestRecoveryTime = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLatestRecoveryTime( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLatestRecoveryTime with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getLatestRecoveryTime = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getLatestRecoveryTime(request), expectedError); - const actualRequest = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLatestRecoveryTime as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLatestRecoveryTime with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getLatestRecoveryTime(request), expectedError); - }); - }); - - describe('executeSql', () => { - it('invokes executeSql without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlResponse() - ); - client.innerApiCalls.executeSql = stubSimpleCall(expectedResponse); - const [response] = await client.executeSql(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes executeSql without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlResponse() - ); - client.innerApiCalls.executeSql = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.executeSql( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes executeSql with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.executeSql = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.executeSql(request), expectedError); - const actualRequest = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.executeSql as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes executeSql with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.executeSql(request), expectedError); - }); - }); - - describe('acquireSsrsLease', () => { - it('invokes acquireSsrsLease without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseResponse() - ); - client.innerApiCalls.acquireSsrsLease = stubSimpleCall(expectedResponse); - const [response] = await client.acquireSsrsLease(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acquireSsrsLease without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseResponse() - ); - client.innerApiCalls.acquireSsrsLease = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.acquireSsrsLease( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acquireSsrsLease with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.acquireSsrsLease = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.acquireSsrsLease(request), expectedError); - const actualRequest = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acquireSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acquireSsrsLease with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.acquireSsrsLease(request), expectedError); - }); - }); - - describe('releaseSsrsLease', () => { - it('invokes releaseSsrsLease without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseResponse() - ); - client.innerApiCalls.releaseSsrsLease = stubSimpleCall(expectedResponse); - const [response] = await client.releaseSsrsLease(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes releaseSsrsLease without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseResponse() - ); - client.innerApiCalls.releaseSsrsLease = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.releaseSsrsLease( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes releaseSsrsLease with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.releaseSsrsLease = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.releaseSsrsLease(request), expectedError); - const actualRequest = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.releaseSsrsLease as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes releaseSsrsLease with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.releaseSsrsLease(request), expectedError); - }); - }); - - describe('preCheckMajorVersionUpgrade', () => { - it('invokes preCheckMajorVersionUpgrade without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCall(expectedResponse); - const [response] = await client.preCheckMajorVersionUpgrade(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes preCheckMajorVersionUpgrade without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.preCheckMajorVersionUpgrade( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes preCheckMajorVersionUpgrade with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.preCheckMajorVersionUpgrade(request), expectedError); - const actualRequest = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes preCheckMajorVersionUpgrade with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.preCheckMajorVersionUpgrade(request), expectedError); - }); - }); - - describe('pointInTimeRestore', () => { - it('invokes pointInTimeRestore without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.pointInTimeRestore = stubSimpleCall(expectedResponse); - const [response] = await client.pointInTimeRestore(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pointInTimeRestore without error using callback', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.pointInTimeRestore = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pointInTimeRestore( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pointInTimeRestore with error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.pointInTimeRestore = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pointInTimeRestore(request), expectedError); - const actualRequest = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pointInTimeRestore as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pointInTimeRestore with closed client', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pointInTimeRestore(request), expectedError); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - 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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - 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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - 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)); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + 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('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + 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('addServerCa', () => { + it('invokes addServerCa without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.addServerCa = stubSimpleCall(expectedResponse); + const [response] = await client.addServerCa(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes addServerCa without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.addServerCa = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.addServerCa( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('invokes addServerCa with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.addServerCa = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.addServerCa(request), expectedError); + const actualRequest = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes addServerCa with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.addServerCa(request), expectedError); + }); + }); + + describe('addServerCertificate', () => { + it('invokes addServerCertificate without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.addServerCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.addServerCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes addServerCertificate without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.addServerCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.addServerCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes addServerCertificate with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.addServerCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.addServerCertificate(request), expectedError); + const actualRequest = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes addServerCertificate with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.addServerCertificate(request), expectedError); + }); + }); + + describe('addEntraIdCertificate', () => { + it('invokes addEntraIdCertificate without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.addEntraIdCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.addEntraIdCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes addEntraIdCertificate without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.addEntraIdCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.addEntraIdCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes addEntraIdCertificate with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.addEntraIdCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.addEntraIdCertificate(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.addEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes addEntraIdCertificate with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAddEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.addEntraIdCertificate(request), + expectedError, + ); + }); + }); + + describe('clone', () => { + it('invokes clone without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.clone = stubSimpleCall(expectedResponse); + const [response] = await client.clone(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.clone as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.clone as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes clone without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.clone = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.clone( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.clone as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.clone as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes clone with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.clone = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.clone(request), expectedError); + const actualRequest = (client.innerApiCalls.clone as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.clone as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes clone with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCloneRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCloneRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.clone(request), expectedError); + }); + }); + + describe('delete', () => { + it('invokes delete without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes delete without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes delete with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes delete with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); + + describe('demoteMaster', () => { + it('invokes demoteMaster without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.demoteMaster = stubSimpleCall(expectedResponse); + const [response] = await client.demoteMaster(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes demoteMaster without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.demoteMaster = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.demoteMaster( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes demoteMaster with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.demoteMaster = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.demoteMaster(request), expectedError); + const actualRequest = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demoteMaster as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes demoteMaster with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteMasterRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.demoteMaster(request), expectedError); + }); + }); + + describe('demote', () => { + it('invokes demote without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.demote = stubSimpleCall(expectedResponse); + const [response] = await client.demote(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.demote as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes demote without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.demote = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.demote( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.demote as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes demote with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.demote = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.demote(request), expectedError); + const actualRequest = (client.innerApiCalls.demote as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.demote as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes demote with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesDemoteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.demote(request), expectedError); + }); + }); + + describe('export', () => { + it('invokes export without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.export = stubSimpleCall(expectedResponse); + const [response] = await client.export(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.export as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.export as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes export without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.export = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.export( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.export as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.export as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes export with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.export = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.export(request), expectedError); + const actualRequest = (client.innerApiCalls.export as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.export as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes export with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.export(request), expectedError); + }); + }); + + describe('failover', () => { + it('invokes failover without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.failover = stubSimpleCall(expectedResponse); + const [response] = await client.failover(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes failover without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.failover = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.failover( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes failover with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.failover = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.failover(request), expectedError); + const actualRequest = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes failover with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesFailoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.failover(request), expectedError); + }); + }); + + describe('reencrypt', () => { + it('invokes reencrypt without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.reencrypt = stubSimpleCall(expectedResponse); + const [response] = await client.reencrypt(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes reencrypt without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.reencrypt = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.reencrypt( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes reencrypt with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.reencrypt = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.reencrypt(request), expectedError); + const actualRequest = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.reencrypt as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes reencrypt with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReencryptRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.reencrypt(request), expectedError); + }); + }); + + describe('get', () => { + it('invokes get without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DatabaseInstance(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.DatabaseInstance(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IDatabaseInstance | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); + + describe('import', () => { + it('invokes import without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.import = stubSimpleCall(expectedResponse); + const [response] = await client.import(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.import as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.import as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes import without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.import = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.import( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.import as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.import as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes import with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.import = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.import(request), expectedError); + const actualRequest = (client.innerApiCalls.import as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.import as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes import with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesImportRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesImportRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.import(request), expectedError); + }); + }); + + describe('insert', () => { + it('invokes insert without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IInstancesListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + + describe('listServerCas', () => { + it('invokes listServerCas without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListServerCasResponse(), + ); + client.innerApiCalls.listServerCas = stubSimpleCall(expectedResponse); + const [response] = await client.listServerCas(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listServerCas without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListServerCasResponse(), + ); + client.innerApiCalls.listServerCas = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listServerCas( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IInstancesListServerCasResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listServerCas with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listServerCas = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.listServerCas(request), expectedError); + const actualRequest = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCas as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listServerCas with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCasRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.listServerCas(request), expectedError); + }); + }); + + describe('listServerCertificates', () => { + it('invokes listServerCertificates without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListServerCertificatesResponse(), + ); + client.innerApiCalls.listServerCertificates = + stubSimpleCall(expectedResponse); + const [response] = await client.listServerCertificates(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listServerCertificates without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListServerCertificatesResponse(), + ); + client.innerApiCalls.listServerCertificates = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listServerCertificates( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IInstancesListServerCertificatesResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listServerCertificates with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listServerCertificates = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.listServerCertificates(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listServerCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listServerCertificates with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListServerCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.listServerCertificates(request), + expectedError, + ); + }); + }); + + describe('listEntraIdCertificates', () => { + it('invokes listEntraIdCertificates without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListEntraIdCertificatesResponse(), + ); + client.innerApiCalls.listEntraIdCertificates = + stubSimpleCall(expectedResponse); + const [response] = await client.listEntraIdCertificates(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listEntraIdCertificates without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.InstancesListEntraIdCertificatesResponse(), + ); + client.innerApiCalls.listEntraIdCertificates = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listEntraIdCertificates( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IInstancesListEntraIdCertificatesResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listEntraIdCertificates with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listEntraIdCertificates = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.listEntraIdCertificates(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntraIdCertificates as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listEntraIdCertificates with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesListEntraIdCertificatesRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.listEntraIdCertificates(request), + expectedError, + ); + }); + }); + + describe('patch', () => { + it('invokes patch without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCall(expectedResponse); + const [response] = await client.patch(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes patch without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.patch = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.patch( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes patch with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.patch = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.patch(request), expectedError); + const actualRequest = (client.innerApiCalls.patch as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.patch as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes patch with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPatchRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPatchRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.patch(request), expectedError); + }); + }); + + describe('promoteReplica', () => { + it('invokes promoteReplica without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.promoteReplica = stubSimpleCall(expectedResponse); + const [response] = await client.promoteReplica(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes promoteReplica without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.promoteReplica = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.promoteReplica( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes promoteReplica with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.promoteReplica = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.promoteReplica(request), expectedError); + const actualRequest = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.promoteReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes promoteReplica with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPromoteReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.promoteReplica(request), expectedError); + }); + }); + + describe('switchover', () => { + it('invokes switchover without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.switchover = stubSimpleCall(expectedResponse); + const [response] = await client.switchover(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes switchover without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.switchover = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.switchover( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes switchover with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.switchover = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.switchover(request), expectedError); + const actualRequest = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.switchover as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes switchover with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesSwitchoverRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.switchover(request), expectedError); + }); + }); + + describe('resetSslConfig', () => { + it('invokes resetSslConfig without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.resetSslConfig = stubSimpleCall(expectedResponse); + const [response] = await client.resetSslConfig(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetSslConfig without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.resetSslConfig = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.resetSslConfig( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetSslConfig with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.resetSslConfig = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.resetSslConfig(request), expectedError); + const actualRequest = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetSslConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetSslConfig with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetSslConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.resetSslConfig(request), expectedError); + }); + }); + + describe('restart', () => { + it('invokes restart without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.restart = stubSimpleCall(expectedResponse); + const [response] = await client.restart(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.restart as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restart as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes restart without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.restart = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.restart( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.restart as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restart as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes restart with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.restart = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.restart(request), expectedError); + const actualRequest = (client.innerApiCalls.restart as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restart as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes restart with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestartRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestartRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.restart(request), expectedError); + }); + }); + + describe('restoreBackup', () => { + it('invokes restoreBackup without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.restoreBackup = stubSimpleCall(expectedResponse); + const [response] = await client.restoreBackup(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes restoreBackup without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.restoreBackup = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.restoreBackup( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes restoreBackup with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.restoreBackup = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.restoreBackup(request), expectedError); + const actualRequest = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreBackup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes restoreBackup with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRestoreBackupRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.restoreBackup(request), expectedError); + }); + }); + + describe('rotateServerCa', () => { + it('invokes rotateServerCa without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rotateServerCa = stubSimpleCall(expectedResponse); + const [response] = await client.rotateServerCa(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateServerCa without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rotateServerCa = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rotateServerCa( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateServerCa with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rotateServerCa = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.rotateServerCa(request), expectedError); + const actualRequest = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCa as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateServerCa with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.rotateServerCa(request), expectedError); + }); + }); + + describe('rotateServerCertificate', () => { + it('invokes rotateServerCertificate without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rotateServerCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.rotateServerCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateServerCertificate without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rotateServerCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rotateServerCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateServerCertificate with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rotateServerCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.rotateServerCertificate(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateServerCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateServerCertificate with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateServerCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.rotateServerCertificate(request), + expectedError, + ); + }); + }); + + describe('rotateEntraIdCertificate', () => { + it('invokes rotateEntraIdCertificate without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rotateEntraIdCertificate = + stubSimpleCall(expectedResponse); + const [response] = await client.rotateEntraIdCertificate(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateEntraIdCertificate without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rotateEntraIdCertificate = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rotateEntraIdCertificate( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateEntraIdCertificate with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rotateEntraIdCertificate = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.rotateEntraIdCertificate(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rotateEntraIdCertificate as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rotateEntraIdCertificate with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRotateEntraIdCertificateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.rotateEntraIdCertificate(request), + expectedError, + ); + }); + }); + + describe('startReplica', () => { + it('invokes startReplica without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.startReplica = stubSimpleCall(expectedResponse); + const [response] = await client.startReplica(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes startReplica without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.startReplica = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.startReplica( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes startReplica with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.startReplica = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.startReplica(request), expectedError); + const actualRequest = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes startReplica with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.startReplica(request), expectedError); + }); + }); + + describe('stopReplica', () => { + it('invokes stopReplica without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.stopReplica = stubSimpleCall(expectedResponse); + const [response] = await client.stopReplica(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes stopReplica without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.stopReplica = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.stopReplica( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes stopReplica with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.stopReplica = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.stopReplica(request), expectedError); + const actualRequest = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopReplica as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes stopReplica with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStopReplicaRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.stopReplica(request), expectedError); + }); + }); + + describe('truncateLog', () => { + it('invokes truncateLog without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.truncateLog = stubSimpleCall(expectedResponse); + const [response] = await client.truncateLog(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes truncateLog without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.truncateLog = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.truncateLog( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes truncateLog with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.truncateLog = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.truncateLog(request), expectedError); + const actualRequest = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.truncateLog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes truncateLog with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesTruncateLogRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.truncateLog(request), expectedError); + }); + }); + + describe('update', () => { + it('invokes update without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.update = stubSimpleCall(expectedResponse); + const [response] = await client.update(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes update without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.update = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.update( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes update with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.update(request), expectedError); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes update with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.update(request), expectedError); + }); + }); + + describe('createEphemeral', () => { + it('invokes createEphemeral without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCert(), + ); + client.innerApiCalls.createEphemeral = stubSimpleCall(expectedResponse); + const [response] = await client.createEphemeral(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createEphemeral without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCert(), + ); + client.innerApiCalls.createEphemeral = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createEphemeral( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISslCert | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createEphemeral with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createEphemeral = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.createEphemeral(request), expectedError); + const actualRequest = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEphemeral as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createEphemeral with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesCreateEphemeralCertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.createEphemeral(request), expectedError); + }); + }); + + describe('rescheduleMaintenance', () => { + it('invokes rescheduleMaintenance without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rescheduleMaintenance = + stubSimpleCall(expectedResponse); + const [response] = await client.rescheduleMaintenance(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rescheduleMaintenance without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.rescheduleMaintenance = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rescheduleMaintenance( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rescheduleMaintenance with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rescheduleMaintenance = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.rescheduleMaintenance(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.rescheduleMaintenance as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rescheduleMaintenance with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesRescheduleMaintenanceRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.rescheduleMaintenance(request), + expectedError, + ); + }); + }); + + describe('verifyExternalSyncSettings', () => { + it('invokes verifyExternalSyncSettings without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsResponse(), + ); + client.innerApiCalls.verifyExternalSyncSettings = + stubSimpleCall(expectedResponse); + const [response] = await client.verifyExternalSyncSettings(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes verifyExternalSyncSettings without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsResponse(), + ); + client.innerApiCalls.verifyExternalSyncSettings = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.verifyExternalSyncSettings( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISqlInstancesVerifyExternalSyncSettingsResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes verifyExternalSyncSettings with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.verifyExternalSyncSettings = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.verifyExternalSyncSettings(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.verifyExternalSyncSettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes verifyExternalSyncSettings with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesVerifyExternalSyncSettingsRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.verifyExternalSyncSettings(request), + expectedError, + ); + }); + }); + + describe('startExternalSync', () => { + it('invokes startExternalSync without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.startExternalSync = stubSimpleCall(expectedResponse); + const [response] = await client.startExternalSync(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes startExternalSync without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.startExternalSync = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.startExternalSync( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes startExternalSync with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.startExternalSync = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.startExternalSync(request), expectedError); + const actualRequest = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExternalSync as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes startExternalSync with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesStartExternalSyncRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.startExternalSync(request), expectedError); + }); + }); + + describe('performDiskShrink', () => { + it('invokes performDiskShrink without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.performDiskShrink = stubSimpleCall(expectedResponse); + const [response] = await client.performDiskShrink(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes performDiskShrink without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.performDiskShrink = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.performDiskShrink( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes performDiskShrink with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.performDiskShrink = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.performDiskShrink(request), expectedError); + const actualRequest = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.performDiskShrink as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes performDiskShrink with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPerformDiskShrinkRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.performDiskShrink(request), expectedError); + }); + }); + + describe('getDiskShrinkConfig', () => { + it('invokes getDiskShrinkConfig without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigResponse(), + ); + client.innerApiCalls.getDiskShrinkConfig = + stubSimpleCall(expectedResponse); + const [response] = await client.getDiskShrinkConfig(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getDiskShrinkConfig without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigResponse(), + ); + client.innerApiCalls.getDiskShrinkConfig = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getDiskShrinkConfig( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetDiskShrinkConfigResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getDiskShrinkConfig with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getDiskShrinkConfig = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.getDiskShrinkConfig(request), expectedError); + const actualRequest = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDiskShrinkConfig as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getDiskShrinkConfig with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetDiskShrinkConfigRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.getDiskShrinkConfig(request), expectedError); + }); + }); + + describe('resetReplicaSize', () => { + it('invokes resetReplicaSize without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.resetReplicaSize = stubSimpleCall(expectedResponse); + const [response] = await client.resetReplicaSize(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetReplicaSize without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.resetReplicaSize = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.resetReplicaSize( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetReplicaSize with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.resetReplicaSize = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.resetReplicaSize(request), expectedError); + const actualRequest = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetReplicaSize as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetReplicaSize with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesResetReplicaSizeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.resetReplicaSize(request), expectedError); + }); + }); + + describe('getLatestRecoveryTime', () => { + it('invokes getLatestRecoveryTime without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeResponse(), + ); + client.innerApiCalls.getLatestRecoveryTime = + stubSimpleCall(expectedResponse); + const [response] = await client.getLatestRecoveryTime(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getLatestRecoveryTime without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeResponse(), + ); + client.innerApiCalls.getLatestRecoveryTime = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getLatestRecoveryTime( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISqlInstancesGetLatestRecoveryTimeResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getLatestRecoveryTime with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getLatestRecoveryTime = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.getLatestRecoveryTime(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getLatestRecoveryTime as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getLatestRecoveryTime with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesGetLatestRecoveryTimeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.getLatestRecoveryTime(request), + expectedError, + ); + }); + }); + + describe('executeSql', () => { + it('invokes executeSql without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlResponse(), + ); + client.innerApiCalls.executeSql = stubSimpleCall(expectedResponse); + const [response] = await client.executeSql(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes executeSql without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlResponse(), + ); + client.innerApiCalls.executeSql = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.executeSql( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISqlInstancesExecuteSqlResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes executeSql with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.executeSql = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.executeSql(request), expectedError); + const actualRequest = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.executeSql as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes executeSql with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesExecuteSqlRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.executeSql(request), expectedError); + }); + }); + + describe('acquireSsrsLease', () => { + it('invokes acquireSsrsLease without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseResponse(), + ); + client.innerApiCalls.acquireSsrsLease = stubSimpleCall(expectedResponse); + const [response] = await client.acquireSsrsLease(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes acquireSsrsLease without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseResponse(), + ); + client.innerApiCalls.acquireSsrsLease = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.acquireSsrsLease( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISqlInstancesAcquireSsrsLeaseResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes acquireSsrsLease with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.acquireSsrsLease = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.acquireSsrsLease(request), expectedError); + const actualRequest = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.acquireSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes acquireSsrsLease with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesAcquireSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.acquireSsrsLease(request), expectedError); + }); + }); + + describe('releaseSsrsLease', () => { + it('invokes releaseSsrsLease without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseResponse(), + ); + client.innerApiCalls.releaseSsrsLease = stubSimpleCall(expectedResponse); + const [response] = await client.releaseSsrsLease(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes releaseSsrsLease without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseResponse(), + ); + client.innerApiCalls.releaseSsrsLease = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.releaseSsrsLease( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISqlInstancesReleaseSsrsLeaseResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes releaseSsrsLease with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.releaseSsrsLease = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.releaseSsrsLease(request), expectedError); + const actualRequest = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.releaseSsrsLease as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes releaseSsrsLease with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesReleaseSsrsLeaseRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.releaseSsrsLease(request), expectedError); + }); + }); + + describe('preCheckMajorVersionUpgrade', () => { + it('invokes preCheckMajorVersionUpgrade without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.preCheckMajorVersionUpgrade = + stubSimpleCall(expectedResponse); + const [response] = await client.preCheckMajorVersionUpgrade(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes preCheckMajorVersionUpgrade without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.preCheckMajorVersionUpgrade = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.preCheckMajorVersionUpgrade( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes preCheckMajorVersionUpgrade with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.preCheckMajorVersionUpgrade = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects( + client.preCheckMajorVersionUpgrade(request), + expectedError, + ); + const actualRequest = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.preCheckMajorVersionUpgrade as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes preCheckMajorVersionUpgrade with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPreCheckMajorVersionUpgradeRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects( + client.preCheckMajorVersionUpgrade(request), + expectedError, + ); + }); + }); + + describe('pointInTimeRestore', () => { + it('invokes pointInTimeRestore without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.pointInTimeRestore = + stubSimpleCall(expectedResponse); + const [response] = await client.pointInTimeRestore(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes pointInTimeRestore without error using callback', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.pointInTimeRestore = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.pointInTimeRestore( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes pointInTimeRestore with error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.pointInTimeRestore = stubSimpleCall( + undefined, + expectedError, + ); + await assert.rejects(client.pointInTimeRestore(request), expectedError); + const actualRequest = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.pointInTimeRestore as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes pointInTimeRestore with closed client', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlInstancesPointInTimeRestoreRequest', + ['parent'], + ); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.pointInTimeRestore(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + 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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + 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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); + + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = + new sqlinstancesserviceModule.v1beta4.SqlInstancesServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_operations_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_operations_service_v1.ts index 5903ce5f34ca..56b5f9690f63 100644 --- a/packages/google-cloud-sql/test/gapic_sql_operations_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_operations_service_v1.ts @@ -19,771 +19,961 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqloperationsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlOperationsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient(); - 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 = sqloperationsserviceModule.v1.SqlOperationsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqloperationsserviceModule.v1.SqlOperationsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1.SqlOperationsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + it('has universeDomain', () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient(); + 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 = + sqloperationsserviceModule.v1.SqlOperationsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqloperationsserviceModule.v1.SqlOperationsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('has port', () => { - const port = sqloperationsserviceModule.v1.SqlOperationsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient(); - assert(client); + 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 sqloperationsserviceModule.v1.SqlOperationsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('should create a client with gRPC fallback', () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - fallback: true, - }); - assert(client); + 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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlOperationsServiceStub, undefined); - await client.initialize(); - assert(client.sqlOperationsServiceStub); + it('has port', () => { + const port = + sqloperationsserviceModule.v1.SqlOperationsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlOperationsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlOperationsServiceStub, undefined); + await client.initialize(); + assert(client.sqlOperationsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlOperationsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlOperationsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlOperationsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - 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); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + 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()); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + 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('get', () => { + it('invokes get without error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.OperationsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.OperationsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperationsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with closed client', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); + it('invokes get without error using callback', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('cancel', () => { - it('invokes cancel without error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancel = stubSimpleCall(expectedResponse); - const [response] = await client.cancel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancel without error using callback', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cancel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancel with error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.cancel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.cancel(request), expectedError); - const actualRequest = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancel with closed client', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.cancel(request), expectedError); + it('invokes get with closed client', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - 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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - 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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - 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)); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.OperationsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + + it('invokes list without error using callback', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.OperationsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperationsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('invokes list with closed client', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + + describe('cancel', () => { + it('invokes cancel without error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty(), + ); + client.innerApiCalls.cancel = stubSimpleCall(expectedResponse); + const [response] = await client.cancel(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.cancel as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancel as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes cancel without error using callback', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty(), + ); + client.innerApiCalls.cancel = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.cancel( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.cancel as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancel as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes cancel with error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.cancel = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.cancel(request), expectedError); + const actualRequest = (client.innerApiCalls.cancel as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancel as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes cancel with closed client', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.cancel(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + 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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + 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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqloperationsserviceModule.v1.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_operations_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_operations_service_v1beta4.ts index 5fca4c39fd70..28cc64f3a40a 100644 --- a/packages/google-cloud-sql/test/gapic_sql_operations_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_operations_service_v1beta4.ts @@ -19,801 +19,1002 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqloperationsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlOperationsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); - 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 = sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); + it('has universeDomain', () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); - it('has port', () => { - const port = sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient + .servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient + .apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); - assert(client); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - fallback: true, - }); - assert(client); + 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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlOperationsServiceStub, undefined); - await client.initialize(); - assert(client.sqlOperationsServiceStub); - }); + it('has port', () => { + const port = + sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('has close method for the initialized client', done => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlOperationsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('should create a client with no option', () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the non-initialized client', done => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlOperationsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlOperationsServiceStub, undefined); + await client.initialize(); + assert(client.sqlOperationsServiceStub); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - 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 close method for the initialized client', (done) => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlOperationsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - 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); + it('has close method for the non-initialized client', (done) => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlOperationsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsGetRequest', ['operation']); - request.operation = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.OperationsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.OperationsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperationsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with closed client', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsListRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); - }); - - describe('cancel', () => { - it('invokes cancel without error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancel = stubSimpleCall(expectedResponse); - const [response] = await client.cancel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancel without error using callback', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cancel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancel with error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&operation=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.cancel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.cancel(request), expectedError); - const actualRequest = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancel with closed client', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', ['operation']); - request.operation = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.cancel(request), expectedError); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - 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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - 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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - 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)); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + 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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + 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('get', () => { + it('invokes get without error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get without error using callback', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes get with error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes get with closed client', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsGetRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.OperationsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('invokes list without error using callback', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.OperationsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperationsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes list with error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with closed client', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + + describe('cancel', () => { + it('invokes cancel without error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty(), + ); + client.innerApiCalls.cancel = stubSimpleCall(expectedResponse); + const [response] = await client.cancel(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.cancel as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancel as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes cancel without error using callback', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty(), + ); + client.innerApiCalls.cancel = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.cancel( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.cancel as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancel as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes cancel with error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&operation=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.cancel = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.cancel(request), expectedError); + const actualRequest = (client.innerApiCalls.cancel as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.cancel as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes cancel with closed client', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlOperationsCancelRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlOperationsCancelRequest', + ['operation'], + ); + request.operation = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.cancel(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + 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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + 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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); + + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = + new sqloperationsserviceModule.v1beta4.SqlOperationsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1.ts index d3e88a5978ca..07ac5d56e9e0 100644 --- a/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1.ts @@ -19,927 +19,1140 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlsslcertsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlSslCertsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); + 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 = sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - 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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlSslCertsServiceStub, undefined); - await client.initialize(); - assert(client.sqlSslCertsServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlSslCertsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlSslCertsServiceStub, undefined); + await client.initialize(); + assert(client.sqlSslCertsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlSslCertsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlSslCertsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlSslCertsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + 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()); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + 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); + }); + }); - it('invokes delete without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('delete', () => { + it('invokes delete without error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete without error using callback', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); + it('invokes delete with error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCert() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with closed client', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); - it('invokes get without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCert() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISslCert|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('get', () => { + it('invokes get without error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCert(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get without error using callback', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCert(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISslCert | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); + it('invokes get with error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCertsInsertResponse() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get with closed client', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); - it('invokes insert without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCertsInsertResponse() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISslCertsInsertResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('insert', () => { + it('invokes insert without error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCertsInsertResponse(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert without error using callback', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCertsInsertResponse(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISslCertsInsertResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); + it('invokes insert with error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCertsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with closed client', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); - it('invokes list without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.SslCertsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ISslCertsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('list', () => { + it('invokes list without error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCertsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list without error using callback', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.SslCertsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ISslCertsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - 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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - 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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - 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)); - }); + + it('invokes list with closed client', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + 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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); - describe('Path templates', () => { + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlsslcertsserviceModule.v1.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1beta4.ts index 40109a1edb60..7b9549c8daf5 100644 --- a/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_ssl_certs_service_v1beta4.ts @@ -19,957 +19,1213 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlsslcertsserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlSslCertsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); - 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 = sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + it('has universeDomain', () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); + 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 = + sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + universeDomain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('has port', () => { - const port = sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient.port; - assert(port); - assert(typeof port === 'number'); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + universe_domain: 'example.com', }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('should create a client with no option', () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); - assert(client); + 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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('should create a client with gRPC fallback', () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - fallback: true, + 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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + universeDomain: 'configured.example.com', }); - assert(client); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlSslCertsServiceStub, undefined); - await client.initialize(); - assert(client.sqlSslCertsServiceStub); + it('has port', () => { + const port = + sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + fallback: true, }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlSslCertsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has initialize method and supports deferred initialization', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlSslCertsServiceStub, undefined); + await client.initialize(); + assert(client.sqlSslCertsServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlSslCertsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlSslCertsServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + assert.strictEqual(client.sqlSslCertsServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; + }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - 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); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + 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()); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); - }); - - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCert() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCert() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISslCert|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&sha1_fingerprint=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', ['sha1Fingerprint']); - request.sha1Fingerprint = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCertsInsertResponse() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCertsInsertResponse() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCertsListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SslCertsListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ISslCertsListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with closed client', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlSslCertsListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); - }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - 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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - 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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - 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)); - }); - }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + 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('delete', () => { + it('invokes delete without error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes delete without error using callback', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes delete with error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes delete with closed client', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsDeleteRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + describe('get', () => { + it('invokes get without error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCert(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('invokes get without error using callback', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCert(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISslCert | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&sha1_fingerprint=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes get with closed client', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsGetRequest', + ['sha1Fingerprint'], + ); + request.sha1Fingerprint = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); + + describe('insert', () => { + it('invokes insert without error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCertsInsertResponse(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert without error using callback', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCertsInsertResponse(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISslCertsInsertResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes insert with closed client', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); + + describe('list', () => { + it('invokes list without error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCertsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list without error using callback', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SslCertsListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ISslCertsListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes list with closed client', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlSslCertsListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlSslCertsListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + 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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + 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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + }); + + describe('project', async () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = + new sqlsslcertsserviceModule.v1beta4.SqlSslCertsServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1.ts index 7be02eaff388..0f48bbe07820 100644 --- a/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1.ts @@ -19,531 +19,635 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqltiersserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlTiersServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient(); + 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 = sqltiersserviceModule.v1.SqlTiersServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqltiersserviceModule.v1.SqlTiersServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqltiersserviceModule.v1.SqlTiersServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqltiersserviceModule.v1.SqlTiersServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqltiersserviceModule.v1.SqlTiersServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - 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 sqltiersserviceModule.v1.SqlTiersServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqltiersserviceModule.v1.SqlTiersServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqltiersserviceModule.v1.SqlTiersServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + 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 sqltiersserviceModule.v1.SqlTiersServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqltiersserviceModule.v1.SqlTiersServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqltiersserviceModule.v1.SqlTiersServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqltiersserviceModule.v1.SqlTiersServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlTiersServiceStub, undefined); - await client.initialize(); - assert(client.sqlTiersServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlTiersServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlTiersServiceStub, undefined); + await client.initialize(); + assert(client.sqlTiersServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlTiersServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlTiersServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlTiersServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + 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()); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.TiersListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + 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('list', () => { + it('invokes list without error', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.TiersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list without error using callback', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.TiersListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.ITiersListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list without error using callback', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.TiersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.ITiersListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with error', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with closed client', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - 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 sqltiersserviceModule.v1.SqlTiersServiceClient({ - 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 sqltiersserviceModule.v1.SqlTiersServiceClient({ - 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)); - }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.locationsClient.getLocation as SinonStub).getCall(0)); }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes getLocation with error', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqltiersserviceModule.v1.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1beta4.ts index 84dcb4615d7f..7eed7f7ae61f 100644 --- a/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_tiers_service_v1beta4.ts @@ -19,531 +19,637 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqltiersserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlTiersServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); + 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 = sqltiersserviceModule.v1beta4.SqlTiersServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqltiersserviceModule.v1beta4.SqlTiersServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqltiersserviceModule.v1beta4.SqlTiersServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqltiersserviceModule.v1beta4.SqlTiersServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - 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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqltiersserviceModule.v1beta4.SqlTiersServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqltiersserviceModule.v1beta4.SqlTiersServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlTiersServiceStub, undefined); - await client.initialize(); - assert(client.sqlTiersServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlTiersServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlTiersServiceStub, undefined); + await client.initialize(); + assert(client.sqlTiersServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlTiersServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlTiersServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlTiersServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + 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()); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.TiersListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + 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('list', () => { + it('invokes list without error', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.TiersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list without error using callback', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.TiersListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.ITiersListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list without error using callback', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.TiersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.ITiersListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with error', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlTiersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlTiersListRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with closed client', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlTiersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlTiersListRequest', + ['project'], + ); + request.project = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - 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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - 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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - 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)); - }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.locationsClient.getLocation as SinonStub).getCall(0)); }); - - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('invokes getLocation with error', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); + + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqltiersserviceModule.v1beta4.SqlTiersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); + + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); + + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_users_service_v1.ts b/packages/google-cloud-sql/test/gapic_sql_users_service_v1.ts index b5b898848b1b..ffbc06c9fd47 100644 --- a/packages/google-cloud-sql/test/gapic_sql_users_service_v1.ts +++ b/packages/google-cloud-sql/test/gapic_sql_users_service_v1.ts @@ -19,1035 +19,1267 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlusersserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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.SqlUsersServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.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 = sqlusersserviceModule.v1.SqlUsersServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + it('has universeDomain', () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlusersserviceModule.v1.SqlUsersServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.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 = + sqlusersserviceModule.v1.SqlUsersServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlusersserviceModule.v1.SqlUsersServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlusersserviceModule.v1.SqlUsersServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - 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 sqlusersserviceModule.v1.SqlUsersServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.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 sqlusersserviceModule.v1.SqlUsersServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + 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 sqlusersserviceModule.v1.SqlUsersServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - it('has port', () => { - const port = sqlusersserviceModule.v1.SqlUsersServiceClient.port; - assert(port); - assert(typeof port === 'number'); + 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 sqlusersserviceModule.v1.SqlUsersServiceClient({ + universeDomain: 'configured.example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('should create a client with no option', () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient(); - assert(client); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlusersserviceModule.v1.SqlUsersServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - fallback: true, - }); - assert(client); - }); + it('has port', () => { + const port = sqlusersserviceModule.v1.SqlUsersServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlUsersServiceStub, undefined); - await client.initialize(); - assert(client.sqlUsersServiceStub); - }); + it('should create a client with no option', () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient(); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlUsersServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlUsersServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlUsersServiceStub, undefined); + await client.initialize(); + assert(client.sqlUsersServiceStub); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - 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 close method for the initialized client', (done) => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlUsersServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - 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); + it('has close method for the non-initialized client', (done) => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlUsersServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + 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('invokes delete without error using callback', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + 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); + }); + }); - it('invokes delete with error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('delete', () => { + it('invokes delete without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with closed client', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); + it('invokes delete without error using callback', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&name=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.User() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get without error using callback', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&name=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.User() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with closed client', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); - it('invokes get with error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&name=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('get', () => { + it('invokes get without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&name=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.User(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with closed client', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); + it('invokes get without error using callback', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&name=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.User(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IUser | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get with error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&name=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert without error using callback', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get with closed client', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); - it('invokes insert with error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('insert', () => { + it('invokes insert without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with closed client', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); + it('invokes insert without error using callback', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.UsersListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list without error using callback', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.UsersListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IUsersListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with closed client', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); - it('invokes list with error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('list', () => { + it('invokes list without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.UsersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list without error using callback', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.UsersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IUsersListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('update', () => { - it('invokes update without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.update = stubSimpleCall(expectedResponse); - const [response] = await client.update(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update without error using callback', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1.Operation() - ); - client.innerApiCalls.update = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.update( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with closed client', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); - it('invokes update with error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.update(request), expectedError); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('update', () => { + it('invokes update without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.update = stubSimpleCall(expectedResponse); + const [response] = await client.update(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with closed client', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.update(request), expectedError); - }); + it('invokes update without error using callback', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1.Operation(), + ); + client.innerApiCalls.update = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.update( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - 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 sqlusersserviceModule.v1.SqlUsersServiceClient({ - 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 sqlusersserviceModule.v1.SqlUsersServiceClient({ - 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)); - }); + + it('invokes update with error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.update(request), expectedError); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes update with closed client', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.update(request), expectedError); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + 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), + ); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + it('invokes getLocation without error using callback', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqlusersserviceModule.v1.SqlUsersServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlusersserviceModule.v1.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/test/gapic_sql_users_service_v1beta4.ts b/packages/google-cloud-sql/test/gapic_sql_users_service_v1beta4.ts index 46449019b106..10439be8e2e5 100644 --- a/packages/google-cloud-sql/test/gapic_sql_users_service_v1beta4.ts +++ b/packages/google-cloud-sql/test/gapic_sql_users_service_v1beta4.ts @@ -19,1035 +19,1269 @@ 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 { SinonStub } from 'sinon'; +import { describe, it } from 'mocha'; import * as sqlusersserviceModule from '../src'; -import {protobuf, LocationProtos} from 'google-gax'; +import { protobuf, 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(); +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; + 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; + 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]); + 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 stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error, +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); } -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); +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('v1beta4.SqlUsersServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - }); + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + }); - it('has universeDomain', () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); + it('has universeDomain', () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); + 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 = sqlusersserviceModule.v1beta4.SqlUsersServiceClient.servicePath; - assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); + if ( + typeof process === 'object' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + sqlusersserviceModule.v1beta4.SqlUsersServiceClient.servicePath; + assert.strictEqual(servicePath, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sqlusersserviceModule.v1beta4.SqlUsersServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + sqlusersserviceModule.v1beta4.SqlUsersServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'sqladmin.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.example.com'); + }); - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - }); + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); + 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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'sqladmin.configured.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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + universeDomain: 'configured.example.com', }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'sqladmin.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } }); - - it('has port', () => { - const port = sqlusersserviceModule.v1beta4.SqlUsersServiceClient.port; - assert(port); - assert(typeof port === 'number'); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', }); + }); + }); - it('should create a client with no option', () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); - assert(client); - }); + it('has port', () => { + const port = sqlusersserviceModule.v1beta4.SqlUsersServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); - it('should create a client with gRPC fallback', () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - fallback: true, - }); - assert(client); - }); + it('should create a client with no option', () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient(); + assert(client); + }); - it('has initialize method and supports deferred initialization', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlUsersServiceStub, undefined); - await client.initialize(); - assert(client.sqlUsersServiceStub); - }); + it('should create a client with gRPC fallback', () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + fallback: true, + }); + assert(client); + }); - it('has close method for the initialized client', done => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sqlUsersServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); + it('has initialize method and supports deferred initialization', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlUsersServiceStub, undefined); + await client.initialize(); + assert(client.sqlUsersServiceStub); + }); - it('has close method for the non-initialized client', done => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sqlUsersServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); + it('has close method for the initialized client', (done) => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.initialize().catch((err) => { + throw err; + }); + assert(client.sqlUsersServiceStub); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - 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 close method for the non-initialized client', (done) => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.sqlUsersServiceStub, undefined); + client + .close() + .then(() => { + done(); + }) + .catch((err) => { + throw err; }); + }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - 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); - }); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + 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()); }); - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + 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); + }); + }); - it('invokes delete without error using callback', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('delete', () => { + it('invokes delete without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = stubSimpleCall(expectedResponse); + const [response] = await client.delete(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete without error using callback', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.delete = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.delete( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes delete with closed client', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); + it('invokes delete with error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.delete(request), expectedError); + const actualRequest = (client.innerApiCalls.delete as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.delete as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('get', () => { - it('invokes get without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&name=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.User() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes delete with closed client', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersDeleteRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersDeleteRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.delete(request), expectedError); + }); + }); - it('invokes get without error using callback', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&name=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.User() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('get', () => { + it('invokes get without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&name=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.User(), + ); + client.innerApiCalls.get = stubSimpleCall(expectedResponse); + const [response] = await client.get(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }&name=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get without error using callback', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&name=${defaultValue3 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.User(), + ); + client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.get( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IUser | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes get with closed client', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['instance']); - request.instance = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersGetRequest', ['name']); - request.name = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); + it('invokes get with error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}&name=${defaultValue3 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.get(request), expectedError); + const actualRequest = (client.innerApiCalls.get as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.get as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes get with closed client', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersGetRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['instance'], + ); + request.instance = defaultValue2; + const defaultValue3 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersGetRequest', + ['name'], + ); + request.name = defaultValue3; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.get(request), expectedError); + }); + }); - it('invokes insert without error using callback', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('insert', () => { + it('invokes insert without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = stubSimpleCall(expectedResponse); + const [response] = await client.insert(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert without error using callback', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.insert = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.insert( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes insert with closed client', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersInsertRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); + it('invokes insert with error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.insert(request), expectedError); + const actualRequest = (client.innerApiCalls.insert as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.insert as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('list', () => { - it('invokes list without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.UsersListResponse() - ); - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes insert with closed client', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersInsertRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersInsertRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.insert(request), expectedError); + }); + }); - it('invokes list without error using callback', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.UsersListResponse() - ); - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IUsersListResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('list', () => { + it('invokes list without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.UsersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCall(expectedResponse); + const [response] = await client.list(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list without error using callback', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.UsersListResponse(), + ); + client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.list( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IUsersListResponse | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes list with closed client', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersListRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersListRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.list(request), expectedError); - }); + it('invokes list with error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.list(request), expectedError); + const actualRequest = (client.innerApiCalls.list as SinonStub).getCall(0) + .args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.list as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('update', () => { - it('invokes update without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.update = stubSimpleCall(expectedResponse); - const [response] = await client.update(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes list with closed client', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersListRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersListRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.list(request), expectedError); + }); + }); - it('invokes update without error using callback', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.Operation() - ); - client.innerApiCalls.update = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.update( - request, - (err?: Error|null, result?: protos.google.cloud.sql.v1beta4.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + describe('update', () => { + it('invokes update without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.update = stubSimpleCall(expectedResponse); + const [response] = await client.update(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }&instance=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.update(request), expectedError); - const actualRequest = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.update as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); + it('invokes update without error using callback', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.Operation(), + ); + client.innerApiCalls.update = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.update( + request, + ( + err?: Error | null, + result?: protos.google.cloud.sql.v1beta4.IOperation | null, + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }, + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); - it('invokes update with closed client', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', ['instance']); - request.instance = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.update(request), expectedError); - }); + it('invokes update with error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedHeaderRequestParams = `project=${defaultValue1 ?? ''}&instance=${defaultValue2 ?? ''}`; + const expectedError = new Error('expected'); + client.innerApiCalls.update = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.update(request), expectedError); + const actualRequest = (client.innerApiCalls.update as SinonStub).getCall( + 0, + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.update as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); - describe('getLocation', () => { - it('invokes getLocation without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - 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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - 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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - 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)); - }); + + it('invokes update with closed client', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.sql.v1beta4.SqlUsersUpdateRequest(), + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['project'], + ); + request.project = defaultValue1; + const defaultValue2 = getTypeDefaultValue( + '.google.cloud.sql.v1beta4.SqlUsersUpdateRequest', + ['instance'], + ); + request.instance = defaultValue2; + const expectedError = new Error('The client has already been closed.'); + client.close().catch((err) => { + throw err; + }); + await assert.rejects(client.update(request), expectedError); }); - describe('listLocationsAsync', () => { - it('uses async iteration with listLocations without error', async () => { - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedResponse = [ - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - generateSampleMessage( - new LocationProtos.google.cloud.location.Location() - ), - ]; - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - const iterable = client.listLocationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + 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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + 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); } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new LocationProtos.google.cloud.location.ListLocationsRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedError = new Error('expected'); - client.locationsClient.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLocationsAsync(request); - await assert.rejects(async () => { - const responses: LocationProtos.google.cloud.location.ILocation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.locationsClient.descriptors.page.listLocations.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); + }, + ); + }); + 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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + 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), + ); + }); + }); + describe('listLocationsAsync', () => { + it('uses async iteration with listLocations without error', async () => { + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + generateSampleMessage( + new LocationProtos.google.cloud.location.Location(), + ), + ]; + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: LocationProtos.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.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.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 sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.ListLocationsRequest(), + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.locationsClient.descriptors.page.listLocations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: LocationProtos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request, + ); + assert( + ( + client.locationsClient.descriptors.page.listLocations + .asyncIterate as SinonStub + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams, + ), + ); + }); + }); - describe('Path templates', () => { - - describe('backup', async () => { - const fakePath = "/rendered/path/backup"; - const expectedParameters = { - project: "projectValue", - backup: "backupValue", - }; - const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.backupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.backupPathTemplate.match = - sinon.stub().returns(expectedParameters); + describe('Path templates', () => { + describe('backup', async () => { + const fakePath = '/rendered/path/backup'; + const expectedParameters = { + project: 'projectValue', + backup: 'backupValue', + }; + const client = new sqlusersserviceModule.v1beta4.SqlUsersServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + await client.initialize(); + client.pathTemplates.backupPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.backupPathTemplate.match = sinon + .stub() + .returns(expectedParameters); - it('backupPath', () => { - const result = client.backupPath("projectValue", "backupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.backupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); + it('backupPath', () => { + const result = client.backupPath('projectValue', 'backupValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.backupPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters), + ); + }); - it('matchProjectFromBackupName', () => { - const result = client.matchProjectFromBackupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); + it('matchProjectFromBackupName', () => { + const result = client.matchProjectFromBackupName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); - it('matchBackupFromBackupName', () => { - const result = client.matchBackupFromBackupName(fakePath); - assert.strictEqual(result, "backupValue"); - assert((client.pathTemplates.backupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); + it('matchBackupFromBackupName', () => { + const result = client.matchBackupFromBackupName(fakePath); + assert.strictEqual(result, 'backupValue'); + assert( + (client.pathTemplates.backupPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath), + ); + }); }); + }); }); diff --git a/packages/google-cloud-sql/webpack.config.js b/packages/google-cloud-sql/webpack.config.js index 6968d355a69c..07dc78031d41 100644 --- a/packages/google-cloud-sql/webpack.config.js +++ b/packages/google-cloud-sql/webpack.config.js @@ -1,4 +1,4 @@ -// Copyright 2026 Google LLC +// 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.