From d1c2a8fb6c95a6ecad8f510579287a3f5a33a1b6 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 26 Sep 2023 22:51:24 +0000 Subject: [PATCH 1/3] build: update typescript generator version to publish in dual format (ESM) PiperOrigin-RevId: 568643156 Source-Link: https://github.com/googleapis/googleapis/commit/f95afc063e20a0a61e13b186806ac84b49e329cf Source-Link: https://github.com/googleapis/googleapis-gen/commit/bbd2c49d2e423a8ce5cc85627402d512aeefc58b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYmJkMmM0OWQyZTQyM2E4Y2U1Y2M4NTYyNzQwMmQ1MTJhZWVmYzU4YiJ9 --- owl-bot-staging/v1/.eslintignore | 7 + owl-bot-staging/v1/.eslintrc.json | 3 + owl-bot-staging/v1/.gitignore | 14 + owl-bot-staging/v1/.jsdoc.js | 55 + owl-bot-staging/v1/.mocharc.js | 33 + owl-bot-staging/v1/.prettierrc.js | 22 + owl-bot-staging/v1/README.md | 1 + owl-bot-staging/v1/package.json | 60 + .../v1/protos/google/pubsub/v1/pubsub.proto | 1591 ++++++++++ .../v1/protos/google/pubsub/v1/schema.proto | 410 +++ owl-bot-staging/v1/src/index.ts | 29 + owl-bot-staging/v1/src/v1/index.ts | 21 + owl-bot-staging/v1/src/v1/publisher_client.ts | 1668 +++++++++++ .../v1/src/v1/publisher_client_config.json | 103 + .../v1/src/v1/publisher_proto_list.json | 4 + .../v1/src/v1/schema_service_client.ts | 1615 ++++++++++ .../src/v1/schema_service_client_config.json | 79 + .../v1/src/v1/schema_service_proto_list.json | 4 + .../v1/src/v1/subscriber_client.ts | 2204 ++++++++++++++ .../v1/src/v1/subscriber_client_config.json | 136 + .../v1/src/v1/subscriber_proto_list.json | 4 + owl-bot-staging/v1/test/gapic_publisher_v1.ts | 2013 +++++++++++++ .../v1/test/gapic_schema_service_v1.ts | 2012 +++++++++++++ .../v1/test/gapic_subscriber_v1.ts | 2633 +++++++++++++++++ owl-bot-staging/v1/tsconfig.json | 19 + owl-bot-staging/v1/webpack.config.js | 64 + 26 files changed, 14804 insertions(+) create mode 100644 owl-bot-staging/v1/.eslintignore create mode 100644 owl-bot-staging/v1/.eslintrc.json create mode 100644 owl-bot-staging/v1/.gitignore create mode 100644 owl-bot-staging/v1/.jsdoc.js create mode 100644 owl-bot-staging/v1/.mocharc.js create mode 100644 owl-bot-staging/v1/.prettierrc.js create mode 100644 owl-bot-staging/v1/README.md create mode 100644 owl-bot-staging/v1/package.json create mode 100644 owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto create mode 100644 owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto create mode 100644 owl-bot-staging/v1/src/index.ts create mode 100644 owl-bot-staging/v1/src/v1/index.ts create mode 100644 owl-bot-staging/v1/src/v1/publisher_client.ts create mode 100644 owl-bot-staging/v1/src/v1/publisher_client_config.json create mode 100644 owl-bot-staging/v1/src/v1/publisher_proto_list.json create mode 100644 owl-bot-staging/v1/src/v1/schema_service_client.ts create mode 100644 owl-bot-staging/v1/src/v1/schema_service_client_config.json create mode 100644 owl-bot-staging/v1/src/v1/schema_service_proto_list.json create mode 100644 owl-bot-staging/v1/src/v1/subscriber_client.ts create mode 100644 owl-bot-staging/v1/src/v1/subscriber_client_config.json create mode 100644 owl-bot-staging/v1/src/v1/subscriber_proto_list.json create mode 100644 owl-bot-staging/v1/test/gapic_publisher_v1.ts create mode 100644 owl-bot-staging/v1/test/gapic_schema_service_v1.ts create mode 100644 owl-bot-staging/v1/test/gapic_subscriber_v1.ts create mode 100644 owl-bot-staging/v1/tsconfig.json create mode 100644 owl-bot-staging/v1/webpack.config.js diff --git a/owl-bot-staging/v1/.eslintignore b/owl-bot-staging/v1/.eslintignore new file mode 100644 index 000000000..cfc348ec4 --- /dev/null +++ b/owl-bot-staging/v1/.eslintignore @@ -0,0 +1,7 @@ +**/node_modules +**/.coverage +build/ +docs/ +protos/ +system-test/ +samples/generated/ diff --git a/owl-bot-staging/v1/.eslintrc.json b/owl-bot-staging/v1/.eslintrc.json new file mode 100644 index 000000000..782153495 --- /dev/null +++ b/owl-bot-staging/v1/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/owl-bot-staging/v1/.gitignore b/owl-bot-staging/v1/.gitignore new file mode 100644 index 000000000..d4f03a0df --- /dev/null +++ b/owl-bot-staging/v1/.gitignore @@ -0,0 +1,14 @@ +**/*.log +**/node_modules +/.coverage +/coverage +/.nyc_output +/docs/ +/out/ +/build/ +system-test/secrets.js +system-test/*key.json +*.lock +.DS_Store +package-lock.json +__pycache__ diff --git a/owl-bot-staging/v1/.jsdoc.js b/owl-bot-staging/v1/.jsdoc.js new file mode 100644 index 000000000..6618d0cc4 --- /dev/null +++ b/owl-bot-staging/v1/.jsdoc.js @@ -0,0 +1,55 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +'use strict'; + +module.exports = { + opts: { + readme: './README.md', + package: './package.json', + template: './node_modules/jsdoc-fresh', + recurse: true, + verbose: true, + destination: './docs/' + }, + plugins: [ + 'plugins/markdown', + 'jsdoc-region-tag' + ], + source: { + excludePattern: '(^|\\/|\\\\)[._]', + include: [ + 'build/src', + 'protos' + ], + includePattern: '\\.js$' + }, + templates: { + copyright: 'Copyright 2023 Google LLC', + includeDate: false, + sourceFiles: false, + systemName: '@google-cloud/pubsub', + theme: 'lumen', + default: { + outputSourceFiles: false + } + }, + markdown: { + idInHeadings: true + } +}; diff --git a/owl-bot-staging/v1/.mocharc.js b/owl-bot-staging/v1/.mocharc.js new file mode 100644 index 000000000..1a38f257d --- /dev/null +++ b/owl-bot-staging/v1/.mocharc.js @@ -0,0 +1,33 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +const config = { + "enable-source-maps": true, + "throw-deprecation": true, + "timeout": 10000 +} +if (process.env.MOCHA_THROW_DEPRECATION === 'false') { + delete config['throw-deprecation']; +} +if (process.env.MOCHA_REPORTER) { + config.reporter = process.env.MOCHA_REPORTER; +} +if (process.env.MOCHA_REPORTER_OUTPUT) { + config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; +} +module.exports = config diff --git a/owl-bot-staging/v1/.prettierrc.js b/owl-bot-staging/v1/.prettierrc.js new file mode 100644 index 000000000..55639e70f --- /dev/null +++ b/owl-bot-staging/v1/.prettierrc.js @@ -0,0 +1,22 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/owl-bot-staging/v1/README.md b/owl-bot-staging/v1/README.md new file mode 100644 index 000000000..cdb58308f --- /dev/null +++ b/owl-bot-staging/v1/README.md @@ -0,0 +1 @@ +Pubsub: Nodejs Client diff --git a/owl-bot-staging/v1/package.json b/owl-bot-staging/v1/package.json new file mode 100644 index 000000000..06d5a3816 --- /dev/null +++ b/owl-bot-staging/v1/package.json @@ -0,0 +1,60 @@ +{ + "name": "@google-cloud/pubsub", + "version": "0.1.0", + "description": "Pubsub client for Node.js", + "repository": "googleapis/nodejs-pubsub", + "license": "Apache-2.0", + "author": "Google LLC", + "main": "build/src/index.js", + "files": [ + "build/src", + "build/protos" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google pubsub", + "pubsub", + "publisher", + "schema service", + "subscriber" + ], + "scripts": { + "clean": "gts clean", + "compile": "tsc -p . && cp -r protos build/ && minifyProtoJson", + "compile-protos": "compileProtos src", + "docs": "jsdoc -c .jsdoc.js", + "fix": "gts fix", + "lint": "gts check", + "prepare": "npm run compile-protos && npm run compile", + "system-test": "c8 mocha build/system-test", + "test": "c8 mocha build/test" + }, + "dependencies": { + "google-gax": "^4.0.4" + }, + "devDependencies": { + "@types/mocha": "^10.0.1", + "@types/node": "^18.11.18", + "@types/sinon": "^10.0.17", + "c8": "^8.0.1", + "gapic-tools": "^0.2.0", + "gts": "5.0.1", + "jsdoc": "^4.0.2", + "jsdoc-fresh": "^3.0.0", + "jsdoc-region-tag": "^3.0.0", + "mocha": "^10.2.0", + "pack-n-play": "^1.0.0-2", + "sinon": "^15.2.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=v14" + } +} diff --git a/owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto b/owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto new file mode 100644 index 000000000..4468de178 --- /dev/null +++ b/owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto @@ -0,0 +1,1591 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.pubsub.v1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; +import "google/pubsub/v1/schema.proto"; + +option cc_enable_arenas = true; +option csharp_namespace = "Google.Cloud.PubSub.V1"; +option go_package = "cloud.google.com/go/pubsub/apiv1/pubsubpb;pubsubpb"; +option java_multiple_files = true; +option java_outer_classname = "PubsubProto"; +option java_package = "com.google.pubsub.v1"; +option php_namespace = "Google\\Cloud\\PubSub\\V1"; +option ruby_package = "Google::Cloud::PubSub::V1"; + +// The service that an application uses to manipulate topics, and to send +// messages to a topic. +service Publisher { + option (google.api.default_host) = "pubsub.googleapis.com"; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform," + "https://www.googleapis.com/auth/pubsub"; + + // Creates the given topic with the given name. See the [resource name rules] + // (https://cloud.google.com/pubsub/docs/admin#resource_names). + rpc CreateTopic(Topic) returns (Topic) { + option (google.api.http) = { + put: "/v1/{name=projects/*/topics/*}" + body: "*" + }; + option (google.api.method_signature) = "name"; + } + + // Updates an existing topic. Note that certain properties of a + // topic are not modifiable. + rpc UpdateTopic(UpdateTopicRequest) returns (Topic) { + option (google.api.http) = { + patch: "/v1/{topic.name=projects/*/topics/*}" + body: "*" + }; + option (google.api.method_signature) = "topic,update_mask"; + } + + // Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic + // does not exist. + rpc Publish(PublishRequest) returns (PublishResponse) { + option (google.api.http) = { + post: "/v1/{topic=projects/*/topics/*}:publish" + body: "*" + }; + option (google.api.method_signature) = "topic,messages"; + } + + // Gets the configuration of a topic. + rpc GetTopic(GetTopicRequest) returns (Topic) { + option (google.api.http) = { + get: "/v1/{topic=projects/*/topics/*}" + }; + option (google.api.method_signature) = "topic"; + } + + // Lists matching topics. + rpc ListTopics(ListTopicsRequest) returns (ListTopicsResponse) { + option (google.api.http) = { + get: "/v1/{project=projects/*}/topics" + }; + option (google.api.method_signature) = "project"; + } + + // Lists the names of the attached subscriptions on this topic. + rpc ListTopicSubscriptions(ListTopicSubscriptionsRequest) + returns (ListTopicSubscriptionsResponse) { + option (google.api.http) = { + get: "/v1/{topic=projects/*/topics/*}/subscriptions" + }; + option (google.api.method_signature) = "topic"; + } + + // Lists the names of the snapshots on this topic. Snapshots are used in + // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + // which allow you to manage message acknowledgments in bulk. That is, you can + // set the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. + rpc ListTopicSnapshots(ListTopicSnapshotsRequest) + returns (ListTopicSnapshotsResponse) { + option (google.api.http) = { + get: "/v1/{topic=projects/*/topics/*}/snapshots" + }; + option (google.api.method_signature) = "topic"; + } + + // Deletes the topic with the given name. Returns `NOT_FOUND` if the topic + // does not exist. After a topic is deleted, a new topic may be created with + // the same name; this is an entirely new topic with none of the old + // configuration or subscriptions. Existing subscriptions to this topic are + // not deleted, but their `topic` field is set to `_deleted-topic_`. + rpc DeleteTopic(DeleteTopicRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{topic=projects/*/topics/*}" + }; + option (google.api.method_signature) = "topic"; + } + + // Detaches a subscription from this topic. All messages retained in the + // subscription are dropped. Subsequent `Pull` and `StreamingPull` requests + // will return FAILED_PRECONDITION. If the subscription is a push + // subscription, pushes to the endpoint will stop. + rpc DetachSubscription(DetachSubscriptionRequest) + returns (DetachSubscriptionResponse) { + option (google.api.http) = { + post: "/v1/{subscription=projects/*/subscriptions/*}:detach" + }; + } +} + +// A policy constraining the storage of messages published to the topic. +message MessageStoragePolicy { + // A list of IDs of GCP regions where messages that are published to the topic + // may be persisted in storage. Messages published by publishers running in + // non-allowed GCP regions (or running outside of GCP altogether) will be + // routed for storage in one of the allowed regions. An empty list means that + // no regions are allowed, and is not a valid configuration. + repeated string allowed_persistence_regions = 1; +} + +// Settings for validating messages published against a schema. +message SchemaSettings { + // Required. The name of the schema that messages published should be + // validated against. Format is `projects/{project}/schemas/{schema}`. The + // value of this field will be `_deleted-schema_` if the schema has been + // deleted. + string schema = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // The encoding of messages validated against `schema`. + Encoding encoding = 2; + + // The minimum (inclusive) revision allowed for validating messages. If empty + // or not present, allow any revision to be validated against last_revision or + // any revision created before. + string first_revision_id = 3; + + // The maximum (inclusive) revision allowed for validating messages. If empty + // or not present, allow any revision to be validated against first_revision + // or any revision created after. + string last_revision_id = 4; +} + +// A topic resource. +message Topic { + option (google.api.resource) = { + type: "pubsub.googleapis.com/Topic" + pattern: "projects/{project}/topics/{topic}" + pattern: "_deleted-topic_" + }; + + // Required. The name of the topic. It must have the format + // `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, + // and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), + // underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent + // signs (`%`). It must be between 3 and 255 characters in length, and it + // must not start with `"goog"`. + string name = 1 [(google.api.field_behavior) = REQUIRED]; + + // See [Creating and managing labels] + // (https://cloud.google.com/pubsub/docs/labels). + map labels = 2; + + // Policy constraining the set of Google Cloud Platform regions where messages + // published to the topic may be stored. If not present, then no constraints + // are in effect. + MessageStoragePolicy message_storage_policy = 3; + + // The resource name of the Cloud KMS CryptoKey to be used to protect access + // to messages published on this topic. + // + // The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`. + string kms_key_name = 5; + + // Settings for validating messages published against a schema. + SchemaSettings schema_settings = 6; + + // Reserved for future use. This field is set only in responses from the + // server; it is ignored if it is set in any requests. + bool satisfies_pzs = 7; + + // Indicates the minimum duration to retain a message after it is published to + // the topic. If this field is set, messages published to the topic in the + // last `message_retention_duration` are always available to subscribers. For + // instance, it allows any attached subscription to [seek to a + // timestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) + // that is up to `message_retention_duration` in the past. If this field is + // not set, message retention is controlled by settings on individual + // subscriptions. Cannot be more than 31 days or less than 10 minutes. + google.protobuf.Duration message_retention_duration = 8; +} + +// A message that is published by publishers and consumed by subscribers. The +// message must contain either a non-empty data field or at least one attribute. +// Note that client libraries represent this object differently +// depending on the language. See the corresponding [client library +// documentation](https://cloud.google.com/pubsub/docs/reference/libraries) for +// more information. See [quotas and limits] +// (https://cloud.google.com/pubsub/quotas) for more information about message +// limits. +message PubsubMessage { + // The message data field. If this field is empty, the message must contain + // at least one attribute. + bytes data = 1; + + // Attributes for this message. If this field is empty, the message must + // contain non-empty data. This can be used to filter messages on the + // subscription. + map attributes = 2; + + // ID of this message, assigned by the server when the message is published. + // Guaranteed to be unique within the topic. This value may be read by a + // subscriber that receives a `PubsubMessage` via a `Pull` call or a push + // delivery. It must not be populated by the publisher in a `Publish` call. + string message_id = 3; + + // The time at which the message was published, populated by the server when + // it receives the `Publish` call. It must not be populated by the + // publisher in a `Publish` call. + google.protobuf.Timestamp publish_time = 4; + + // If non-empty, identifies related messages for which publish order should be + // respected. If a `Subscription` has `enable_message_ordering` set to `true`, + // messages published with the same non-empty `ordering_key` value will be + // delivered to subscribers in the order in which they are received by the + // Pub/Sub system. All `PubsubMessage`s published in a given `PublishRequest` + // must specify the same `ordering_key` value. + // For more information, see [ordering + // messages](https://cloud.google.com/pubsub/docs/ordering). + string ordering_key = 5; +} + +// Request for the GetTopic method. +message GetTopicRequest { + // Required. The name of the topic to get. + // Format is `projects/{project}/topics/{topic}`. + string topic = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; +} + +// Request for the UpdateTopic method. +message UpdateTopicRequest { + // Required. The updated topic object. + Topic topic = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. Indicates which fields in the provided topic to update. Must be + // specified and non-empty. Note that if `update_mask` contains + // "message_storage_policy" but the `message_storage_policy` is not set in + // the `topic` provided above, then the updated value is determined by the + // policy configured at the project or organization level. + google.protobuf.FieldMask update_mask = 2 + [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the Publish method. +message PublishRequest { + // Required. The messages in the request will be published on this topic. + // Format is `projects/{project}/topics/{topic}`. + string topic = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; + + // Required. The messages to publish. + repeated PubsubMessage messages = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// Response for the `Publish` method. +message PublishResponse { + // The server-assigned ID of each published message, in the same order as + // the messages in the request. IDs are guaranteed to be unique within + // the topic. + repeated string message_ids = 1; +} + +// Request for the `ListTopics` method. +message ListTopicsRequest { + // Required. The name of the project in which to list topics. + // Format is `projects/{project-id}`. + string project = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "cloudresourcemanager.googleapis.com/Project" + } + ]; + + // Maximum number of topics to return. + int32 page_size = 2; + + // The value returned by the last `ListTopicsResponse`; indicates that this is + // a continuation of a prior `ListTopics` call, and that the system should + // return the next page of data. + string page_token = 3; +} + +// Response for the `ListTopics` method. +message ListTopicsResponse { + // The resulting topics. + repeated Topic topics = 1; + + // If not empty, indicates that there may be more topics that match the + // request; this value should be passed in a new `ListTopicsRequest`. + string next_page_token = 2; +} + +// Request for the `ListTopicSubscriptions` method. +message ListTopicSubscriptionsRequest { + // Required. The name of the topic that subscriptions are attached to. + // Format is `projects/{project}/topics/{topic}`. + string topic = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; + + // Maximum number of subscription names to return. + int32 page_size = 2; + + // The value returned by the last `ListTopicSubscriptionsResponse`; indicates + // that this is a continuation of a prior `ListTopicSubscriptions` call, and + // that the system should return the next page of data. + string page_token = 3; +} + +// Response for the `ListTopicSubscriptions` method. +message ListTopicSubscriptionsResponse { + // The names of subscriptions attached to the topic specified in the request. + repeated string subscriptions = 1 [(google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + }]; + + // If not empty, indicates that there may be more subscriptions that match + // the request; this value should be passed in a new + // `ListTopicSubscriptionsRequest` to get more subscriptions. + string next_page_token = 2; +} + +// Request for the `ListTopicSnapshots` method. +message ListTopicSnapshotsRequest { + // Required. The name of the topic that snapshots are attached to. + // Format is `projects/{project}/topics/{topic}`. + string topic = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; + + // Maximum number of snapshot names to return. + int32 page_size = 2; + + // The value returned by the last `ListTopicSnapshotsResponse`; indicates + // that this is a continuation of a prior `ListTopicSnapshots` call, and + // that the system should return the next page of data. + string page_token = 3; +} + +// Response for the `ListTopicSnapshots` method. +message ListTopicSnapshotsResponse { + // The names of the snapshots that match the request. + repeated string snapshots = 1; + + // If not empty, indicates that there may be more snapshots that match + // the request; this value should be passed in a new + // `ListTopicSnapshotsRequest` to get more snapshots. + string next_page_token = 2; +} + +// Request for the `DeleteTopic` method. +message DeleteTopicRequest { + // Required. Name of the topic to delete. + // Format is `projects/{project}/topics/{topic}`. + string topic = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; +} + +// Request for the DetachSubscription method. +message DetachSubscriptionRequest { + // Required. The subscription to detach. + // Format is `projects/{project}/subscriptions/{subscription}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; +} + +// Response for the DetachSubscription method. +// Reserved for future use. +message DetachSubscriptionResponse {} + +// The service that an application uses to manipulate subscriptions and to +// consume messages from a subscription via the `Pull` method or by +// establishing a bi-directional stream using the `StreamingPull` method. +service Subscriber { + option (google.api.default_host) = "pubsub.googleapis.com"; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform," + "https://www.googleapis.com/auth/pubsub"; + + // Creates a subscription to a given topic. See the [resource name rules] + // (https://cloud.google.com/pubsub/docs/admin#resource_names). + // If the subscription already exists, returns `ALREADY_EXISTS`. + // If the corresponding topic doesn't exist, returns `NOT_FOUND`. + // + // If the name is not provided in the request, the server will assign a random + // name for this subscription on the same project as the topic, conforming + // to the [resource name format] + // (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated + // name is populated in the returned Subscription object. Note that for REST + // API requests, you must specify a name in the request. + rpc CreateSubscription(Subscription) returns (Subscription) { + option (google.api.http) = { + put: "/v1/{name=projects/*/subscriptions/*}" + body: "*" + }; + option (google.api.method_signature) = + "name,topic,push_config,ack_deadline_seconds"; + } + + // Gets the configuration details of a subscription. + rpc GetSubscription(GetSubscriptionRequest) returns (Subscription) { + option (google.api.http) = { + get: "/v1/{subscription=projects/*/subscriptions/*}" + }; + option (google.api.method_signature) = "subscription"; + } + + // Updates an existing subscription. Note that certain properties of a + // subscription, such as its topic, are not modifiable. + rpc UpdateSubscription(UpdateSubscriptionRequest) returns (Subscription) { + option (google.api.http) = { + patch: "/v1/{subscription.name=projects/*/subscriptions/*}" + body: "*" + }; + option (google.api.method_signature) = "subscription,update_mask"; + } + + // Lists matching subscriptions. + rpc ListSubscriptions(ListSubscriptionsRequest) + returns (ListSubscriptionsResponse) { + option (google.api.http) = { + get: "/v1/{project=projects/*}/subscriptions" + }; + option (google.api.method_signature) = "project"; + } + + // Deletes an existing subscription. All messages retained in the subscription + // are immediately dropped. Calls to `Pull` after deletion will return + // `NOT_FOUND`. After a subscription is deleted, a new one may be created with + // the same name, but the new one has no association with the old + // subscription or its topic unless the same topic is specified. + rpc DeleteSubscription(DeleteSubscriptionRequest) + returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{subscription=projects/*/subscriptions/*}" + }; + option (google.api.method_signature) = "subscription"; + } + + // Modifies the ack deadline for a specific message. This method is useful + // to indicate that more time is needed to process a message by the + // subscriber, or to make the message available for redelivery if the + // processing was interrupted. Note that this does not modify the + // subscription-level `ackDeadlineSeconds` used for subsequent messages. + rpc ModifyAckDeadline(ModifyAckDeadlineRequest) + returns (google.protobuf.Empty) { + option (google.api.http) = { + post: "/v1/{subscription=projects/*/subscriptions/*}:modifyAckDeadline" + body: "*" + }; + option (google.api.method_signature) = + "subscription,ack_ids,ack_deadline_seconds"; + } + + // Acknowledges the messages associated with the `ack_ids` in the + // `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages + // from the subscription. + // + // Acknowledging a message whose ack deadline has expired may succeed, + // but such a message may be redelivered later. Acknowledging a message more + // than once will not result in an error. + rpc Acknowledge(AcknowledgeRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + post: "/v1/{subscription=projects/*/subscriptions/*}:acknowledge" + body: "*" + }; + option (google.api.method_signature) = "subscription,ack_ids"; + } + + // Pulls messages from the server. + rpc Pull(PullRequest) returns (PullResponse) { + option (google.api.http) = { + post: "/v1/{subscription=projects/*/subscriptions/*}:pull" + body: "*" + }; + option (google.api.method_signature) = + "subscription,return_immediately,max_messages"; + option (google.api.method_signature) = "subscription,max_messages"; + } + + // Establishes a stream with the server, which sends messages down to the + // client. The client streams acknowledgements and ack deadline modifications + // back to the server. The server will close the stream and return the status + // on any error. The server may close the stream with status `UNAVAILABLE` to + // reassign server-side resources, in which case, the client should + // re-establish the stream. Flow control can be achieved by configuring the + // underlying RPC channel. + rpc StreamingPull(stream StreamingPullRequest) + returns (stream StreamingPullResponse) {} + + // Modifies the `PushConfig` for a specified subscription. + // + // This may be used to change a push subscription to a pull one (signified by + // an empty `PushConfig`) or vice versa, or change the endpoint URL and other + // attributes of a push subscription. Messages will accumulate for delivery + // continuously through the call regardless of changes to the `PushConfig`. + rpc ModifyPushConfig(ModifyPushConfigRequest) + returns (google.protobuf.Empty) { + option (google.api.http) = { + post: "/v1/{subscription=projects/*/subscriptions/*}:modifyPushConfig" + body: "*" + }; + option (google.api.method_signature) = "subscription,push_config"; + } + + // Gets the configuration details of a snapshot. Snapshots are used in + // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + // which allow you to manage message acknowledgments in bulk. That is, you can + // set the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. + rpc GetSnapshot(GetSnapshotRequest) returns (Snapshot) { + option (google.api.http) = { + get: "/v1/{snapshot=projects/*/snapshots/*}" + }; + option (google.api.method_signature) = "snapshot"; + } + + // Lists the existing snapshots. Snapshots are used in [Seek]( + // https://cloud.google.com/pubsub/docs/replay-overview) operations, which + // allow you to manage message acknowledgments in bulk. That is, you can set + // the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. + rpc ListSnapshots(ListSnapshotsRequest) returns (ListSnapshotsResponse) { + option (google.api.http) = { + get: "/v1/{project=projects/*}/snapshots" + }; + option (google.api.method_signature) = "project"; + } + + // Creates a snapshot from the requested subscription. Snapshots are used in + // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + // which allow you to manage message acknowledgments in bulk. That is, you can + // set the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. + // If the snapshot already exists, returns `ALREADY_EXISTS`. + // If the requested subscription doesn't exist, returns `NOT_FOUND`. + // If the backlog in the subscription is too old -- and the resulting snapshot + // would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. + // See also the `Snapshot.expire_time` field. If the name is not provided in + // the request, the server will assign a random + // name for this snapshot on the same project as the subscription, conforming + // to the [resource name format] + // (https://cloud.google.com/pubsub/docs/admin#resource_names). The + // generated name is populated in the returned Snapshot object. Note that for + // REST API requests, you must specify a name in the request. + rpc CreateSnapshot(CreateSnapshotRequest) returns (Snapshot) { + option (google.api.http) = { + put: "/v1/{name=projects/*/snapshots/*}" + body: "*" + }; + option (google.api.method_signature) = "name,subscription"; + } + + // Updates an existing snapshot. Snapshots are used in + // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + // which allow you to manage message acknowledgments in bulk. That is, you can + // set the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. + rpc UpdateSnapshot(UpdateSnapshotRequest) returns (Snapshot) { + option (google.api.http) = { + patch: "/v1/{snapshot.name=projects/*/snapshots/*}" + body: "*" + }; + option (google.api.method_signature) = "snapshot,update_mask"; + } + + // Removes an existing snapshot. Snapshots are used in [Seek] + // (https://cloud.google.com/pubsub/docs/replay-overview) operations, which + // allow you to manage message acknowledgments in bulk. That is, you can set + // the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. + // When the snapshot is deleted, all messages retained in the snapshot + // are immediately dropped. After a snapshot is deleted, a new one may be + // created with the same name, but the new one has no association with the old + // snapshot or its subscription, unless the same subscription is specified. + rpc DeleteSnapshot(DeleteSnapshotRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{snapshot=projects/*/snapshots/*}" + }; + option (google.api.method_signature) = "snapshot"; + } + + // Seeks an existing subscription to a point in time or to a given snapshot, + // whichever is provided in the request. Snapshots are used in [Seek] + // (https://cloud.google.com/pubsub/docs/replay-overview) operations, which + // allow you to manage message acknowledgments in bulk. That is, you can set + // the acknowledgment state of messages in an existing subscription to the + // state captured by a snapshot. Note that both the subscription and the + // snapshot must be on the same topic. + rpc Seek(SeekRequest) returns (SeekResponse) { + option (google.api.http) = { + post: "/v1/{subscription=projects/*/subscriptions/*}:seek" + body: "*" + }; + } +} + +// A subscription resource. If none of `push_config`, `bigquery_config`, or +// `cloud_storage_config` is set, then the subscriber will pull and ack messages +// using API methods. At most one of these fields may be set. +message Subscription { + option (google.api.resource) = { + type: "pubsub.googleapis.com/Subscription" + pattern: "projects/{project}/subscriptions/{subscription}" + }; + + // Possible states for a subscription. + enum State { + // Default value. This value is unused. + STATE_UNSPECIFIED = 0; + + // The subscription can actively receive messages + ACTIVE = 1; + + // The subscription cannot receive messages because of an error with the + // resource to which it pushes messages. See the more detailed error state + // in the corresponding configuration. + RESOURCE_ERROR = 2; + } + + // Required. The name of the subscription. It must have the format + // `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must + // start with a letter, and contain only letters (`[A-Za-z]`), numbers + // (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), + // plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters + // in length, and it must not start with `"goog"`. + string name = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. The name of the topic from which this subscription is receiving + // messages. Format is `projects/{project}/topics/{topic}`. The value of this + // field will be `_deleted-topic_` if the topic has been deleted. + string topic = 2 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; + + // If push delivery is used with this subscription, this field is + // used to configure it. + PushConfig push_config = 4; + + // If delivery to BigQuery is used with this subscription, this field is + // used to configure it. + BigQueryConfig bigquery_config = 18; + + // If delivery to Google Cloud Storage is used with this subscription, this + // field is used to configure it. + CloudStorageConfig cloud_storage_config = 22; + + // The approximate amount of time (on a best-effort basis) Pub/Sub waits for + // the subscriber to acknowledge receipt before resending the message. In the + // interval after the message is delivered and before it is acknowledged, it + // is considered to be _outstanding_. During that time period, the + // message will not be redelivered (on a best-effort basis). + // + // For pull subscriptions, this value is used as the initial value for the ack + // deadline. To override this value for a given message, call + // `ModifyAckDeadline` with the corresponding `ack_id` if using + // non-streaming pull or send the `ack_id` in a + // `StreamingModifyAckDeadlineRequest` if using streaming pull. + // The minimum custom deadline you can specify is 10 seconds. + // The maximum custom deadline you can specify is 600 seconds (10 minutes). + // If this parameter is 0, a default value of 10 seconds is used. + // + // For push delivery, this value is also used to set the request timeout for + // the call to the push endpoint. + // + // If the subscriber never acknowledges the message, the Pub/Sub + // system will eventually redeliver the message. + int32 ack_deadline_seconds = 5; + + // Indicates whether to retain acknowledged messages. If true, then + // messages are not expunged from the subscription's backlog, even if they are + // acknowledged, until they fall out of the `message_retention_duration` + // window. This must be true if you would like to [`Seek` to a timestamp] + // (https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) in + // the past to replay previously-acknowledged messages. + bool retain_acked_messages = 7; + + // How long to retain unacknowledged messages in the subscription's backlog, + // from the moment a message is published. + // If `retain_acked_messages` is true, then this also configures the retention + // of acknowledged messages, and thus configures how far back in time a `Seek` + // can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 + // minutes. + google.protobuf.Duration message_retention_duration = 8; + + // See [Creating and managing + // labels](https://cloud.google.com/pubsub/docs/labels). + map labels = 9; + + // If true, messages published with the same `ordering_key` in `PubsubMessage` + // will be delivered to the subscribers in the order in which they + // are received by the Pub/Sub system. Otherwise, they may be delivered in + // any order. + bool enable_message_ordering = 10; + + // A policy that specifies the conditions for this subscription's expiration. + // A subscription is considered active as long as any connected subscriber is + // successfully consuming messages from the subscription or is issuing + // operations on the subscription. If `expiration_policy` is not set, a + // *default policy* with `ttl` of 31 days will be used. The minimum allowed + // value for `expiration_policy.ttl` is 1 day. If `expiration_policy` is set, + // but `expiration_policy.ttl` is not set, the subscription never expires. + ExpirationPolicy expiration_policy = 11; + + // An expression written in the Pub/Sub [filter + // language](https://cloud.google.com/pubsub/docs/filtering). If non-empty, + // then only `PubsubMessage`s whose `attributes` field matches the filter are + // delivered on this subscription. If empty, then no messages are filtered + // out. + string filter = 12; + + // A policy that specifies the conditions for dead lettering messages in + // this subscription. If dead_letter_policy is not set, dead lettering + // is disabled. + // + // The Cloud Pub/Sub service account associated with this subscriptions's + // parent project (i.e., + // service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have + // permission to Acknowledge() messages on this subscription. + DeadLetterPolicy dead_letter_policy = 13; + + // A policy that specifies how Pub/Sub retries message delivery for this + // subscription. + // + // If not set, the default retry policy is applied. This generally implies + // that messages will be retried as soon as possible for healthy subscribers. + // RetryPolicy will be triggered on NACKs or acknowledgement deadline + // exceeded events for a given message. + RetryPolicy retry_policy = 14; + + // Indicates whether the subscription is detached from its topic. Detached + // subscriptions don't receive messages from their topic and don't retain any + // backlog. `Pull` and `StreamingPull` requests will return + // FAILED_PRECONDITION. If the subscription is a push subscription, pushes to + // the endpoint will not be made. + bool detached = 15; + + // If true, Pub/Sub provides the following guarantees for the delivery of + // a message with a given value of `message_id` on this subscription: + // + // * The message sent to a subscriber is guaranteed not to be resent + // before the message's acknowledgement deadline expires. + // * An acknowledged message will not be resent to a subscriber. + // + // Note that subscribers may still receive multiple copies of a message + // when `enable_exactly_once_delivery` is true if the message was published + // multiple times by a publisher client. These copies are considered distinct + // by Pub/Sub and have distinct `message_id` values. + bool enable_exactly_once_delivery = 16; + + // Output only. Indicates the minimum duration for which a message is retained + // after it is published to the subscription's topic. If this field is set, + // messages published to the subscription's topic in the last + // `topic_message_retention_duration` are always available to subscribers. See + // the `message_retention_duration` field in `Topic`. This field is set only + // in responses from the server; it is ignored if it is set in any requests. + google.protobuf.Duration topic_message_retention_duration = 17 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. An output-only field indicating whether or not the + // subscription can receive messages. + State state = 19 [(google.api.field_behavior) = OUTPUT_ONLY]; +} + +// A policy that specifies how Cloud Pub/Sub retries message delivery. +// +// Retry delay will be exponential based on provided minimum and maximum +// backoffs. https://en.wikipedia.org/wiki/Exponential_backoff. +// +// RetryPolicy will be triggered on NACKs or acknowledgement deadline exceeded +// events for a given message. +// +// Retry Policy is implemented on a best effort basis. At times, the delay +// between consecutive deliveries may not match the configuration. That is, +// delay can be more or less than configured backoff. +message RetryPolicy { + // The minimum delay between consecutive deliveries of a given message. + // Value should be between 0 and 600 seconds. Defaults to 10 seconds. + google.protobuf.Duration minimum_backoff = 1; + + // The maximum delay between consecutive deliveries of a given message. + // Value should be between 0 and 600 seconds. Defaults to 600 seconds. + google.protobuf.Duration maximum_backoff = 2; +} + +// Dead lettering is done on a best effort basis. The same message might be +// dead lettered multiple times. +// +// If validation on any of the fields fails at subscription creation/updation, +// the create/update subscription request will fail. +message DeadLetterPolicy { + // The name of the topic to which dead letter messages should be published. + // Format is `projects/{project}/topics/{topic}`.The Cloud Pub/Sub service + // account associated with the enclosing subscription's parent project (i.e., + // service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have + // permission to Publish() to this topic. + // + // The operation will fail if the topic does not exist. + // Users should ensure that there is a subscription attached to this topic + // since messages published to a topic with no subscriptions are lost. + string dead_letter_topic = 1; + + // The maximum number of delivery attempts for any message. The value must be + // between 5 and 100. + // + // The number of delivery attempts is defined as 1 + (the sum of number of + // NACKs and number of times the acknowledgement deadline has been exceeded + // for the message). + // + // A NACK is any call to ModifyAckDeadline with a 0 deadline. Note that + // client libraries may automatically extend ack_deadlines. + // + // This field will be honored on a best effort basis. + // + // If this parameter is 0, a default value of 5 is used. + int32 max_delivery_attempts = 2; +} + +// A policy that specifies the conditions for resource expiration (i.e., +// automatic resource deletion). +message ExpirationPolicy { + // Specifies the "time-to-live" duration for an associated resource. The + // resource expires if it is not active for a period of `ttl`. The definition + // of "activity" depends on the type of the associated resource. The minimum + // and maximum allowed values for `ttl` depend on the type of the associated + // resource, as well. If `ttl` is not set, the associated resource never + // expires. + google.protobuf.Duration ttl = 1; +} + +// Configuration for a push delivery endpoint. +message PushConfig { + // Contains information needed for generating an + // [OpenID Connect + // token](https://developers.google.com/identity/protocols/OpenIDConnect). + message OidcToken { + // [Service account + // email](https://cloud.google.com/iam/docs/service-accounts) + // used for generating the OIDC token. For more information + // on setting up authentication, see + // [Push subscriptions](https://cloud.google.com/pubsub/docs/push). + string service_account_email = 1; + + // Audience to be used when generating OIDC token. The audience claim + // identifies the recipients that the JWT is intended for. The audience + // value is a single case-sensitive string. Having multiple values (array) + // for the audience field is not supported. More info about the OIDC JWT + // token audience here: https://tools.ietf.org/html/rfc7519#section-4.1.3 + // Note: if not specified, the Push endpoint URL will be used. + string audience = 2; + } + + // The payload to the push endpoint is in the form of the JSON representation + // of a PubsubMessage + // (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). + message PubsubWrapper {} + + // Sets the `data` field as the HTTP body for delivery. + message NoWrapper { + // When true, writes the Pub/Sub message metadata to + // `x-goog-pubsub-:` headers of the HTTP request. Writes the + // Pub/Sub message attributes to `:` headers of the HTTP request. + bool write_metadata = 1; + } + + // A URL locating the endpoint to which messages should be pushed. + // For example, a Webhook endpoint might use `https://example.com/push`. + string push_endpoint = 1; + + // Endpoint configuration attributes that can be used to control different + // aspects of the message delivery. + // + // The only currently supported attribute is `x-goog-version`, which you can + // use to change the format of the pushed message. This attribute + // indicates the version of the data expected by the endpoint. This + // controls the shape of the pushed message (i.e., its fields and metadata). + // + // If not present during the `CreateSubscription` call, it will default to + // the version of the Pub/Sub API used to make such call. If not present in a + // `ModifyPushConfig` call, its value will not be changed. `GetSubscription` + // calls will always return a valid version, even if the subscription was + // created without this attribute. + // + // The only supported values for the `x-goog-version` attribute are: + // + // * `v1beta1`: uses the push format defined in the v1beta1 Pub/Sub API. + // * `v1` or `v1beta2`: uses the push format defined in the v1 Pub/Sub API. + // + // For example: + // `attributes { "x-goog-version": "v1" }` + map attributes = 2; + + // An authentication method used by push endpoints to verify the source of + // push requests. This can be used with push endpoints that are private by + // default to allow requests only from the Cloud Pub/Sub system, for example. + // This field is optional and should be set only by users interested in + // authenticated push. + oneof authentication_method { + // If specified, Pub/Sub will generate and attach an OIDC JWT token as an + // `Authorization` header in the HTTP request for every pushed message. + OidcToken oidc_token = 3; + } + + // The format of the delivered message to the push endpoint is defined by + // the chosen wrapper. When unset, `PubsubWrapper` is used. + oneof wrapper { + // When set, the payload to the push endpoint is in the form of the JSON + // representation of a PubsubMessage + // (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). + PubsubWrapper pubsub_wrapper = 4; + + // When set, the payload to the push endpoint is not wrapped. + NoWrapper no_wrapper = 5; + } +} + +// Configuration for a BigQuery subscription. +message BigQueryConfig { + // Possible states for a BigQuery subscription. + enum State { + // Default value. This value is unused. + STATE_UNSPECIFIED = 0; + + // The subscription can actively send messages to BigQuery + ACTIVE = 1; + + // Cannot write to the BigQuery table because of permission denied errors. + // This can happen if + // - Pub/Sub SA has not been granted the [appropriate BigQuery IAM + // permissions](https://cloud.google.com/pubsub/docs/create-subscription#assign_bigquery_service_account) + // - bigquery.googleapis.com API is not enabled for the project + // ([instructions](https://cloud.google.com/service-usage/docs/enable-disable)) + PERMISSION_DENIED = 2; + + // Cannot write to the BigQuery table because it does not exist. + NOT_FOUND = 3; + + // Cannot write to the BigQuery table due to a schema mismatch. + SCHEMA_MISMATCH = 4; + } + + // The name of the table to which to write data, of the form + // {projectId}.{datasetId}.{tableId} + string table = 1; + + // When true, use the topic's schema as the columns to write to in BigQuery, + // if it exists. + bool use_topic_schema = 2; + + // When true, write the subscription name, message_id, publish_time, + // attributes, and ordering_key to additional columns in the table. The + // subscription name, message_id, and publish_time fields are put in their own + // columns while all other message properties (other than data) are written to + // a JSON object in the attributes column. + bool write_metadata = 3; + + // When true and use_topic_schema is true, any fields that are a part of the + // topic schema that are not part of the BigQuery table schema are dropped + // when writing to BigQuery. Otherwise, the schemas must be kept in sync and + // any messages with extra fields are not written and remain in the + // subscription's backlog. + bool drop_unknown_fields = 4; + + // Output only. An output-only field that indicates whether or not the + // subscription can receive messages. + State state = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; +} + +// Configuration for a Cloud Storage subscription. +message CloudStorageConfig { + // Configuration for writing message data in text format. + // Message payloads will be written to files as raw text, separated by a + // newline. + message TextConfig {} + + // Configuration for writing message data in Avro format. + // Message payloads and metadata will be written to files as an Avro binary. + message AvroConfig { + // When true, write the subscription name, message_id, publish_time, + // attributes, and ordering_key as additional fields in the output. The + // subscription name, message_id, and publish_time fields are put in their + // own fields while all other message properties other than data (for + // example, an ordering_key, if present) are added as entries in the + // attributes map. + bool write_metadata = 1; + } + + // Possible states for a Cloud Storage subscription. + enum State { + // Default value. This value is unused. + STATE_UNSPECIFIED = 0; + + // The subscription can actively send messages to Cloud Storage. + ACTIVE = 1; + + // Cannot write to the Cloud Storage bucket because of permission denied + // errors. + PERMISSION_DENIED = 2; + + // Cannot write to the Cloud Storage bucket because it does not exist. + NOT_FOUND = 3; + } + + // Required. User-provided name for the Cloud Storage bucket. + // The bucket must be created by the user. The bucket name must be without + // any prefix like "gs://". See the [bucket naming + // requirements] (https://cloud.google.com/storage/docs/buckets#naming). + string bucket = 1 [(google.api.field_behavior) = REQUIRED]; + + // User-provided prefix for Cloud Storage filename. See the [object naming + // requirements](https://cloud.google.com/storage/docs/objects#naming). + string filename_prefix = 2; + + // User-provided suffix for Cloud Storage filename. See the [object naming + // requirements](https://cloud.google.com/storage/docs/objects#naming). Must + // not end in "/". + string filename_suffix = 3; + + // Defaults to text format. + oneof output_format { + // If set, message data will be written to Cloud Storage in text format. + TextConfig text_config = 4; + + // If set, message data will be written to Cloud Storage in Avro format. + AvroConfig avro_config = 5; + } + + // The maximum duration that can elapse before a new Cloud Storage file is + // created. Min 1 minute, max 10 minutes, default 5 minutes. May not exceed + // the subscription's acknowledgement deadline. + google.protobuf.Duration max_duration = 6; + + // The maximum bytes that can be written to a Cloud Storage file before a new + // file is created. Min 1 KB, max 10 GiB. The max_bytes limit may be exceeded + // in cases where messages are larger than the limit. + int64 max_bytes = 7; + + // Output only. An output-only field that indicates whether or not the + // subscription can receive messages. + State state = 9 [(google.api.field_behavior) = OUTPUT_ONLY]; +} + +// A message and its corresponding acknowledgment ID. +message ReceivedMessage { + // This ID can be used to acknowledge the received message. + string ack_id = 1; + + // The message. + PubsubMessage message = 2; + + // The approximate number of times that Cloud Pub/Sub has attempted to deliver + // the associated message to a subscriber. + // + // More precisely, this is 1 + (number of NACKs) + + // (number of ack_deadline exceeds) for this message. + // + // A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline + // exceeds event is whenever a message is not acknowledged within + // ack_deadline. Note that ack_deadline is initially + // Subscription.ackDeadlineSeconds, but may get extended automatically by + // the client library. + // + // Upon the first delivery of a given message, `delivery_attempt` will have a + // value of 1. The value is calculated at best effort and is approximate. + // + // If a DeadLetterPolicy is not set on the subscription, this will be 0. + int32 delivery_attempt = 3; +} + +// Request for the GetSubscription method. +message GetSubscriptionRequest { + // Required. The name of the subscription to get. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; +} + +// Request for the UpdateSubscription method. +message UpdateSubscriptionRequest { + // Required. The updated subscription object. + Subscription subscription = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. Indicates which fields in the provided subscription to update. + // Must be specified and non-empty. + google.protobuf.FieldMask update_mask = 2 + [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the `ListSubscriptions` method. +message ListSubscriptionsRequest { + // Required. The name of the project in which to list subscriptions. + // Format is `projects/{project-id}`. + string project = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "cloudresourcemanager.googleapis.com/Project" + } + ]; + + // Maximum number of subscriptions to return. + int32 page_size = 2; + + // The value returned by the last `ListSubscriptionsResponse`; indicates that + // this is a continuation of a prior `ListSubscriptions` call, and that the + // system should return the next page of data. + string page_token = 3; +} + +// Response for the `ListSubscriptions` method. +message ListSubscriptionsResponse { + // The subscriptions that match the request. + repeated Subscription subscriptions = 1; + + // If not empty, indicates that there may be more subscriptions that match + // the request; this value should be passed in a new + // `ListSubscriptionsRequest` to get more subscriptions. + string next_page_token = 2; +} + +// Request for the DeleteSubscription method. +message DeleteSubscriptionRequest { + // Required. The subscription to delete. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; +} + +// Request for the ModifyPushConfig method. +message ModifyPushConfigRequest { + // Required. The name of the subscription. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + // Required. The push configuration for future deliveries. + // + // An empty `pushConfig` indicates that the Pub/Sub system should + // stop pushing messages from the given subscription and allow + // messages to be pulled and acknowledged - effectively pausing + // the subscription if `Pull` or `StreamingPull` is not called. + PushConfig push_config = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the `Pull` method. +message PullRequest { + // Required. The subscription from which messages should be pulled. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + // Optional. If this field set to true, the system will respond immediately + // even if it there are no messages available to return in the `Pull` + // response. Otherwise, the system may wait (for a bounded amount of time) + // until at least one message is available, rather than returning no messages. + // Warning: setting this field to `true` is discouraged because it adversely + // impacts the performance of `Pull` operations. We recommend that users do + // not set this field. + bool return_immediately = 2 + [deprecated = true, (google.api.field_behavior) = OPTIONAL]; + + // Required. The maximum number of messages to return for this request. Must + // be a positive integer. The Pub/Sub system may return fewer than the number + // specified. + int32 max_messages = 3 [(google.api.field_behavior) = REQUIRED]; +} + +// Response for the `Pull` method. +message PullResponse { + // Received Pub/Sub messages. The list will be empty if there are no more + // messages available in the backlog, or if no messages could be returned + // before the request timeout. For JSON, the response can be entirely + // empty. The Pub/Sub system may return fewer than the `maxMessages` requested + // even if there are more messages available in the backlog. + repeated ReceivedMessage received_messages = 1; +} + +// Request for the ModifyAckDeadline method. +message ModifyAckDeadlineRequest { + // Required. The name of the subscription. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + // Required. List of acknowledgment IDs. + repeated string ack_ids = 4 [(google.api.field_behavior) = REQUIRED]; + + // Required. The new ack deadline with respect to the time this request was + // sent to the Pub/Sub system. For example, if the value is 10, the new ack + // deadline will expire 10 seconds after the `ModifyAckDeadline` call was + // made. Specifying zero might immediately make the message available for + // delivery to another subscriber client. This typically results in an + // increase in the rate of message redeliveries (that is, duplicates). + // The minimum deadline you can specify is 0 seconds. + // The maximum deadline you can specify is 600 seconds (10 minutes). + int32 ack_deadline_seconds = 3 [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the Acknowledge method. +message AcknowledgeRequest { + // Required. The subscription whose message is being acknowledged. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + // Required. The acknowledgment ID for the messages being acknowledged that + // was returned by the Pub/Sub system in the `Pull` response. Must not be + // empty. + repeated string ack_ids = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the `StreamingPull` streaming RPC method. This request is used to +// establish the initial stream as well as to stream acknowledgements and ack +// deadline modifications from the client to the server. +message StreamingPullRequest { + // Required. The subscription for which to initialize the new stream. This + // must be provided in the first request on the stream, and must not be set in + // subsequent requests from client to server. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + // List of acknowledgement IDs for acknowledging previously received messages + // (received on this stream or a different stream). If an ack ID has expired, + // the corresponding message may be redelivered later. Acknowledging a message + // more than once will not result in an error. If the acknowledgement ID is + // malformed, the stream will be aborted with status `INVALID_ARGUMENT`. + repeated string ack_ids = 2; + + // The list of new ack deadlines for the IDs listed in + // `modify_deadline_ack_ids`. The size of this list must be the same as the + // size of `modify_deadline_ack_ids`. If it differs the stream will be aborted + // with `INVALID_ARGUMENT`. Each element in this list is applied to the + // element in the same position in `modify_deadline_ack_ids`. The new ack + // deadline is with respect to the time this request was sent to the Pub/Sub + // system. Must be >= 0. For example, if the value is 10, the new ack deadline + // will expire 10 seconds after this request is received. If the value is 0, + // the message is immediately made available for another streaming or + // non-streaming pull request. If the value is < 0 (an error), the stream will + // be aborted with status `INVALID_ARGUMENT`. + repeated int32 modify_deadline_seconds = 3; + + // List of acknowledgement IDs whose deadline will be modified based on the + // corresponding element in `modify_deadline_seconds`. This field can be used + // to indicate that more time is needed to process a message by the + // subscriber, or to make the message available for redelivery if the + // processing was interrupted. + repeated string modify_deadline_ack_ids = 4; + + // Required. The ack deadline to use for the stream. This must be provided in + // the first request on the stream, but it can also be updated on subsequent + // requests from client to server. The minimum deadline you can specify is 10 + // seconds. The maximum deadline you can specify is 600 seconds (10 minutes). + int32 stream_ack_deadline_seconds = 5 + [(google.api.field_behavior) = REQUIRED]; + + // A unique identifier that is used to distinguish client instances from each + // other. Only needs to be provided on the initial request. When a stream + // disconnects and reconnects for the same stream, the client_id should be set + // to the same value so that state associated with the old stream can be + // transferred to the new stream. The same client_id should not be used for + // different client instances. + string client_id = 6; + + // Flow control settings for the maximum number of outstanding messages. When + // there are `max_outstanding_messages` or more currently sent to the + // streaming pull client that have not yet been acked or nacked, the server + // stops sending more messages. The sending of messages resumes once the + // number of outstanding messages is less than this value. If the value is + // <= 0, there is no limit to the number of outstanding messages. This + // property can only be set on the initial StreamingPullRequest. If it is set + // on a subsequent request, the stream will be aborted with status + // `INVALID_ARGUMENT`. + int64 max_outstanding_messages = 7; + + // Flow control settings for the maximum number of outstanding bytes. When + // there are `max_outstanding_bytes` or more worth of messages currently sent + // to the streaming pull client that have not yet been acked or nacked, the + // server will stop sending more messages. The sending of messages resumes + // once the number of outstanding bytes is less than this value. If the value + // is <= 0, there is no limit to the number of outstanding bytes. This + // property can only be set on the initial StreamingPullRequest. If it is set + // on a subsequent request, the stream will be aborted with status + // `INVALID_ARGUMENT`. + int64 max_outstanding_bytes = 8; +} + +// Response for the `StreamingPull` method. This response is used to stream +// messages from the server to the client. +message StreamingPullResponse { + // Acknowledgement IDs sent in one or more previous requests to acknowledge a + // previously received message. + message AcknowledgeConfirmation { + // Successfully processed acknowledgement IDs. + repeated string ack_ids = 1; + + // List of acknowledgement IDs that were malformed or whose acknowledgement + // deadline has expired. + repeated string invalid_ack_ids = 2; + + // List of acknowledgement IDs that were out of order. + repeated string unordered_ack_ids = 3; + + // List of acknowledgement IDs that failed processing with temporary issues. + repeated string temporary_failed_ack_ids = 4; + } + + // Acknowledgement IDs sent in one or more previous requests to modify the + // deadline for a specific message. + message ModifyAckDeadlineConfirmation { + // Successfully processed acknowledgement IDs. + repeated string ack_ids = 1; + + // List of acknowledgement IDs that were malformed or whose acknowledgement + // deadline has expired. + repeated string invalid_ack_ids = 2; + + // List of acknowledgement IDs that failed processing with temporary issues. + repeated string temporary_failed_ack_ids = 3; + } + + // Subscription properties sent as part of the response. + message SubscriptionProperties { + // True iff exactly once delivery is enabled for this subscription. + bool exactly_once_delivery_enabled = 1; + + // True iff message ordering is enabled for this subscription. + bool message_ordering_enabled = 2; + } + + // Received Pub/Sub messages. This will not be empty. + repeated ReceivedMessage received_messages = 1; + + // This field will only be set if `enable_exactly_once_delivery` is set to + // `true`. + AcknowledgeConfirmation acknowledge_confirmation = 5; + + // This field will only be set if `enable_exactly_once_delivery` is set to + // `true`. + ModifyAckDeadlineConfirmation modify_ack_deadline_confirmation = 3; + + // Properties associated with this subscription. + SubscriptionProperties subscription_properties = 4; +} + +// Request for the `CreateSnapshot` method. +message CreateSnapshotRequest { + // Required. User-provided name for this snapshot. If the name is not provided + // in the request, the server will assign a random name for this snapshot on + // the same project as the subscription. Note that for REST API requests, you + // must specify a name. See the [resource name + // rules](https://cloud.google.com/pubsub/docs/admin#resource_names). Format + // is `projects/{project}/snapshots/{snap}`. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Snapshot" } + ]; + + // Required. The subscription whose backlog the snapshot retains. + // Specifically, the created snapshot is guaranteed to retain: + // (a) The existing backlog on the subscription. More precisely, this is + // defined as the messages in the subscription's backlog that are + // unacknowledged upon the successful completion of the + // `CreateSnapshot` request; as well as: + // (b) Any messages published to the subscription's topic following the + // successful completion of the CreateSnapshot request. + // Format is `projects/{project}/subscriptions/{sub}`. + string subscription = 2 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + // See [Creating and managing + // labels](https://cloud.google.com/pubsub/docs/labels). + map labels = 3; +} + +// Request for the UpdateSnapshot method. +message UpdateSnapshotRequest { + // Required. The updated snapshot object. + Snapshot snapshot = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. Indicates which fields in the provided snapshot to update. + // Must be specified and non-empty. + google.protobuf.FieldMask update_mask = 2 + [(google.api.field_behavior) = REQUIRED]; +} + +// A snapshot resource. Snapshots are used in +// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) +// operations, which allow you to manage message acknowledgments in bulk. That +// is, you can set the acknowledgment state of messages in an existing +// subscription to the state captured by a snapshot. +message Snapshot { + option (google.api.resource) = { + type: "pubsub.googleapis.com/Snapshot" + pattern: "projects/{project}/snapshots/{snapshot}" + }; + + // The name of the snapshot. + string name = 1; + + // The name of the topic from which this snapshot is retaining messages. + string topic = 2 [ + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } + ]; + + // The snapshot is guaranteed to exist up until this time. + // A newly-created snapshot expires no later than 7 days from the time of its + // creation. Its exact lifetime is determined at creation by the existing + // backlog in the source subscription. Specifically, the lifetime of the + // snapshot is `7 days - (age of oldest unacked message in the subscription)`. + // For example, consider a subscription whose oldest unacked message is 3 days + // old. If a snapshot is created from this subscription, the snapshot -- which + // will always capture this 3-day-old backlog as long as the snapshot + // exists -- will expire in 4 days. The service will refuse to create a + // snapshot that would expire in less than 1 hour after creation. + google.protobuf.Timestamp expire_time = 3; + + // See [Creating and managing labels] + // (https://cloud.google.com/pubsub/docs/labels). + map labels = 4; +} + +// Request for the GetSnapshot method. +message GetSnapshotRequest { + // Required. The name of the snapshot to get. + // Format is `projects/{project}/snapshots/{snap}`. + string snapshot = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Snapshot" } + ]; +} + +// Request for the `ListSnapshots` method. +message ListSnapshotsRequest { + // Required. The name of the project in which to list snapshots. + // Format is `projects/{project-id}`. + string project = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "cloudresourcemanager.googleapis.com/Project" + } + ]; + + // Maximum number of snapshots to return. + int32 page_size = 2; + + // The value returned by the last `ListSnapshotsResponse`; indicates that this + // is a continuation of a prior `ListSnapshots` call, and that the system + // should return the next page of data. + string page_token = 3; +} + +// Response for the `ListSnapshots` method. +message ListSnapshotsResponse { + // The resulting snapshots. + repeated Snapshot snapshots = 1; + + // If not empty, indicates that there may be more snapshot that match the + // request; this value should be passed in a new `ListSnapshotsRequest`. + string next_page_token = 2; +} + +// Request for the `DeleteSnapshot` method. +message DeleteSnapshotRequest { + // Required. The name of the snapshot to delete. + // Format is `projects/{project}/snapshots/{snap}`. + string snapshot = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Snapshot" } + ]; +} + +// Request for the `Seek` method. +message SeekRequest { + // Required. The subscription to affect. + string subscription = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "pubsub.googleapis.com/Subscription" + } + ]; + + oneof target { + // The time to seek to. + // Messages retained in the subscription that were published before this + // time are marked as acknowledged, and messages retained in the + // subscription that were published after this time are marked as + // unacknowledged. Note that this operation affects only those messages + // retained in the subscription (configured by the combination of + // `message_retention_duration` and `retain_acked_messages`). For example, + // if `time` corresponds to a point before the message retention + // window (or to a point before the system's notion of the subscription + // creation time), only retained messages will be marked as unacknowledged, + // and already-expunged messages will not be restored. + google.protobuf.Timestamp time = 2; + + // The snapshot to seek to. The snapshot's topic must be the same as that of + // the provided subscription. + // Format is `projects/{project}/snapshots/{snap}`. + string snapshot = 3 [(google.api.resource_reference) = { + type: "pubsub.googleapis.com/Snapshot" + }]; + } +} + +// Response for the `Seek` method (this response is empty). +message SeekResponse {} diff --git a/owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto b/owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto new file mode 100644 index 000000000..32aa0d75c --- /dev/null +++ b/owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto @@ -0,0 +1,410 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.pubsub.v1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; + +option cc_enable_arenas = true; +option csharp_namespace = "Google.Cloud.PubSub.V1"; +option go_package = "cloud.google.com/go/pubsub/apiv1/pubsubpb;pubsubpb"; +option java_multiple_files = true; +option java_outer_classname = "SchemaProto"; +option java_package = "com.google.pubsub.v1"; +option php_namespace = "Google\\Cloud\\PubSub\\V1"; +option ruby_package = "Google::Cloud::PubSub::V1"; + +// Service for doing schema-related operations. +service SchemaService { + option (google.api.default_host) = "pubsub.googleapis.com"; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform," + "https://www.googleapis.com/auth/pubsub"; + + // Creates a schema. + rpc CreateSchema(CreateSchemaRequest) returns (Schema) { + option (google.api.http) = { + post: "/v1/{parent=projects/*}/schemas" + body: "schema" + }; + option (google.api.method_signature) = "parent,schema,schema_id"; + } + + // Gets a schema. + rpc GetSchema(GetSchemaRequest) returns (Schema) { + option (google.api.http) = { + get: "/v1/{name=projects/*/schemas/*}" + }; + option (google.api.method_signature) = "name"; + } + + // Lists schemas in a project. + rpc ListSchemas(ListSchemasRequest) returns (ListSchemasResponse) { + option (google.api.http) = { + get: "/v1/{parent=projects/*}/schemas" + }; + option (google.api.method_signature) = "parent"; + } + + // Lists all schema revisions for the named schema. + rpc ListSchemaRevisions(ListSchemaRevisionsRequest) + returns (ListSchemaRevisionsResponse) { + option (google.api.http) = { + get: "/v1/{name=projects/*/schemas/*}:listRevisions" + }; + option (google.api.method_signature) = "name"; + } + + // Commits a new schema revision to an existing schema. + rpc CommitSchema(CommitSchemaRequest) returns (Schema) { + option (google.api.http) = { + post: "/v1/{name=projects/*/schemas/*}:commit" + body: "*" + }; + option (google.api.method_signature) = "name,schema"; + } + + // Creates a new schema revision that is a copy of the provided revision_id. + rpc RollbackSchema(RollbackSchemaRequest) returns (Schema) { + option (google.api.http) = { + post: "/v1/{name=projects/*/schemas/*}:rollback" + body: "*" + }; + option (google.api.method_signature) = "name,revision_id"; + } + + // Deletes a specific schema revision. + rpc DeleteSchemaRevision(DeleteSchemaRevisionRequest) returns (Schema) { + option (google.api.http) = { + delete: "/v1/{name=projects/*/schemas/*}:deleteRevision" + }; + option (google.api.method_signature) = "name,revision_id"; + } + + // Deletes a schema. + rpc DeleteSchema(DeleteSchemaRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/{name=projects/*/schemas/*}" + }; + option (google.api.method_signature) = "name"; + } + + // Validates a schema. + rpc ValidateSchema(ValidateSchemaRequest) returns (ValidateSchemaResponse) { + option (google.api.http) = { + post: "/v1/{parent=projects/*}/schemas:validate" + body: "*" + }; + option (google.api.method_signature) = "parent,schema"; + } + + // Validates a message against a schema. + rpc ValidateMessage(ValidateMessageRequest) + returns (ValidateMessageResponse) { + option (google.api.http) = { + post: "/v1/{parent=projects/*}/schemas:validateMessage" + body: "*" + }; + } +} + +// A schema resource. +message Schema { + option (google.api.resource) = { + type: "pubsub.googleapis.com/Schema" + pattern: "projects/{project}/schemas/{schema}" + }; + + // Possible schema definition types. + enum Type { + // Default value. This value is unused. + TYPE_UNSPECIFIED = 0; + + // A Protocol Buffer schema definition. + PROTOCOL_BUFFER = 1; + + // An Avro schema definition. + AVRO = 2; + } + + // Required. Name of the schema. + // Format is `projects/{project}/schemas/{schema}`. + string name = 1 [(google.api.field_behavior) = REQUIRED]; + + // The type of the schema definition. + Type type = 2; + + // The definition of the schema. This should contain a string representing + // the full definition of the schema that is a valid schema definition of + // the type specified in `type`. + string definition = 3; + + // Output only. Immutable. The revision ID of the schema. + string revision_id = 4 [ + (google.api.field_behavior) = IMMUTABLE, + (google.api.field_behavior) = OUTPUT_ONLY + ]; + + // Output only. The timestamp that the revision was created. + google.protobuf.Timestamp revision_create_time = 6 + [(google.api.field_behavior) = OUTPUT_ONLY]; +} + +// View of Schema object fields to be returned by GetSchema and ListSchemas. +enum SchemaView { + // The default / unset value. + // The API will default to the BASIC view. + SCHEMA_VIEW_UNSPECIFIED = 0; + + // Include the name and type of the schema, but not the definition. + BASIC = 1; + + // Include all Schema object fields. + FULL = 2; +} + +// Request for the CreateSchema method. +message CreateSchemaRequest { + // Required. The name of the project in which to create the schema. + // Format is `projects/{project-id}`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + child_type: "pubsub.googleapis.com/Schema" + } + ]; + + // Required. The schema object to create. + // + // This schema's `name` parameter is ignored. The schema object returned + // by CreateSchema will have a `name` made using the given `parent` and + // `schema_id`. + Schema schema = 2 [(google.api.field_behavior) = REQUIRED]; + + // The ID to use for the schema, which will become the final component of + // the schema's resource name. + // + // See https://cloud.google.com/pubsub/docs/admin#resource_names for resource + // name constraints. + string schema_id = 3; +} + +// Request for the GetSchema method. +message GetSchemaRequest { + // Required. The name of the schema to get. + // Format is `projects/{project}/schemas/{schema}`. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // The set of fields to return in the response. If not set, returns a Schema + // with all fields filled out. Set to `BASIC` to omit the `definition`. + SchemaView view = 2; +} + +// Request for the `ListSchemas` method. +message ListSchemasRequest { + // Required. The name of the project in which to list schemas. + // Format is `projects/{project-id}`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "cloudresourcemanager.googleapis.com/Project" + } + ]; + + // The set of Schema fields to return in the response. If not set, returns + // Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + // retrieve all fields. + SchemaView view = 2; + + // Maximum number of schemas to return. + int32 page_size = 3; + + // The value returned by the last `ListSchemasResponse`; indicates that + // this is a continuation of a prior `ListSchemas` call, and that the + // system should return the next page of data. + string page_token = 4; +} + +// Response for the `ListSchemas` method. +message ListSchemasResponse { + // The resulting schemas. + repeated Schema schemas = 1; + + // If not empty, indicates that there may be more schemas that match the + // request; this value should be passed in a new `ListSchemasRequest`. + string next_page_token = 2; +} + +// Request for the `ListSchemaRevisions` method. +message ListSchemaRevisionsRequest { + // Required. The name of the schema to list revisions for. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // The set of Schema fields to return in the response. If not set, returns + // Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + // retrieve all fields. + SchemaView view = 2; + + // The maximum number of revisions to return per page. + int32 page_size = 3; + + // The page token, received from a previous ListSchemaRevisions call. + // Provide this to retrieve the subsequent page. + string page_token = 4; +} + +// Response for the `ListSchemaRevisions` method. +message ListSchemaRevisionsResponse { + // The revisions of the schema. + repeated Schema schemas = 1; + + // A token that can be sent as `page_token` to retrieve the next page. + // If this field is empty, there are no subsequent pages. + string next_page_token = 2; +} + +// Request for CommitSchema method. +message CommitSchemaRequest { + // Required. The name of the schema we are revising. + // Format is `projects/{project}/schemas/{schema}`. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // Required. The schema revision to commit. + Schema schema = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the `RollbackSchema` method. +message RollbackSchemaRequest { + // Required. The schema being rolled back with revision id. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // Required. The revision ID to roll back to. + // It must be a revision of the same schema. + // + // Example: c7cfa2a8 + string revision_id = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// Request for the `DeleteSchemaRevision` method. +message DeleteSchemaRevisionRequest { + // Required. The name of the schema revision to be deleted, with a revision ID + // explicitly included. + // + // Example: `projects/123/schemas/my-schema@c7cfa2a8` + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // Optional. This field is deprecated and should not be used for specifying + // the revision ID. The revision ID should be specified via the `name` + // parameter. + string revision_id = 2 + [deprecated = true, (google.api.field_behavior) = OPTIONAL]; +} + +// Request for the `DeleteSchema` method. +message DeleteSchemaRequest { + // Required. Name of the schema to delete. + // Format is `projects/{project}/schemas/{schema}`. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; +} + +// Request for the `ValidateSchema` method. +message ValidateSchemaRequest { + // Required. The name of the project in which to validate schemas. + // Format is `projects/{project-id}`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "cloudresourcemanager.googleapis.com/Project" + } + ]; + + // Required. The schema object to validate. + Schema schema = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// Response for the `ValidateSchema` method. +// Empty for now. +message ValidateSchemaResponse {} + +// Request for the `ValidateMessage` method. +message ValidateMessageRequest { + // Required. The name of the project in which to validate schemas. + // Format is `projects/{project-id}`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "cloudresourcemanager.googleapis.com/Project" + } + ]; + + oneof schema_spec { + // Name of the schema against which to validate. + // + // Format is `projects/{project}/schemas/{schema}`. + string name = 2 [ + (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } + ]; + + // Ad-hoc schema against which to validate + Schema schema = 3; + } + + // Message to validate against the provided `schema_spec`. + bytes message = 4; + + // The encoding expected for messages + Encoding encoding = 5; +} + +// Response for the `ValidateMessage` method. +// Empty for now. +message ValidateMessageResponse {} + +// Possible encoding types for messages. +enum Encoding { + // Unspecified + ENCODING_UNSPECIFIED = 0; + + // JSON encoding + JSON = 1; + + // Binary encoding, as defined by the schema type. For some schema types, + // binary encoding may not be available. + BINARY = 2; +} diff --git a/owl-bot-staging/v1/src/index.ts b/owl-bot-staging/v1/src/index.ts new file mode 100644 index 000000000..c304135e4 --- /dev/null +++ b/owl-bot-staging/v1/src/index.ts @@ -0,0 +1,29 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as v1 from './v1'; +const PublisherClient = v1.PublisherClient; +type PublisherClient = v1.PublisherClient; +const SchemaServiceClient = v1.SchemaServiceClient; +type SchemaServiceClient = v1.SchemaServiceClient; +const SubscriberClient = v1.SubscriberClient; +type SubscriberClient = v1.SubscriberClient; +export {v1, PublisherClient, SchemaServiceClient, SubscriberClient}; +export default {v1, PublisherClient, SchemaServiceClient, SubscriberClient}; +import * as protos from '../protos/protos'; +export {protos} diff --git a/owl-bot-staging/v1/src/v1/index.ts b/owl-bot-staging/v1/src/v1/index.ts new file mode 100644 index 000000000..8bcd06706 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/index.ts @@ -0,0 +1,21 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +export {PublisherClient} from './publisher_client'; +export {SchemaServiceClient} from './schema_service_client'; +export {SubscriberClient} from './subscriber_client'; diff --git a/owl-bot-staging/v1/src/v1/publisher_client.ts b/owl-bot-staging/v1/src/v1/publisher_client.ts new file mode 100644 index 000000000..abb8b5001 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/publisher_client.ts @@ -0,0 +1,1668 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import type * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos} from 'google-gax'; +import {Transform} from 'stream'; +import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); +/** + * Client JSON configuration object, loaded from + * `src/v1/publisher_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +import * as gapicConfig from './publisher_client_config.json'; +const version = require('../../../package.json').version; + +/** + * The service that an application uses to manipulate topics, and to send + * messages to a topic. + * @class + * @memberof v1 + */ +export class PublisherClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + iamClient: IamClient; + pathTemplates: {[name: string]: gax.PathTemplate}; + publisherStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of PublisherClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new PublisherClient({fallback: true}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof PublisherClient; + const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.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); + + // Request numeric enum values if REST transport is used. + opts.numericEnums = true; + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); + + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectTopicPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/topics/{topic}' + ), + schemaPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/schemas/{schema}' + ), + snapshotPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/snapshots/{snapshot}' + ), + subscriptionPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/subscriptions/{subscription}' + ), + }; + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listTopics: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'topics'), + listTopicSubscriptions: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'), + listTopicSnapshots: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots') + }; + + const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos); + // Some methods on this API support automatically batching + // requests; denote this. + + this.descriptors.batching = { + publish: new this._gaxModule.BundleDescriptor( + 'messages', + ['topic'], + 'message_ids', + this._gaxModule.GrpcClient.createByteLengthFunction( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + protoFilesRoot.lookupType('google.pubsub.v1.PubsubMessage') as any + ) + ), + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.pubsub.v1.Publisher', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.publisherStub) { + return this.publisherStub; + } + + // Put together the "service stub" for + // google.pubsub.v1.Publisher. + this.publisherStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.pubsub.v1.Publisher') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.pubsub.v1.Publisher, + 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 publisherStubMethods = + ['createTopic', 'updateTopic', 'publish', 'getTopic', 'listTopics', 'listTopicSubscriptions', 'listTopicSnapshots', 'deleteTopic', 'detachSubscription']; + for (const methodName of publisherStubMethods) { + const callPromise = this.publisherStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + this.descriptors.batching?.[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.publisherStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'pubsub.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'pubsub.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/pubsub' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- +/** + * Creates the given topic with the given name. See the [resource name rules] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the topic. It must have the format + * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, + * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), + * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent + * signs (`%`). It must be between 3 and 255 characters in length, and it + * must not start with `"goog"`. + * @param {number[]} request.labels + * See [Creating and managing labels] + * (https://cloud.google.com/pubsub/docs/labels). + * @param {google.pubsub.v1.MessageStoragePolicy} request.messageStoragePolicy + * Policy constraining the set of Google Cloud Platform regions where messages + * published to the topic may be stored. If not present, then no constraints + * are in effect. + * @param {string} request.kmsKeyName + * The resource name of the Cloud KMS CryptoKey to be used to protect access + * to messages published on this topic. + * + * The expected format is `projects/* /locations/* /keyRings/* /cryptoKeys/*`. + * @param {google.pubsub.v1.SchemaSettings} request.schemaSettings + * Settings for validating messages published against a schema. + * @param {boolean} request.satisfiesPzs + * Reserved for future use. This field is set only in responses from the + * server; it is ignored if it is set in any requests. + * @param {google.protobuf.Duration} request.messageRetentionDuration + * Indicates the minimum duration to retain a message after it is published to + * the topic. If this field is set, messages published to the topic in the + * last `message_retention_duration` are always available to subscribers. For + * instance, it allows any attached subscription to [seek to a + * timestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) + * that is up to `message_retention_duration` in the past. If this field is + * not set, message retention is controlled by settings on individual + * subscriptions. Cannot be more than 31 days or less than 10 minutes. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Topic|Topic}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + createTopic( + request?: protos.google.pubsub.v1.ITopic, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.ITopic|undefined, {}|undefined + ]>; + createTopic( + request: protos.google.pubsub.v1.ITopic, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.ITopic|null|undefined, + {}|null|undefined>): void; + createTopic( + request: protos.google.pubsub.v1.ITopic, + callback: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.ITopic|null|undefined, + {}|null|undefined>): void; + createTopic( + request?: protos.google.pubsub.v1.ITopic, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.ITopic|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.ITopic|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.ITopic|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.createTopic(request, options, callback); + } +/** + * Updates an existing topic. Note that certain properties of a + * topic are not modifiable. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.pubsub.v1.Topic} request.topic + * Required. The updated topic object. + * @param {google.protobuf.FieldMask} request.updateMask + * Required. Indicates which fields in the provided topic to update. Must be + * specified and non-empty. Note that if `update_mask` contains + * "message_storage_policy" but the `message_storage_policy` is not set in + * the `topic` provided above, then the updated value is determined by the + * policy configured at the project or organization level. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Topic|Topic}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + updateTopic( + request?: protos.google.pubsub.v1.IUpdateTopicRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IUpdateTopicRequest|undefined, {}|undefined + ]>; + updateTopic( + request: protos.google.pubsub.v1.IUpdateTopicRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, + {}|null|undefined>): void; + updateTopic( + request: protos.google.pubsub.v1.IUpdateTopicRequest, + callback: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, + {}|null|undefined>): void; + updateTopic( + request?: protos.google.pubsub.v1.IUpdateTopicRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IUpdateTopicRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'topic.name': request.topic!.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.updateTopic(request, options, callback); + } +/** + * Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic + * does not exist. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. The messages in the request will be published on this topic. + * Format is `projects/{project}/topics/{topic}`. + * @param {number[]} request.messages + * Required. The messages to publish. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.PublishResponse|PublishResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + publish( + request?: protos.google.pubsub.v1.IPublishRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.IPublishResponse, + protos.google.pubsub.v1.IPublishRequest|undefined, {}|undefined + ]>; + publish( + request: protos.google.pubsub.v1.IPublishRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.IPublishResponse, + protos.google.pubsub.v1.IPublishRequest|null|undefined, + {}|null|undefined>): void; + publish( + request: protos.google.pubsub.v1.IPublishRequest, + callback: Callback< + protos.google.pubsub.v1.IPublishResponse, + protos.google.pubsub.v1.IPublishRequest|null|undefined, + {}|null|undefined>): void; + publish( + request?: protos.google.pubsub.v1.IPublishRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.IPublishResponse, + protos.google.pubsub.v1.IPublishRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.IPublishResponse, + protos.google.pubsub.v1.IPublishRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.IPublishResponse, + protos.google.pubsub.v1.IPublishRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'topic': request.topic ?? '', + }); + this.initialize(); + return this.innerApiCalls.publish(request, options, callback); + } +/** + * Gets the configuration of a topic. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. The name of the topic to get. + * Format is `projects/{project}/topics/{topic}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Topic|Topic}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + getTopic( + request?: protos.google.pubsub.v1.IGetTopicRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IGetTopicRequest|undefined, {}|undefined + ]>; + getTopic( + request: protos.google.pubsub.v1.IGetTopicRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IGetTopicRequest|null|undefined, + {}|null|undefined>): void; + getTopic( + request: protos.google.pubsub.v1.IGetTopicRequest, + callback: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IGetTopicRequest|null|undefined, + {}|null|undefined>): void; + getTopic( + request?: protos.google.pubsub.v1.IGetTopicRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IGetTopicRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IGetTopicRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ITopic, + protos.google.pubsub.v1.IGetTopicRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'topic': request.topic ?? '', + }); + this.initialize(); + return this.innerApiCalls.getTopic(request, options, callback); + } +/** + * Deletes the topic with the given name. Returns `NOT_FOUND` if the topic + * does not exist. After a topic is deleted, a new topic may be created with + * the same name; this is an entirely new topic with none of the old + * configuration or subscriptions. Existing subscriptions to this topic are + * not deleted, but their `topic` field is set to `_deleted-topic_`. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. Name of the topic to delete. + * Format is `projects/{project}/topics/{topic}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + deleteTopic( + request?: protos.google.pubsub.v1.IDeleteTopicRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteTopicRequest|undefined, {}|undefined + ]>; + deleteTopic( + request: protos.google.pubsub.v1.IDeleteTopicRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, + {}|null|undefined>): void; + deleteTopic( + request: protos.google.pubsub.v1.IDeleteTopicRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, + {}|null|undefined>): void; + deleteTopic( + request?: protos.google.pubsub.v1.IDeleteTopicRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteTopicRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'topic': request.topic ?? '', + }); + this.initialize(); + return this.innerApiCalls.deleteTopic(request, options, callback); + } +/** + * Detaches a subscription from this topic. All messages retained in the + * subscription are dropped. Subsequent `Pull` and `StreamingPull` requests + * will return FAILED_PRECONDITION. If the subscription is a push + * subscription, pushes to the endpoint will stop. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The subscription to detach. + * Format is `projects/{project}/subscriptions/{subscription}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.DetachSubscriptionResponse|DetachSubscriptionResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + detachSubscription( + request?: protos.google.pubsub.v1.IDetachSubscriptionRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.IDetachSubscriptionResponse, + protos.google.pubsub.v1.IDetachSubscriptionRequest|undefined, {}|undefined + ]>; + detachSubscription( + request: protos.google.pubsub.v1.IDetachSubscriptionRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.IDetachSubscriptionResponse, + protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + detachSubscription( + request: protos.google.pubsub.v1.IDetachSubscriptionRequest, + callback: Callback< + protos.google.pubsub.v1.IDetachSubscriptionResponse, + protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + detachSubscription( + request?: protos.google.pubsub.v1.IDetachSubscriptionRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.IDetachSubscriptionResponse, + protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.IDetachSubscriptionResponse, + protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.IDetachSubscriptionResponse, + protos.google.pubsub.v1.IDetachSubscriptionRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.detachSubscription(request, options, callback); + } + + /** + * Lists matching topics. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Required. The name of the project in which to list topics. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of topics to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicsResponse`; indicates that this is + * a continuation of a prior `ListTopics` call, and that the system should + * return the next page of data. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Topic|Topic}. + * 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 `listTopicsAsync()` + * 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. + */ + listTopics( + request?: protos.google.pubsub.v1.IListTopicsRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ITopic[], + protos.google.pubsub.v1.IListTopicsRequest|null, + protos.google.pubsub.v1.IListTopicsResponse + ]>; + listTopics( + request: protos.google.pubsub.v1.IListTopicsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListTopicsRequest, + protos.google.pubsub.v1.IListTopicsResponse|null|undefined, + protos.google.pubsub.v1.ITopic>): void; + listTopics( + request: protos.google.pubsub.v1.IListTopicsRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListTopicsRequest, + protos.google.pubsub.v1.IListTopicsResponse|null|undefined, + protos.google.pubsub.v1.ITopic>): void; + listTopics( + request?: protos.google.pubsub.v1.IListTopicsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListTopicsRequest, + protos.google.pubsub.v1.IListTopicsResponse|null|undefined, + protos.google.pubsub.v1.ITopic>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListTopicsRequest, + protos.google.pubsub.v1.IListTopicsResponse|null|undefined, + protos.google.pubsub.v1.ITopic>): + Promise<[ + protos.google.pubsub.v1.ITopic[], + protos.google.pubsub.v1.IListTopicsRequest|null, + protos.google.pubsub.v1.IListTopicsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'project': request.project ?? '', + }); + this.initialize(); + return this.innerApiCalls.listTopics(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Required. The name of the project in which to list topics. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of topics to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicsResponse`; indicates that this is + * a continuation of a prior `ListTopics` call, and that the system should + * return the next page of data. + * @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.pubsub.v1.Topic|Topic} 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 `listTopicsAsync()` + * 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. + */ + listTopicsStream( + request?: protos.google.pubsub.v1.IListTopicsRequest, + 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({ + 'project': request.project ?? '', + }); + const defaultCallSettings = this._defaults['listTopics']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listTopics.createStream( + this.innerApiCalls.listTopics as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listTopics`, 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.project + * Required. The name of the project in which to list topics. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of topics to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicsResponse`; indicates that this is + * a continuation of a prior `ListTopics` call, and that the system should + * return the next page of data. + * @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.pubsub.v1.Topic|Topic}. 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. + */ + listTopicsAsync( + request?: protos.google.pubsub.v1.IListTopicsRequest, + 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({ + 'project': request.project ?? '', + }); + const defaultCallSettings = this._defaults['listTopics']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listTopics.asyncIterate( + this.innerApiCalls['listTopics'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + /** + * Lists the names of the attached subscriptions on this topic. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. The name of the topic that subscriptions are attached to. + * Format is `projects/{project}/topics/{topic}`. + * @param {number} request.pageSize + * Maximum number of subscription names to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicSubscriptionsResponse`; indicates + * that this is a continuation of a prior `ListTopicSubscriptions` call, and + * that the system should return the next page of data. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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 string. + * 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 `listTopicSubscriptionsAsync()` + * 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. + */ + listTopicSubscriptions( + request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + options?: CallOptions): + Promise<[ + string[], + protos.google.pubsub.v1.IListTopicSubscriptionsRequest|null, + protos.google.pubsub.v1.IListTopicSubscriptionsResponse + ]>; + listTopicSubscriptions( + request: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, + string>): void; + listTopicSubscriptions( + request: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, + string>): void; + listTopicSubscriptions( + request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, + string>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, + string>): + Promise<[ + string[], + protos.google.pubsub.v1.IListTopicSubscriptionsRequest|null, + protos.google.pubsub.v1.IListTopicSubscriptionsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'topic': request.topic ?? '', + }); + this.initialize(); + return this.innerApiCalls.listTopicSubscriptions(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. The name of the topic that subscriptions are attached to. + * Format is `projects/{project}/topics/{topic}`. + * @param {number} request.pageSize + * Maximum number of subscription names to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicSubscriptionsResponse`; indicates + * that this is a continuation of a prior `ListTopicSubscriptions` call, and + * that the system should return the next page of data. + * @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 string 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 `listTopicSubscriptionsAsync()` + * 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. + */ + listTopicSubscriptionsStream( + request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + 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({ + 'topic': request.topic ?? '', + }); + const defaultCallSettings = this._defaults['listTopicSubscriptions']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listTopicSubscriptions.createStream( + this.innerApiCalls.listTopicSubscriptions as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listTopicSubscriptions`, 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.topic + * Required. The name of the topic that subscriptions are attached to. + * Format is `projects/{project}/topics/{topic}`. + * @param {number} request.pageSize + * Maximum number of subscription names to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicSubscriptionsResponse`; indicates + * that this is a continuation of a prior `ListTopicSubscriptions` call, and + * that the system should return the next page of data. + * @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 + * string. 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. + */ + listTopicSubscriptionsAsync( + request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, + 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({ + 'topic': request.topic ?? '', + }); + const defaultCallSettings = this._defaults['listTopicSubscriptions']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listTopicSubscriptions.asyncIterate( + this.innerApiCalls['listTopicSubscriptions'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + /** + * Lists the names of the snapshots on this topic. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. The name of the topic that snapshots are attached to. + * Format is `projects/{project}/topics/{topic}`. + * @param {number} request.pageSize + * Maximum number of snapshot names to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicSnapshotsResponse`; indicates + * that this is a continuation of a prior `ListTopicSnapshots` call, and + * that the system should return the next page of data. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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 string. + * 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 `listTopicSnapshotsAsync()` + * 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. + */ + listTopicSnapshots( + request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, + options?: CallOptions): + Promise<[ + string[], + protos.google.pubsub.v1.IListTopicSnapshotsRequest|null, + protos.google.pubsub.v1.IListTopicSnapshotsResponse + ]>; + listTopicSnapshots( + request: protos.google.pubsub.v1.IListTopicSnapshotsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListTopicSnapshotsRequest, + protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, + string>): void; + listTopicSnapshots( + request: protos.google.pubsub.v1.IListTopicSnapshotsRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListTopicSnapshotsRequest, + protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, + string>): void; + listTopicSnapshots( + request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListTopicSnapshotsRequest, + protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, + string>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListTopicSnapshotsRequest, + protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, + string>): + Promise<[ + string[], + protos.google.pubsub.v1.IListTopicSnapshotsRequest|null, + protos.google.pubsub.v1.IListTopicSnapshotsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'topic': request.topic ?? '', + }); + this.initialize(); + return this.innerApiCalls.listTopicSnapshots(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.topic + * Required. The name of the topic that snapshots are attached to. + * Format is `projects/{project}/topics/{topic}`. + * @param {number} request.pageSize + * Maximum number of snapshot names to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicSnapshotsResponse`; indicates + * that this is a continuation of a prior `ListTopicSnapshots` call, and + * that the system should return the next page of data. + * @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 string 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 `listTopicSnapshotsAsync()` + * 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. + */ + listTopicSnapshotsStream( + request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, + 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({ + 'topic': request.topic ?? '', + }); + const defaultCallSettings = this._defaults['listTopicSnapshots']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listTopicSnapshots.createStream( + this.innerApiCalls.listTopicSnapshots as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listTopicSnapshots`, 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.topic + * Required. The name of the topic that snapshots are attached to. + * Format is `projects/{project}/topics/{topic}`. + * @param {number} request.pageSize + * Maximum number of snapshot names to return. + * @param {string} request.pageToken + * The value returned by the last `ListTopicSnapshotsResponse`; indicates + * that this is a continuation of a prior `ListTopicSnapshots` call, and + * that the system should return the next page of data. + * @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 + * string. 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. + */ + listTopicSnapshotsAsync( + request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, + 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({ + 'topic': request.topic ?? '', + }); + const defaultCallSettings = this._defaults['listTopicSnapshots']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listTopicSnapshots.asyncIterate( + this.innerApiCalls['listTopicSnapshots'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } +/** + * Gets the access control policy for a resource. Returns an empty policy + * if the resource exists and does not have a policy set. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {Object} [request.options] + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * + * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + getIamPolicy( + request: IamProtos.google.iam.v1.GetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.getIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + setIamPolicy( + request: IamProtos.google.iam.v1.SetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.setIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + */ + testIamPermissions( + request: IamProtos.google.iam.v1.TestIamPermissionsRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { + return this.iamClient.testIamPermissions(request, options, callback); + } + + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified project resource name string. + * + * @param {string} project + * @returns {string} Resource name string. + */ + projectPath(project:string) { + return this.pathTemplates.projectPathTemplate.render({ + project: project, + }); + } + + /** + * Parse the project from Project resource. + * + * @param {string} projectName + * A fully-qualified path representing Project resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectName(projectName: string) { + return this.pathTemplates.projectPathTemplate.match(projectName).project; + } + + /** + * Return a fully-qualified projectTopic resource name string. + * + * @param {string} project + * @param {string} topic + * @returns {string} Resource name string. + */ + projectTopicPath(project:string,topic:string) { + return this.pathTemplates.projectTopicPathTemplate.render({ + project: project, + topic: topic, + }); + } + + /** + * Parse the project from ProjectTopic resource. + * + * @param {string} projectTopicName + * A fully-qualified path representing project_topic resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectTopicName(projectTopicName: string) { + return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).project; + } + + /** + * Parse the topic from ProjectTopic resource. + * + * @param {string} projectTopicName + * A fully-qualified path representing project_topic resource. + * @returns {string} A string representing the topic. + */ + matchTopicFromProjectTopicName(projectTopicName: string) { + return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).topic; + } + + /** + * Return a fully-qualified schema resource name string. + * + * @param {string} project + * @param {string} schema + * @returns {string} Resource name string. + */ + schemaPath(project:string,schema:string) { + return this.pathTemplates.schemaPathTemplate.render({ + project: project, + schema: schema, + }); + } + + /** + * Parse the project from Schema resource. + * + * @param {string} schemaName + * A fully-qualified path representing Schema resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSchemaName(schemaName: string) { + return this.pathTemplates.schemaPathTemplate.match(schemaName).project; + } + + /** + * Parse the schema from Schema resource. + * + * @param {string} schemaName + * A fully-qualified path representing Schema resource. + * @returns {string} A string representing the schema. + */ + matchSchemaFromSchemaName(schemaName: string) { + return this.pathTemplates.schemaPathTemplate.match(schemaName).schema; + } + + /** + * Return a fully-qualified snapshot resource name string. + * + * @param {string} project + * @param {string} snapshot + * @returns {string} Resource name string. + */ + snapshotPath(project:string,snapshot:string) { + return this.pathTemplates.snapshotPathTemplate.render({ + project: project, + snapshot: snapshot, + }); + } + + /** + * Parse the project from Snapshot resource. + * + * @param {string} snapshotName + * A fully-qualified path representing Snapshot resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSnapshotName(snapshotName: string) { + return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project; + } + + /** + * Parse the snapshot from Snapshot resource. + * + * @param {string} snapshotName + * A fully-qualified path representing Snapshot resource. + * @returns {string} A string representing the snapshot. + */ + matchSnapshotFromSnapshotName(snapshotName: string) { + return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot; + } + + /** + * Return a fully-qualified subscription resource name string. + * + * @param {string} project + * @param {string} subscription + * @returns {string} Resource name string. + */ + subscriptionPath(project:string,subscription:string) { + return this.pathTemplates.subscriptionPathTemplate.render({ + project: project, + subscription: subscription, + }); + } + + /** + * Parse the project from Subscription resource. + * + * @param {string} subscriptionName + * A fully-qualified path representing Subscription resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSubscriptionName(subscriptionName: string) { + return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).project; + } + + /** + * Parse the subscription from Subscription resource. + * + * @param {string} subscriptionName + * A fully-qualified path representing Subscription resource. + * @returns {string} A string representing the subscription. + */ + matchSubscriptionFromSubscriptionName(subscriptionName: string) { + return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).subscription; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.publisherStub && !this._terminated) { + return this.publisherStub.then(stub => { + this._terminated = true; + stub.close(); + this.iamClient.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/owl-bot-staging/v1/src/v1/publisher_client_config.json b/owl-bot-staging/v1/src/v1/publisher_client_config.json new file mode 100644 index 000000000..187d70936 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/publisher_client_config.json @@ -0,0 +1,103 @@ +{ + "interfaces": { + "google.pubsub.v1.Publisher": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "unavailable": [ + "UNAVAILABLE" + ], + "cancelled_unknown_deadline_exceeded_resource_exhausted_aborted_internal_unavailable": [ + "CANCELLED", + "UNKNOWN", + "DEADLINE_EXCEEDED", + "RESOURCE_EXHAUSTED", + "ABORTED", + "INTERNAL", + "UNAVAILABLE" + ], + "unknown_aborted_unavailable": [ + "UNKNOWN", + "ABORTED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + }, + "693222d32e887d96c8faeadca469f7763ccda85a": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 4, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "CreateTopic": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "UpdateTopic": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "Publish": { + "timeout_millis": 60000, + "retry_codes_name": "cancelled_unknown_deadline_exceeded_resource_exhausted_aborted_internal_unavailable", + "retry_params_name": "693222d32e887d96c8faeadca469f7763ccda85a", + "bundling": { + "element_count_threshold": 100, + "request_byte_threshold": 1048576, + "delay_threshold_millis": 10, + "element_count_limit": 1000 + } + }, + "GetTopic": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "ListTopics": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "ListTopicSubscriptions": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "ListTopicSnapshots": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "DeleteTopic": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "DetachSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + } + } + } + } +} diff --git a/owl-bot-staging/v1/src/v1/publisher_proto_list.json b/owl-bot-staging/v1/src/v1/publisher_proto_list.json new file mode 100644 index 000000000..91011aec1 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/publisher_proto_list.json @@ -0,0 +1,4 @@ +[ + "../../protos/google/pubsub/v1/pubsub.proto", + "../../protos/google/pubsub/v1/schema.proto" +] diff --git a/owl-bot-staging/v1/src/v1/schema_service_client.ts b/owl-bot-staging/v1/src/v1/schema_service_client.ts new file mode 100644 index 000000000..b0bea8a78 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/schema_service_client.ts @@ -0,0 +1,1615 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import type * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos} from 'google-gax'; +import {Transform} from 'stream'; +import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); +/** + * Client JSON configuration object, loaded from + * `src/v1/schema_service_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +import * as gapicConfig from './schema_service_client_config.json'; +const version = require('../../../package.json').version; + +/** + * Service for doing schema-related operations. + * @class + * @memberof v1 + */ +export class SchemaServiceClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + iamClient: IamClient; + pathTemplates: {[name: string]: gax.PathTemplate}; + schemaServiceStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of SchemaServiceClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new SchemaServiceClient({fallback: true}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof SchemaServiceClient; + const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.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); + + // Request numeric enum values if REST transport is used. + opts.numericEnums = true; + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); + + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectTopicPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/topics/{topic}' + ), + schemaPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/schemas/{schema}' + ), + snapshotPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/snapshots/{snapshot}' + ), + subscriptionPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/subscriptions/{subscription}' + ), + }; + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listSchemas: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'schemas'), + listSchemaRevisions: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'schemas') + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.pubsub.v1.SchemaService', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.schemaServiceStub) { + return this.schemaServiceStub; + } + + // Put together the "service stub" for + // google.pubsub.v1.SchemaService. + this.schemaServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.pubsub.v1.SchemaService') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.pubsub.v1.SchemaService, + 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 schemaServiceStubMethods = + ['createSchema', 'getSchema', 'listSchemas', 'listSchemaRevisions', 'commitSchema', 'rollbackSchema', 'deleteSchemaRevision', 'deleteSchema', 'validateSchema', 'validateMessage']; + for (const methodName of schemaServiceStubMethods) { + const callPromise = this.schemaServiceStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.schemaServiceStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'pubsub.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'pubsub.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/pubsub' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- +/** + * Creates a schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project in which to create the schema. + * Format is `projects/{project-id}`. + * @param {google.pubsub.v1.Schema} request.schema + * Required. The schema object to create. + * + * This schema's `name` parameter is ignored. The schema object returned + * by CreateSchema will have a `name` made using the given `parent` and + * `schema_id`. + * @param {string} request.schemaId + * The ID to use for the schema, which will become the final component of + * the schema's resource name. + * + * See https://cloud.google.com/pubsub/docs/admin#resource_names for resource + * name constraints. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + createSchema( + request?: protos.google.pubsub.v1.ICreateSchemaRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICreateSchemaRequest|undefined, {}|undefined + ]>; + createSchema( + request: protos.google.pubsub.v1.ICreateSchemaRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, + {}|null|undefined>): void; + createSchema( + request: protos.google.pubsub.v1.ICreateSchemaRequest, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, + {}|null|undefined>): void; + createSchema( + request?: protos.google.pubsub.v1.ICreateSchemaRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICreateSchemaRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + this.initialize(); + return this.innerApiCalls.createSchema(request, options, callback); + } +/** + * Gets a schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the schema to get. + * Format is `projects/{project}/schemas/{schema}`. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of fields to return in the response. If not set, returns a Schema + * with all fields filled out. Set to `BASIC` to omit the `definition`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + getSchema( + request?: protos.google.pubsub.v1.IGetSchemaRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IGetSchemaRequest|undefined, {}|undefined + ]>; + getSchema( + request: protos.google.pubsub.v1.IGetSchemaRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, + {}|null|undefined>): void; + getSchema( + request: protos.google.pubsub.v1.IGetSchemaRequest, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, + {}|null|undefined>): void; + getSchema( + request?: protos.google.pubsub.v1.IGetSchemaRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IGetSchemaRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.getSchema(request, options, callback); + } +/** + * Commits a new schema revision to an existing schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the schema we are revising. + * Format is `projects/{project}/schemas/{schema}`. + * @param {google.pubsub.v1.Schema} request.schema + * Required. The schema revision to commit. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + commitSchema( + request?: protos.google.pubsub.v1.ICommitSchemaRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICommitSchemaRequest|undefined, {}|undefined + ]>; + commitSchema( + request: protos.google.pubsub.v1.ICommitSchemaRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, + {}|null|undefined>): void; + commitSchema( + request: protos.google.pubsub.v1.ICommitSchemaRequest, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, + {}|null|undefined>): void; + commitSchema( + request?: protos.google.pubsub.v1.ICommitSchemaRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.ICommitSchemaRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.commitSchema(request, options, callback); + } +/** + * Creates a new schema revision that is a copy of the provided revision_id. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The schema being rolled back with revision id. + * @param {string} request.revisionId + * Required. The revision ID to roll back to. + * It must be a revision of the same schema. + * + * Example: c7cfa2a8 + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + rollbackSchema( + request?: protos.google.pubsub.v1.IRollbackSchemaRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IRollbackSchemaRequest|undefined, {}|undefined + ]>; + rollbackSchema( + request: protos.google.pubsub.v1.IRollbackSchemaRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, + {}|null|undefined>): void; + rollbackSchema( + request: protos.google.pubsub.v1.IRollbackSchemaRequest, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, + {}|null|undefined>): void; + rollbackSchema( + request?: protos.google.pubsub.v1.IRollbackSchemaRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IRollbackSchemaRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.rollbackSchema(request, options, callback); + } +/** + * Deletes a specific schema revision. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the schema revision to be deleted, with a revision ID + * explicitly included. + * + * Example: `projects/123/schemas/my-schema@c7cfa2a8` + * @param {string} [request.revisionId] + * Optional. This field is deprecated and should not be used for specifying + * the revision ID. The revision ID should be specified via the `name` + * parameter. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + deleteSchemaRevision( + request?: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|undefined, {}|undefined + ]>; + deleteSchemaRevision( + request: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, + {}|null|undefined>): void; + deleteSchemaRevision( + request: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, + callback: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, + {}|null|undefined>): void; + deleteSchemaRevision( + request?: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISchema, + protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.deleteSchemaRevision(request, options, callback); + } +/** + * Deletes a schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Name of the schema to delete. + * Format is `projects/{project}/schemas/{schema}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + deleteSchema( + request?: protos.google.pubsub.v1.IDeleteSchemaRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSchemaRequest|undefined, {}|undefined + ]>; + deleteSchema( + request: protos.google.pubsub.v1.IDeleteSchemaRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, + {}|null|undefined>): void; + deleteSchema( + request: protos.google.pubsub.v1.IDeleteSchemaRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, + {}|null|undefined>): void; + deleteSchema( + request?: protos.google.pubsub.v1.IDeleteSchemaRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSchemaRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.deleteSchema(request, options, callback); + } +/** + * Validates a schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project in which to validate schemas. + * Format is `projects/{project-id}`. + * @param {google.pubsub.v1.Schema} request.schema + * Required. The schema object to validate. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.ValidateSchemaResponse|ValidateSchemaResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + validateSchema( + request?: protos.google.pubsub.v1.IValidateSchemaRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.IValidateSchemaResponse, + protos.google.pubsub.v1.IValidateSchemaRequest|undefined, {}|undefined + ]>; + validateSchema( + request: protos.google.pubsub.v1.IValidateSchemaRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.IValidateSchemaResponse, + protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, + {}|null|undefined>): void; + validateSchema( + request: protos.google.pubsub.v1.IValidateSchemaRequest, + callback: Callback< + protos.google.pubsub.v1.IValidateSchemaResponse, + protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, + {}|null|undefined>): void; + validateSchema( + request?: protos.google.pubsub.v1.IValidateSchemaRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.IValidateSchemaResponse, + protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.IValidateSchemaResponse, + protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.IValidateSchemaResponse, + protos.google.pubsub.v1.IValidateSchemaRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + this.initialize(); + return this.innerApiCalls.validateSchema(request, options, callback); + } +/** + * Validates a message against a schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project in which to validate schemas. + * Format is `projects/{project-id}`. + * @param {string} request.name + * Name of the schema against which to validate. + * + * Format is `projects/{project}/schemas/{schema}`. + * @param {google.pubsub.v1.Schema} request.schema + * Ad-hoc schema against which to validate + * @param {Buffer} request.message + * Message to validate against the provided `schema_spec`. + * @param {google.pubsub.v1.Encoding} request.encoding + * The encoding expected for messages + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.ValidateMessageResponse|ValidateMessageResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + validateMessage( + request?: protos.google.pubsub.v1.IValidateMessageRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.IValidateMessageResponse, + protos.google.pubsub.v1.IValidateMessageRequest|undefined, {}|undefined + ]>; + validateMessage( + request: protos.google.pubsub.v1.IValidateMessageRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.IValidateMessageResponse, + protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, + {}|null|undefined>): void; + validateMessage( + request: protos.google.pubsub.v1.IValidateMessageRequest, + callback: Callback< + protos.google.pubsub.v1.IValidateMessageResponse, + protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, + {}|null|undefined>): void; + validateMessage( + request?: protos.google.pubsub.v1.IValidateMessageRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.IValidateMessageResponse, + protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.IValidateMessageResponse, + protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.IValidateMessageResponse, + protos.google.pubsub.v1.IValidateMessageRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + this.initialize(); + return this.innerApiCalls.validateMessage(request, options, callback); + } + + /** + * Lists schemas in a project. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project in which to list schemas. + * Format is `projects/{project-id}`. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @param {number} request.pageSize + * Maximum number of schemas to return. + * @param {string} request.pageToken + * The value returned by the last `ListSchemasResponse`; indicates that + * this is a continuation of a prior `ListSchemas` call, and that the + * system should return the next page of data. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Schema|Schema}. + * 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 `listSchemasAsync()` + * 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. + */ + listSchemas( + request?: protos.google.pubsub.v1.IListSchemasRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema[], + protos.google.pubsub.v1.IListSchemasRequest|null, + protos.google.pubsub.v1.IListSchemasResponse + ]>; + listSchemas( + request: protos.google.pubsub.v1.IListSchemasRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSchemasRequest, + protos.google.pubsub.v1.IListSchemasResponse|null|undefined, + protos.google.pubsub.v1.ISchema>): void; + listSchemas( + request: protos.google.pubsub.v1.IListSchemasRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSchemasRequest, + protos.google.pubsub.v1.IListSchemasResponse|null|undefined, + protos.google.pubsub.v1.ISchema>): void; + listSchemas( + request?: protos.google.pubsub.v1.IListSchemasRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListSchemasRequest, + protos.google.pubsub.v1.IListSchemasResponse|null|undefined, + protos.google.pubsub.v1.ISchema>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListSchemasRequest, + protos.google.pubsub.v1.IListSchemasResponse|null|undefined, + protos.google.pubsub.v1.ISchema>): + Promise<[ + protos.google.pubsub.v1.ISchema[], + protos.google.pubsub.v1.IListSchemasRequest|null, + protos.google.pubsub.v1.IListSchemasResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + this.initialize(); + return this.innerApiCalls.listSchemas(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project in which to list schemas. + * Format is `projects/{project-id}`. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @param {number} request.pageSize + * Maximum number of schemas to return. + * @param {string} request.pageToken + * The value returned by the last `ListSchemasResponse`; indicates that + * this is a continuation of a prior `ListSchemas` call, and that the + * system should return the next page of data. + * @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.pubsub.v1.Schema|Schema} 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 `listSchemasAsync()` + * 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. + */ + listSchemasStream( + request?: protos.google.pubsub.v1.IListSchemasRequest, + 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 ?? '', + }); + const defaultCallSettings = this._defaults['listSchemas']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSchemas.createStream( + this.innerApiCalls.listSchemas as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listSchemas`, 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 name of the project in which to list schemas. + * Format is `projects/{project-id}`. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @param {number} request.pageSize + * Maximum number of schemas to return. + * @param {string} request.pageToken + * The value returned by the last `ListSchemasResponse`; indicates that + * this is a continuation of a prior `ListSchemas` call, and that the + * system should return the next page of data. + * @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.pubsub.v1.Schema|Schema}. 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. + */ + listSchemasAsync( + request?: protos.google.pubsub.v1.IListSchemasRequest, + 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 ?? '', + }); + const defaultCallSettings = this._defaults['listSchemas']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSchemas.asyncIterate( + this.innerApiCalls['listSchemas'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + /** + * Lists all schema revisions for the named schema. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the schema to list revisions for. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @param {number} request.pageSize + * The maximum number of revisions to return per page. + * @param {string} request.pageToken + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Schema|Schema}. + * 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 `listSchemaRevisionsAsync()` + * 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. + */ + listSchemaRevisions( + request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISchema[], + protos.google.pubsub.v1.IListSchemaRevisionsRequest|null, + protos.google.pubsub.v1.IListSchemaRevisionsResponse + ]>; + listSchemaRevisions( + request: protos.google.pubsub.v1.IListSchemaRevisionsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSchemaRevisionsRequest, + protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, + protos.google.pubsub.v1.ISchema>): void; + listSchemaRevisions( + request: protos.google.pubsub.v1.IListSchemaRevisionsRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSchemaRevisionsRequest, + protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, + protos.google.pubsub.v1.ISchema>): void; + listSchemaRevisions( + request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListSchemaRevisionsRequest, + protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, + protos.google.pubsub.v1.ISchema>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListSchemaRevisionsRequest, + protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, + protos.google.pubsub.v1.ISchema>): + Promise<[ + protos.google.pubsub.v1.ISchema[], + protos.google.pubsub.v1.IListSchemaRevisionsRequest|null, + protos.google.pubsub.v1.IListSchemaRevisionsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.listSchemaRevisions(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the schema to list revisions for. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @param {number} request.pageSize + * The maximum number of revisions to return per page. + * @param {string} request.pageToken + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * @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.pubsub.v1.Schema|Schema} 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 `listSchemaRevisionsAsync()` + * 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. + */ + listSchemaRevisionsStream( + request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listSchemaRevisions']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSchemaRevisions.createStream( + this.innerApiCalls.listSchemaRevisions as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listSchemaRevisions`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the schema to list revisions for. + * @param {google.pubsub.v1.SchemaView} request.view + * The set of Schema fields to return in the response. If not set, returns + * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to + * retrieve all fields. + * @param {number} request.pageSize + * The maximum number of revisions to return per page. + * @param {string} request.pageToken + * The page token, received from a previous ListSchemaRevisions call. + * Provide this to retrieve the subsequent page. + * @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.pubsub.v1.Schema|Schema}. 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. + */ + listSchemaRevisionsAsync( + request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listSchemaRevisions']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSchemaRevisions.asyncIterate( + this.innerApiCalls['listSchemaRevisions'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } +/** + * Gets the access control policy for a resource. Returns an empty policy + * if the resource exists and does not have a policy set. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {Object} [request.options] + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * + * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + getIamPolicy( + request: IamProtos.google.iam.v1.GetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.getIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + setIamPolicy( + request: IamProtos.google.iam.v1.SetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.setIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + */ + testIamPermissions( + request: IamProtos.google.iam.v1.TestIamPermissionsRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { + return this.iamClient.testIamPermissions(request, options, callback); + } + + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified project resource name string. + * + * @param {string} project + * @returns {string} Resource name string. + */ + projectPath(project:string) { + return this.pathTemplates.projectPathTemplate.render({ + project: project, + }); + } + + /** + * Parse the project from Project resource. + * + * @param {string} projectName + * A fully-qualified path representing Project resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectName(projectName: string) { + return this.pathTemplates.projectPathTemplate.match(projectName).project; + } + + /** + * Return a fully-qualified projectTopic resource name string. + * + * @param {string} project + * @param {string} topic + * @returns {string} Resource name string. + */ + projectTopicPath(project:string,topic:string) { + return this.pathTemplates.projectTopicPathTemplate.render({ + project: project, + topic: topic, + }); + } + + /** + * Parse the project from ProjectTopic resource. + * + * @param {string} projectTopicName + * A fully-qualified path representing project_topic resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectTopicName(projectTopicName: string) { + return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).project; + } + + /** + * Parse the topic from ProjectTopic resource. + * + * @param {string} projectTopicName + * A fully-qualified path representing project_topic resource. + * @returns {string} A string representing the topic. + */ + matchTopicFromProjectTopicName(projectTopicName: string) { + return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).topic; + } + + /** + * Return a fully-qualified schema resource name string. + * + * @param {string} project + * @param {string} schema + * @returns {string} Resource name string. + */ + schemaPath(project:string,schema:string) { + return this.pathTemplates.schemaPathTemplate.render({ + project: project, + schema: schema, + }); + } + + /** + * Parse the project from Schema resource. + * + * @param {string} schemaName + * A fully-qualified path representing Schema resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSchemaName(schemaName: string) { + return this.pathTemplates.schemaPathTemplate.match(schemaName).project; + } + + /** + * Parse the schema from Schema resource. + * + * @param {string} schemaName + * A fully-qualified path representing Schema resource. + * @returns {string} A string representing the schema. + */ + matchSchemaFromSchemaName(schemaName: string) { + return this.pathTemplates.schemaPathTemplate.match(schemaName).schema; + } + + /** + * Return a fully-qualified snapshot resource name string. + * + * @param {string} project + * @param {string} snapshot + * @returns {string} Resource name string. + */ + snapshotPath(project:string,snapshot:string) { + return this.pathTemplates.snapshotPathTemplate.render({ + project: project, + snapshot: snapshot, + }); + } + + /** + * Parse the project from Snapshot resource. + * + * @param {string} snapshotName + * A fully-qualified path representing Snapshot resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSnapshotName(snapshotName: string) { + return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project; + } + + /** + * Parse the snapshot from Snapshot resource. + * + * @param {string} snapshotName + * A fully-qualified path representing Snapshot resource. + * @returns {string} A string representing the snapshot. + */ + matchSnapshotFromSnapshotName(snapshotName: string) { + return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot; + } + + /** + * Return a fully-qualified subscription resource name string. + * + * @param {string} project + * @param {string} subscription + * @returns {string} Resource name string. + */ + subscriptionPath(project:string,subscription:string) { + return this.pathTemplates.subscriptionPathTemplate.render({ + project: project, + subscription: subscription, + }); + } + + /** + * Parse the project from Subscription resource. + * + * @param {string} subscriptionName + * A fully-qualified path representing Subscription resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSubscriptionName(subscriptionName: string) { + return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).project; + } + + /** + * Parse the subscription from Subscription resource. + * + * @param {string} subscriptionName + * A fully-qualified path representing Subscription resource. + * @returns {string} A string representing the subscription. + */ + matchSubscriptionFromSubscriptionName(subscriptionName: string) { + return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).subscription; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.schemaServiceStub && !this._terminated) { + return this.schemaServiceStub.then(stub => { + this._terminated = true; + stub.close(); + this.iamClient.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/owl-bot-staging/v1/src/v1/schema_service_client_config.json b/owl-bot-staging/v1/src/v1/schema_service_client_config.json new file mode 100644 index 000000000..5a2280962 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/schema_service_client_config.json @@ -0,0 +1,79 @@ +{ + "interfaces": { + "google.pubsub.v1.SchemaService": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "unavailable": [ + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "CreateSchema": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "GetSchema": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "ListSchemas": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "ListSchemaRevisions": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "CommitSchema": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "RollbackSchema": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "DeleteSchemaRevision": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "DeleteSchema": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "ValidateSchema": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "ValidateMessage": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + } + } + } + } +} diff --git a/owl-bot-staging/v1/src/v1/schema_service_proto_list.json b/owl-bot-staging/v1/src/v1/schema_service_proto_list.json new file mode 100644 index 000000000..91011aec1 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/schema_service_proto_list.json @@ -0,0 +1,4 @@ +[ + "../../protos/google/pubsub/v1/pubsub.proto", + "../../protos/google/pubsub/v1/schema.proto" +] diff --git a/owl-bot-staging/v1/src/v1/subscriber_client.ts b/owl-bot-staging/v1/src/v1/subscriber_client.ts new file mode 100644 index 000000000..6fe239510 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/subscriber_client.ts @@ -0,0 +1,2204 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import type * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos} from 'google-gax'; +import {Transform, PassThrough} from 'stream'; +import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); +/** + * Client JSON configuration object, loaded from + * `src/v1/subscriber_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +import * as gapicConfig from './subscriber_client_config.json'; +const version = require('../../../package.json').version; + +/** + * The service that an application uses to manipulate subscriptions and to + * consume messages from a subscription via the `Pull` method or by + * establishing a bi-directional stream using the `StreamingPull` method. + * @class + * @memberof v1 + */ +export class SubscriberClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + iamClient: IamClient; + pathTemplates: {[name: string]: gax.PathTemplate}; + subscriberStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of SubscriberClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new SubscriberClient({fallback: true}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof SubscriberClient; + const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.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); + + // Request numeric enum values if REST transport is used. + opts.numericEnums = true; + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); + + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectTopicPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/topics/{topic}' + ), + schemaPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/schemas/{schema}' + ), + snapshotPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/snapshots/{snapshot}' + ), + subscriptionPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/subscriptions/{subscription}' + ), + }; + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listSubscriptions: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'), + listSnapshots: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots') + }; + + // Some of the methods on this service provide streaming responses. + // Provide descriptors for these. + this.descriptors.stream = { + streamingPull: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback) + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.pubsub.v1.Subscriber', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.subscriberStub) { + return this.subscriberStub; + } + + // Put together the "service stub" for + // google.pubsub.v1.Subscriber. + this.subscriberStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.pubsub.v1.Subscriber') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.pubsub.v1.Subscriber, + 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 subscriberStubMethods = + ['createSubscription', 'getSubscription', 'updateSubscription', 'listSubscriptions', 'deleteSubscription', 'modifyAckDeadline', 'acknowledge', 'pull', 'streamingPull', 'modifyPushConfig', 'getSnapshot', 'listSnapshots', 'createSnapshot', 'updateSnapshot', 'deleteSnapshot', 'seek']; + for (const methodName of subscriberStubMethods) { + const callPromise = this.subscriberStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + if (methodName in this.descriptors.stream) { + const stream = new PassThrough(); + setImmediate(() => { + stream.emit('error', new this._gaxModule.GoogleError('The client has already been closed.')); + }); + return stream; + } + 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] || + this.descriptors.stream[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.subscriberStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'pubsub.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'pubsub.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/pubsub' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- +/** + * Creates a subscription to a given topic. See the [resource name rules] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). + * If the subscription already exists, returns `ALREADY_EXISTS`. + * If the corresponding topic doesn't exist, returns `NOT_FOUND`. + * + * If the name is not provided in the request, the server will assign a random + * name for this subscription on the same project as the topic, conforming + * to the [resource name format] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated + * name is populated in the returned Subscription object. Note that for REST + * API requests, you must specify a name in the request. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the subscription. It must have the format + * `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must + * start with a letter, and contain only letters (`[A-Za-z]`), numbers + * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), + * plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters + * in length, and it must not start with `"goog"`. + * @param {string} request.topic + * Required. The name of the topic from which this subscription is receiving + * messages. Format is `projects/{project}/topics/{topic}`. The value of this + * field will be `_deleted-topic_` if the topic has been deleted. + * @param {google.pubsub.v1.PushConfig} request.pushConfig + * If push delivery is used with this subscription, this field is + * used to configure it. + * @param {google.pubsub.v1.BigQueryConfig} request.bigqueryConfig + * If delivery to BigQuery is used with this subscription, this field is + * used to configure it. + * @param {google.pubsub.v1.CloudStorageConfig} request.cloudStorageConfig + * If delivery to Google Cloud Storage is used with this subscription, this + * field is used to configure it. + * @param {number} request.ackDeadlineSeconds + * The approximate amount of time (on a best-effort basis) Pub/Sub waits for + * the subscriber to acknowledge receipt before resending the message. In the + * interval after the message is delivered and before it is acknowledged, it + * is considered to be _outstanding_. During that time period, the + * message will not be redelivered (on a best-effort basis). + * + * For pull subscriptions, this value is used as the initial value for the ack + * deadline. To override this value for a given message, call + * `ModifyAckDeadline` with the corresponding `ack_id` if using + * non-streaming pull or send the `ack_id` in a + * `StreamingModifyAckDeadlineRequest` if using streaming pull. + * The minimum custom deadline you can specify is 10 seconds. + * The maximum custom deadline you can specify is 600 seconds (10 minutes). + * If this parameter is 0, a default value of 10 seconds is used. + * + * For push delivery, this value is also used to set the request timeout for + * the call to the push endpoint. + * + * If the subscriber never acknowledges the message, the Pub/Sub + * system will eventually redeliver the message. + * @param {boolean} request.retainAckedMessages + * Indicates whether to retain acknowledged messages. If true, then + * messages are not expunged from the subscription's backlog, even if they are + * acknowledged, until they fall out of the `message_retention_duration` + * window. This must be true if you would like to [`Seek` to a timestamp] + * (https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) in + * the past to replay previously-acknowledged messages. + * @param {google.protobuf.Duration} request.messageRetentionDuration + * How long to retain unacknowledged messages in the subscription's backlog, + * from the moment a message is published. + * If `retain_acked_messages` is true, then this also configures the retention + * of acknowledged messages, and thus configures how far back in time a `Seek` + * can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 + * minutes. + * @param {number[]} request.labels + * See [Creating and managing + * labels](https://cloud.google.com/pubsub/docs/labels). + * @param {boolean} request.enableMessageOrdering + * If true, messages published with the same `ordering_key` in `PubsubMessage` + * will be delivered to the subscribers in the order in which they + * are received by the Pub/Sub system. Otherwise, they may be delivered in + * any order. + * @param {google.pubsub.v1.ExpirationPolicy} request.expirationPolicy + * A policy that specifies the conditions for this subscription's expiration. + * A subscription is considered active as long as any connected subscriber is + * successfully consuming messages from the subscription or is issuing + * operations on the subscription. If `expiration_policy` is not set, a + * *default policy* with `ttl` of 31 days will be used. The minimum allowed + * value for `expiration_policy.ttl` is 1 day. If `expiration_policy` is set, + * but `expiration_policy.ttl` is not set, the subscription never expires. + * @param {string} request.filter + * An expression written in the Pub/Sub [filter + * language](https://cloud.google.com/pubsub/docs/filtering). If non-empty, + * then only `PubsubMessage`s whose `attributes` field matches the filter are + * delivered on this subscription. If empty, then no messages are filtered + * out. + * @param {google.pubsub.v1.DeadLetterPolicy} request.deadLetterPolicy + * A policy that specifies the conditions for dead lettering messages in + * this subscription. If dead_letter_policy is not set, dead lettering + * is disabled. + * + * The Cloud Pub/Sub service account associated with this subscriptions's + * parent project (i.e., + * service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have + * permission to Acknowledge() messages on this subscription. + * @param {google.pubsub.v1.RetryPolicy} request.retryPolicy + * A policy that specifies how Pub/Sub retries message delivery for this + * subscription. + * + * If not set, the default retry policy is applied. This generally implies + * that messages will be retried as soon as possible for healthy subscribers. + * RetryPolicy will be triggered on NACKs or acknowledgement deadline + * exceeded events for a given message. + * @param {boolean} request.detached + * Indicates whether the subscription is detached from its topic. Detached + * subscriptions don't receive messages from their topic and don't retain any + * backlog. `Pull` and `StreamingPull` requests will return + * FAILED_PRECONDITION. If the subscription is a push subscription, pushes to + * the endpoint will not be made. + * @param {boolean} request.enableExactlyOnceDelivery + * If true, Pub/Sub provides the following guarantees for the delivery of + * a message with a given value of `message_id` on this subscription: + * + * * The message sent to a subscriber is guaranteed not to be resent + * before the message's acknowledgement deadline expires. + * * An acknowledged message will not be resent to a subscriber. + * + * Note that subscribers may still receive multiple copies of a message + * when `enable_exactly_once_delivery` is true if the message was published + * multiple times by a publisher client. These copies are considered distinct + * by Pub/Sub and have distinct `message_id` values. + * @param {google.protobuf.Duration} request.topicMessageRetentionDuration + * Output only. Indicates the minimum duration for which a message is retained + * after it is published to the subscription's topic. If this field is set, + * messages published to the subscription's topic in the last + * `topic_message_retention_duration` are always available to subscribers. See + * the `message_retention_duration` field in `Topic`. This field is set only + * in responses from the server; it is ignored if it is set in any requests. + * @param {google.pubsub.v1.Subscription.State} request.state + * Output only. An output-only field indicating whether or not the + * subscription can receive messages. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Subscription|Subscription}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + createSubscription( + request?: protos.google.pubsub.v1.ISubscription, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.ISubscription|undefined, {}|undefined + ]>; + createSubscription( + request: protos.google.pubsub.v1.ISubscription, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.ISubscription|null|undefined, + {}|null|undefined>): void; + createSubscription( + request: protos.google.pubsub.v1.ISubscription, + callback: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.ISubscription|null|undefined, + {}|null|undefined>): void; + createSubscription( + request?: protos.google.pubsub.v1.ISubscription, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.ISubscription|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.ISubscription|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.ISubscription|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.createSubscription(request, options, callback); + } +/** + * Gets the configuration details of a subscription. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The name of the subscription to get. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Subscription|Subscription}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + getSubscription( + request?: protos.google.pubsub.v1.IGetSubscriptionRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IGetSubscriptionRequest|undefined, {}|undefined + ]>; + getSubscription( + request: protos.google.pubsub.v1.IGetSubscriptionRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + getSubscription( + request: protos.google.pubsub.v1.IGetSubscriptionRequest, + callback: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + getSubscription( + request?: protos.google.pubsub.v1.IGetSubscriptionRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IGetSubscriptionRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.getSubscription(request, options, callback); + } +/** + * Updates an existing subscription. Note that certain properties of a + * subscription, such as its topic, are not modifiable. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.pubsub.v1.Subscription} request.subscription + * Required. The updated subscription object. + * @param {google.protobuf.FieldMask} request.updateMask + * Required. Indicates which fields in the provided subscription to update. + * Must be specified and non-empty. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Subscription|Subscription}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + updateSubscription( + request?: protos.google.pubsub.v1.IUpdateSubscriptionRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IUpdateSubscriptionRequest|undefined, {}|undefined + ]>; + updateSubscription( + request: protos.google.pubsub.v1.IUpdateSubscriptionRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + updateSubscription( + request: protos.google.pubsub.v1.IUpdateSubscriptionRequest, + callback: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + updateSubscription( + request?: protos.google.pubsub.v1.IUpdateSubscriptionRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISubscription, + protos.google.pubsub.v1.IUpdateSubscriptionRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription.name': request.subscription!.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.updateSubscription(request, options, callback); + } +/** + * Deletes an existing subscription. All messages retained in the subscription + * are immediately dropped. Calls to `Pull` after deletion will return + * `NOT_FOUND`. After a subscription is deleted, a new one may be created with + * the same name, but the new one has no association with the old + * subscription or its topic unless the same topic is specified. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The subscription to delete. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + deleteSubscription( + request?: protos.google.pubsub.v1.IDeleteSubscriptionRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSubscriptionRequest|undefined, {}|undefined + ]>; + deleteSubscription( + request: protos.google.pubsub.v1.IDeleteSubscriptionRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + deleteSubscription( + request: protos.google.pubsub.v1.IDeleteSubscriptionRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, + {}|null|undefined>): void; + deleteSubscription( + request?: protos.google.pubsub.v1.IDeleteSubscriptionRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSubscriptionRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.deleteSubscription(request, options, callback); + } +/** + * Modifies the ack deadline for a specific message. This method is useful + * to indicate that more time is needed to process a message by the + * subscriber, or to make the message available for redelivery if the + * processing was interrupted. Note that this does not modify the + * subscription-level `ackDeadlineSeconds` used for subsequent messages. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The name of the subscription. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {string[]} request.ackIds + * Required. List of acknowledgment IDs. + * @param {number} request.ackDeadlineSeconds + * Required. The new ack deadline with respect to the time this request was + * sent to the Pub/Sub system. For example, if the value is 10, the new ack + * deadline will expire 10 seconds after the `ModifyAckDeadline` call was + * made. Specifying zero might immediately make the message available for + * delivery to another subscriber client. This typically results in an + * increase in the rate of message redeliveries (that is, duplicates). + * The minimum deadline you can specify is 0 seconds. + * The maximum deadline you can specify is 600 seconds (10 minutes). + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + modifyAckDeadline( + request?: protos.google.pubsub.v1.IModifyAckDeadlineRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyAckDeadlineRequest|undefined, {}|undefined + ]>; + modifyAckDeadline( + request: protos.google.pubsub.v1.IModifyAckDeadlineRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, + {}|null|undefined>): void; + modifyAckDeadline( + request: protos.google.pubsub.v1.IModifyAckDeadlineRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, + {}|null|undefined>): void; + modifyAckDeadline( + request?: protos.google.pubsub.v1.IModifyAckDeadlineRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyAckDeadlineRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.modifyAckDeadline(request, options, callback); + } +/** + * Acknowledges the messages associated with the `ack_ids` in the + * `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages + * from the subscription. + * + * Acknowledging a message whose ack deadline has expired may succeed, + * but such a message may be redelivered later. Acknowledging a message more + * than once will not result in an error. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The subscription whose message is being acknowledged. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {string[]} request.ackIds + * Required. The acknowledgment ID for the messages being acknowledged that + * was returned by the Pub/Sub system in the `Pull` response. Must not be + * empty. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + acknowledge( + request?: protos.google.pubsub.v1.IAcknowledgeRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IAcknowledgeRequest|undefined, {}|undefined + ]>; + acknowledge( + request: protos.google.pubsub.v1.IAcknowledgeRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, + {}|null|undefined>): void; + acknowledge( + request: protos.google.pubsub.v1.IAcknowledgeRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, + {}|null|undefined>): void; + acknowledge( + request?: protos.google.pubsub.v1.IAcknowledgeRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IAcknowledgeRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.acknowledge(request, options, callback); + } +/** + * Pulls messages from the server. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The subscription from which messages should be pulled. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {boolean} [request.returnImmediately] + * Optional. If this field set to true, the system will respond immediately + * even if it there are no messages available to return in the `Pull` + * response. Otherwise, the system may wait (for a bounded amount of time) + * until at least one message is available, rather than returning no messages. + * Warning: setting this field to `true` is discouraged because it adversely + * impacts the performance of `Pull` operations. We recommend that users do + * not set this field. + * @param {number} request.maxMessages + * Required. The maximum number of messages to return for this request. Must + * be a positive integer. The Pub/Sub system may return fewer than the number + * specified. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.PullResponse|PullResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + pull( + request?: protos.google.pubsub.v1.IPullRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.IPullResponse, + protos.google.pubsub.v1.IPullRequest|undefined, {}|undefined + ]>; + pull( + request: protos.google.pubsub.v1.IPullRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.IPullResponse, + protos.google.pubsub.v1.IPullRequest|null|undefined, + {}|null|undefined>): void; + pull( + request: protos.google.pubsub.v1.IPullRequest, + callback: Callback< + protos.google.pubsub.v1.IPullResponse, + protos.google.pubsub.v1.IPullRequest|null|undefined, + {}|null|undefined>): void; + pull( + request?: protos.google.pubsub.v1.IPullRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.IPullResponse, + protos.google.pubsub.v1.IPullRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.IPullResponse, + protos.google.pubsub.v1.IPullRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.IPullResponse, + protos.google.pubsub.v1.IPullRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.pull(request, options, callback); + } +/** + * Modifies the `PushConfig` for a specified subscription. + * + * This may be used to change a push subscription to a pull one (signified by + * an empty `PushConfig`) or vice versa, or change the endpoint URL and other + * attributes of a push subscription. Messages will accumulate for delivery + * continuously through the call regardless of changes to the `PushConfig`. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The name of the subscription. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {google.pubsub.v1.PushConfig} request.pushConfig + * Required. The push configuration for future deliveries. + * + * An empty `pushConfig` indicates that the Pub/Sub system should + * stop pushing messages from the given subscription and allow + * messages to be pulled and acknowledged - effectively pausing + * the subscription if `Pull` or `StreamingPull` is not called. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + modifyPushConfig( + request?: protos.google.pubsub.v1.IModifyPushConfigRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyPushConfigRequest|undefined, {}|undefined + ]>; + modifyPushConfig( + request: protos.google.pubsub.v1.IModifyPushConfigRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, + {}|null|undefined>): void; + modifyPushConfig( + request: protos.google.pubsub.v1.IModifyPushConfigRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, + {}|null|undefined>): void; + modifyPushConfig( + request?: protos.google.pubsub.v1.IModifyPushConfigRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IModifyPushConfigRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.modifyPushConfig(request, options, callback); + } +/** + * Gets the configuration details of a snapshot. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.snapshot + * Required. The name of the snapshot to get. + * Format is `projects/{project}/snapshots/{snap}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + getSnapshot( + request?: protos.google.pubsub.v1.IGetSnapshotRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IGetSnapshotRequest|undefined, {}|undefined + ]>; + getSnapshot( + request: protos.google.pubsub.v1.IGetSnapshotRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, + {}|null|undefined>): void; + getSnapshot( + request: protos.google.pubsub.v1.IGetSnapshotRequest, + callback: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, + {}|null|undefined>): void; + getSnapshot( + request?: protos.google.pubsub.v1.IGetSnapshotRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IGetSnapshotRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'snapshot': request.snapshot ?? '', + }); + this.initialize(); + return this.innerApiCalls.getSnapshot(request, options, callback); + } +/** + * Creates a snapshot from the requested subscription. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * If the snapshot already exists, returns `ALREADY_EXISTS`. + * If the requested subscription doesn't exist, returns `NOT_FOUND`. + * If the backlog in the subscription is too old -- and the resulting snapshot + * would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. + * See also the `Snapshot.expire_time` field. If the name is not provided in + * the request, the server will assign a random + * name for this snapshot on the same project as the subscription, conforming + * to the [resource name format] + * (https://cloud.google.com/pubsub/docs/admin#resource_names). The + * generated name is populated in the returned Snapshot object. Note that for + * REST API requests, you must specify a name in the request. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. User-provided name for this snapshot. If the name is not provided + * in the request, the server will assign a random name for this snapshot on + * the same project as the subscription. Note that for REST API requests, you + * must specify a name. See the [resource name + * rules](https://cloud.google.com/pubsub/docs/admin#resource_names). Format + * is `projects/{project}/snapshots/{snap}`. + * @param {string} request.subscription + * Required. The subscription whose backlog the snapshot retains. + * Specifically, the created snapshot is guaranteed to retain: + * (a) The existing backlog on the subscription. More precisely, this is + * defined as the messages in the subscription's backlog that are + * unacknowledged upon the successful completion of the + * `CreateSnapshot` request; as well as: + * (b) Any messages published to the subscription's topic following the + * successful completion of the CreateSnapshot request. + * Format is `projects/{project}/subscriptions/{sub}`. + * @param {number[]} request.labels + * See [Creating and managing + * labels](https://cloud.google.com/pubsub/docs/labels). + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + createSnapshot( + request?: protos.google.pubsub.v1.ICreateSnapshotRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.ICreateSnapshotRequest|undefined, {}|undefined + ]>; + createSnapshot( + request: protos.google.pubsub.v1.ICreateSnapshotRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, + {}|null|undefined>): void; + createSnapshot( + request: protos.google.pubsub.v1.ICreateSnapshotRequest, + callback: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, + {}|null|undefined>): void; + createSnapshot( + request?: protos.google.pubsub.v1.ICreateSnapshotRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.ICreateSnapshotRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.createSnapshot(request, options, callback); + } +/** + * Updates an existing snapshot. Snapshots are used in + * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, + * which allow you to manage message acknowledgments in bulk. That is, you can + * set the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.pubsub.v1.Snapshot} request.snapshot + * Required. The updated snapshot object. + * @param {google.protobuf.FieldMask} request.updateMask + * Required. Indicates which fields in the provided snapshot to update. + * Must be specified and non-empty. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + updateSnapshot( + request?: protos.google.pubsub.v1.IUpdateSnapshotRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IUpdateSnapshotRequest|undefined, {}|undefined + ]>; + updateSnapshot( + request: protos.google.pubsub.v1.IUpdateSnapshotRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, + {}|null|undefined>): void; + updateSnapshot( + request: protos.google.pubsub.v1.IUpdateSnapshotRequest, + callback: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, + {}|null|undefined>): void; + updateSnapshot( + request?: protos.google.pubsub.v1.IUpdateSnapshotRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISnapshot, + protos.google.pubsub.v1.IUpdateSnapshotRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'snapshot.name': request.snapshot!.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.updateSnapshot(request, options, callback); + } +/** + * Removes an existing snapshot. Snapshots are used in [Seek] + * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which + * allow you to manage message acknowledgments in bulk. That is, you can set + * the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * When the snapshot is deleted, all messages retained in the snapshot + * are immediately dropped. After a snapshot is deleted, a new one may be + * created with the same name, but the new one has no association with the old + * snapshot or its subscription, unless the same subscription is specified. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.snapshot + * Required. The name of the snapshot to delete. + * Format is `projects/{project}/snapshots/{snap}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. + */ + deleteSnapshot( + request?: protos.google.pubsub.v1.IDeleteSnapshotRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSnapshotRequest|undefined, {}|undefined + ]>; + deleteSnapshot( + request: protos.google.pubsub.v1.IDeleteSnapshotRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, + {}|null|undefined>): void; + deleteSnapshot( + request: protos.google.pubsub.v1.IDeleteSnapshotRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, + {}|null|undefined>): void; + deleteSnapshot( + request?: protos.google.pubsub.v1.IDeleteSnapshotRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.pubsub.v1.IDeleteSnapshotRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'snapshot': request.snapshot ?? '', + }); + this.initialize(); + return this.innerApiCalls.deleteSnapshot(request, options, callback); + } +/** + * Seeks an existing subscription to a point in time or to a given snapshot, + * whichever is provided in the request. Snapshots are used in [Seek] + * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which + * allow you to manage message acknowledgments in bulk. That is, you can set + * the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. Note that both the subscription and the + * snapshot must be on the same topic. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.subscription + * Required. The subscription to affect. + * @param {google.protobuf.Timestamp} request.time + * The time to seek to. + * Messages retained in the subscription that were published before this + * time are marked as acknowledged, and messages retained in the + * subscription that were published after this time are marked as + * unacknowledged. Note that this operation affects only those messages + * retained in the subscription (configured by the combination of + * `message_retention_duration` and `retain_acked_messages`). For example, + * if `time` corresponds to a point before the message retention + * window (or to a point before the system's notion of the subscription + * creation time), only retained messages will be marked as unacknowledged, + * and already-expunged messages will not be restored. + * @param {string} request.snapshot + * The snapshot to seek to. The snapshot's topic must be the same as that of + * the provided subscription. + * Format is `projects/{project}/snapshots/{snap}`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.pubsub.v1.SeekResponse|SeekResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + */ + seek( + request?: protos.google.pubsub.v1.ISeekRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISeekResponse, + protos.google.pubsub.v1.ISeekRequest|undefined, {}|undefined + ]>; + seek( + request: protos.google.pubsub.v1.ISeekRequest, + options: CallOptions, + callback: Callback< + protos.google.pubsub.v1.ISeekResponse, + protos.google.pubsub.v1.ISeekRequest|null|undefined, + {}|null|undefined>): void; + seek( + request: protos.google.pubsub.v1.ISeekRequest, + callback: Callback< + protos.google.pubsub.v1.ISeekResponse, + protos.google.pubsub.v1.ISeekRequest|null|undefined, + {}|null|undefined>): void; + seek( + request?: protos.google.pubsub.v1.ISeekRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.pubsub.v1.ISeekResponse, + protos.google.pubsub.v1.ISeekRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.pubsub.v1.ISeekResponse, + protos.google.pubsub.v1.ISeekRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.pubsub.v1.ISeekResponse, + protos.google.pubsub.v1.ISeekRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'subscription': request.subscription ?? '', + }); + this.initialize(); + return this.innerApiCalls.seek(request, options, callback); + } + +/** + * Establishes a stream with the server, which sends messages down to the + * client. The client streams acknowledgements and ack deadline modifications + * back to the server. The server will close the stream and return the status + * on any error. The server may close the stream with status `UNAVAILABLE` to + * reassign server-side resources, in which case, the client should + * re-establish the stream. Flow control can be achieved by configuring the + * underlying RPC channel. + * + * @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 is both readable and writable. It accepts objects + * representing {@link protos.google.pubsub.v1.StreamingPullRequest|StreamingPullRequest} for write() method, and + * will emit objects representing {@link protos.google.pubsub.v1.StreamingPullResponse|StreamingPullResponse} on 'data' event asynchronously. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } + * for more details and examples. + */ + streamingPull( + options?: CallOptions): + gax.CancellableStream { + this.initialize(); + return this.innerApiCalls.streamingPull(null, options); + } + + /** + * Lists matching subscriptions. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Required. The name of the project in which to list subscriptions. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of subscriptions to return. + * @param {string} request.pageToken + * The value returned by the last `ListSubscriptionsResponse`; indicates that + * this is a continuation of a prior `ListSubscriptions` call, and that the + * system should return the next page of data. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Subscription|Subscription}. + * 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 `listSubscriptionsAsync()` + * 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. + */ + listSubscriptions( + request?: protos.google.pubsub.v1.IListSubscriptionsRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISubscription[], + protos.google.pubsub.v1.IListSubscriptionsRequest|null, + protos.google.pubsub.v1.IListSubscriptionsResponse + ]>; + listSubscriptions( + request: protos.google.pubsub.v1.IListSubscriptionsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSubscriptionsRequest, + protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, + protos.google.pubsub.v1.ISubscription>): void; + listSubscriptions( + request: protos.google.pubsub.v1.IListSubscriptionsRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSubscriptionsRequest, + protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, + protos.google.pubsub.v1.ISubscription>): void; + listSubscriptions( + request?: protos.google.pubsub.v1.IListSubscriptionsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListSubscriptionsRequest, + protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, + protos.google.pubsub.v1.ISubscription>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListSubscriptionsRequest, + protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, + protos.google.pubsub.v1.ISubscription>): + Promise<[ + protos.google.pubsub.v1.ISubscription[], + protos.google.pubsub.v1.IListSubscriptionsRequest|null, + protos.google.pubsub.v1.IListSubscriptionsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'project': request.project ?? '', + }); + this.initialize(); + return this.innerApiCalls.listSubscriptions(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Required. The name of the project in which to list subscriptions. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of subscriptions to return. + * @param {string} request.pageToken + * The value returned by the last `ListSubscriptionsResponse`; indicates that + * this is a continuation of a prior `ListSubscriptions` call, and that the + * system should return the next page of data. + * @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.pubsub.v1.Subscription|Subscription} 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 `listSubscriptionsAsync()` + * 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. + */ + listSubscriptionsStream( + request?: protos.google.pubsub.v1.IListSubscriptionsRequest, + 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({ + 'project': request.project ?? '', + }); + const defaultCallSettings = this._defaults['listSubscriptions']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSubscriptions.createStream( + this.innerApiCalls.listSubscriptions as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listSubscriptions`, 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.project + * Required. The name of the project in which to list subscriptions. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of subscriptions to return. + * @param {string} request.pageToken + * The value returned by the last `ListSubscriptionsResponse`; indicates that + * this is a continuation of a prior `ListSubscriptions` call, and that the + * system should return the next page of data. + * @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.pubsub.v1.Subscription|Subscription}. 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. + */ + listSubscriptionsAsync( + request?: protos.google.pubsub.v1.IListSubscriptionsRequest, + 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({ + 'project': request.project ?? '', + }); + const defaultCallSettings = this._defaults['listSubscriptions']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSubscriptions.asyncIterate( + this.innerApiCalls['listSubscriptions'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + /** + * Lists the existing snapshots. Snapshots are used in [Seek]( + * https://cloud.google.com/pubsub/docs/replay-overview) operations, which + * allow you to manage message acknowledgments in bulk. That is, you can set + * the acknowledgment state of messages in an existing subscription to the + * state captured by a snapshot. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Required. The name of the project in which to list snapshots. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of snapshots to return. + * @param {string} request.pageToken + * The value returned by the last `ListSnapshotsResponse`; indicates that this + * is a continuation of a prior `ListSnapshots` call, and that the system + * should return the next page of data. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Snapshot|Snapshot}. + * 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 `listSnapshotsAsync()` + * 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. + */ + listSnapshots( + request?: protos.google.pubsub.v1.IListSnapshotsRequest, + options?: CallOptions): + Promise<[ + protos.google.pubsub.v1.ISnapshot[], + protos.google.pubsub.v1.IListSnapshotsRequest|null, + protos.google.pubsub.v1.IListSnapshotsResponse + ]>; + listSnapshots( + request: protos.google.pubsub.v1.IListSnapshotsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSnapshotsRequest, + protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, + protos.google.pubsub.v1.ISnapshot>): void; + listSnapshots( + request: protos.google.pubsub.v1.IListSnapshotsRequest, + callback: PaginationCallback< + protos.google.pubsub.v1.IListSnapshotsRequest, + protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, + protos.google.pubsub.v1.ISnapshot>): void; + listSnapshots( + request?: protos.google.pubsub.v1.IListSnapshotsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.pubsub.v1.IListSnapshotsRequest, + protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, + protos.google.pubsub.v1.ISnapshot>, + callback?: PaginationCallback< + protos.google.pubsub.v1.IListSnapshotsRequest, + protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, + protos.google.pubsub.v1.ISnapshot>): + Promise<[ + protos.google.pubsub.v1.ISnapshot[], + protos.google.pubsub.v1.IListSnapshotsRequest|null, + protos.google.pubsub.v1.IListSnapshotsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'project': request.project ?? '', + }); + this.initialize(); + return this.innerApiCalls.listSnapshots(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.project + * Required. The name of the project in which to list snapshots. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of snapshots to return. + * @param {string} request.pageToken + * The value returned by the last `ListSnapshotsResponse`; indicates that this + * is a continuation of a prior `ListSnapshots` call, and that the system + * should return the next page of data. + * @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.pubsub.v1.Snapshot|Snapshot} 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 `listSnapshotsAsync()` + * 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. + */ + listSnapshotsStream( + request?: protos.google.pubsub.v1.IListSnapshotsRequest, + 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({ + 'project': request.project ?? '', + }); + const defaultCallSettings = this._defaults['listSnapshots']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSnapshots.createStream( + this.innerApiCalls.listSnapshots as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listSnapshots`, 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.project + * Required. The name of the project in which to list snapshots. + * Format is `projects/{project-id}`. + * @param {number} request.pageSize + * Maximum number of snapshots to return. + * @param {string} request.pageToken + * The value returned by the last `ListSnapshotsResponse`; indicates that this + * is a continuation of a prior `ListSnapshots` call, and that the system + * should return the next page of data. + * @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.pubsub.v1.Snapshot|Snapshot}. 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. + */ + listSnapshotsAsync( + request?: protos.google.pubsub.v1.IListSnapshotsRequest, + 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({ + 'project': request.project ?? '', + }); + const defaultCallSettings = this._defaults['listSnapshots']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSnapshots.asyncIterate( + this.innerApiCalls['listSnapshots'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } +/** + * Gets the access control policy for a resource. Returns an empty policy + * if the resource exists and does not have a policy set. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {Object} [request.options] + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * + * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + getIamPolicy( + request: IamProtos.google.iam.v1.GetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.getIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + setIamPolicy( + request: IamProtos.google.iam.v1.SetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.setIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @param {Object} [options] + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. + * @param {function(?Error, ?Object)} [callback] + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + */ + testIamPermissions( + request: IamProtos.google.iam.v1.TestIamPermissionsRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { + return this.iamClient.testIamPermissions(request, options, callback); + } + + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified project resource name string. + * + * @param {string} project + * @returns {string} Resource name string. + */ + projectPath(project:string) { + return this.pathTemplates.projectPathTemplate.render({ + project: project, + }); + } + + /** + * Parse the project from Project resource. + * + * @param {string} projectName + * A fully-qualified path representing Project resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectName(projectName: string) { + return this.pathTemplates.projectPathTemplate.match(projectName).project; + } + + /** + * Return a fully-qualified projectTopic resource name string. + * + * @param {string} project + * @param {string} topic + * @returns {string} Resource name string. + */ + projectTopicPath(project:string,topic:string) { + return this.pathTemplates.projectTopicPathTemplate.render({ + project: project, + topic: topic, + }); + } + + /** + * Parse the project from ProjectTopic resource. + * + * @param {string} projectTopicName + * A fully-qualified path representing project_topic resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectTopicName(projectTopicName: string) { + return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).project; + } + + /** + * Parse the topic from ProjectTopic resource. + * + * @param {string} projectTopicName + * A fully-qualified path representing project_topic resource. + * @returns {string} A string representing the topic. + */ + matchTopicFromProjectTopicName(projectTopicName: string) { + return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).topic; + } + + /** + * Return a fully-qualified schema resource name string. + * + * @param {string} project + * @param {string} schema + * @returns {string} Resource name string. + */ + schemaPath(project:string,schema:string) { + return this.pathTemplates.schemaPathTemplate.render({ + project: project, + schema: schema, + }); + } + + /** + * Parse the project from Schema resource. + * + * @param {string} schemaName + * A fully-qualified path representing Schema resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSchemaName(schemaName: string) { + return this.pathTemplates.schemaPathTemplate.match(schemaName).project; + } + + /** + * Parse the schema from Schema resource. + * + * @param {string} schemaName + * A fully-qualified path representing Schema resource. + * @returns {string} A string representing the schema. + */ + matchSchemaFromSchemaName(schemaName: string) { + return this.pathTemplates.schemaPathTemplate.match(schemaName).schema; + } + + /** + * Return a fully-qualified snapshot resource name string. + * + * @param {string} project + * @param {string} snapshot + * @returns {string} Resource name string. + */ + snapshotPath(project:string,snapshot:string) { + return this.pathTemplates.snapshotPathTemplate.render({ + project: project, + snapshot: snapshot, + }); + } + + /** + * Parse the project from Snapshot resource. + * + * @param {string} snapshotName + * A fully-qualified path representing Snapshot resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSnapshotName(snapshotName: string) { + return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project; + } + + /** + * Parse the snapshot from Snapshot resource. + * + * @param {string} snapshotName + * A fully-qualified path representing Snapshot resource. + * @returns {string} A string representing the snapshot. + */ + matchSnapshotFromSnapshotName(snapshotName: string) { + return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot; + } + + /** + * Return a fully-qualified subscription resource name string. + * + * @param {string} project + * @param {string} subscription + * @returns {string} Resource name string. + */ + subscriptionPath(project:string,subscription:string) { + return this.pathTemplates.subscriptionPathTemplate.render({ + project: project, + subscription: subscription, + }); + } + + /** + * Parse the project from Subscription resource. + * + * @param {string} subscriptionName + * A fully-qualified path representing Subscription resource. + * @returns {string} A string representing the project. + */ + matchProjectFromSubscriptionName(subscriptionName: string) { + return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).project; + } + + /** + * Parse the subscription from Subscription resource. + * + * @param {string} subscriptionName + * A fully-qualified path representing Subscription resource. + * @returns {string} A string representing the subscription. + */ + matchSubscriptionFromSubscriptionName(subscriptionName: string) { + return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).subscription; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.subscriberStub && !this._terminated) { + return this.subscriberStub.then(stub => { + this._terminated = true; + stub.close(); + this.iamClient.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/owl-bot-staging/v1/src/v1/subscriber_client_config.json b/owl-bot-staging/v1/src/v1/subscriber_client_config.json new file mode 100644 index 000000000..a549d3010 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/subscriber_client_config.json @@ -0,0 +1,136 @@ +{ + "interfaces": { + "google.pubsub.v1.Subscriber": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ], + "unknown_aborted_unavailable": [ + "UNKNOWN", + "ABORTED", + "UNAVAILABLE" + ], + "unavailable": [ + "UNAVAILABLE" + ], + "unknown_aborted_internal_unavailable": [ + "UNKNOWN", + "ABORTED", + "INTERNAL", + "UNAVAILABLE" + ], + "deadline_exceeded_resource_exhausted_aborted_internal_unavailable": [ + "DEADLINE_EXCEEDED", + "RESOURCE_EXHAUSTED", + "ABORTED", + "INTERNAL", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + }, + "693222d32e887d96c8faeadca469f7763ccda85a": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 4, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "CreateSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "GetSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "UpdateSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "ListSubscriptions": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "DeleteSubscription": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "ModifyAckDeadline": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "Acknowledge": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "Pull": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_internal_unavailable", + "retry_params_name": "default" + }, + "StreamingPull": { + "timeout_millis": 900000, + "retry_codes_name": "deadline_exceeded_resource_exhausted_aborted_internal_unavailable", + "retry_params_name": "693222d32e887d96c8faeadca469f7763ccda85a" + }, + "ModifyPushConfig": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "GetSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "ListSnapshots": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + }, + "CreateSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "UpdateSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "DeleteSnapshot": { + "timeout_millis": 60000, + "retry_codes_name": "unavailable", + "retry_params_name": "default" + }, + "Seek": { + "timeout_millis": 60000, + "retry_codes_name": "unknown_aborted_unavailable", + "retry_params_name": "default" + } + } + } + } +} diff --git a/owl-bot-staging/v1/src/v1/subscriber_proto_list.json b/owl-bot-staging/v1/src/v1/subscriber_proto_list.json new file mode 100644 index 000000000..91011aec1 --- /dev/null +++ b/owl-bot-staging/v1/src/v1/subscriber_proto_list.json @@ -0,0 +1,4 @@ +[ + "../../protos/google/pubsub/v1/pubsub.proto", + "../../protos/google/pubsub/v1/schema.proto" +] diff --git a/owl-bot-staging/v1/test/gapic_publisher_v1.ts b/owl-bot-staging/v1/test/gapic_publisher_v1.ts new file mode 100644 index 000000000..8fe09a0a4 --- /dev/null +++ b/owl-bot-staging/v1/test/gapic_publisher_v1.ts @@ -0,0 +1,2013 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as publisherModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, IamProtos} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.PublisherClient', () => { + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = publisherModule.v1.PublisherClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = publisherModule.v1.PublisherClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = publisherModule.v1.PublisherClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new publisherModule.v1.PublisherClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new publisherModule.v1.PublisherClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.publisherStub, undefined); + await client.initialize(); + assert(client.publisherStub); + }); + + it('has close method for the initialized client', done => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.publisherStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.publisherStub, undefined); + client.close().then(() => { + done(); + }); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new publisherModule.v1.PublisherClient({ + 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 publisherModule.v1.PublisherClient({ + 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('createTopic', () => { + it('invokes createTopic without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + client.innerApiCalls.createTopic = stubSimpleCall(expectedResponse); + const [response] = await client.createTopic(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createTopic without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + client.innerApiCalls.createTopic = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createTopic( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ITopic|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createTopic with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createTopic = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.createTopic(request), expectedError); + const actualRequest = (client.innerApiCalls.createTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createTopic with closed client', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.createTopic(request), expectedError); + }); + }); + + describe('updateTopic', () => { + it('invokes updateTopic without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateTopicRequest() + ); + request.topic ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); + request.topic.name = defaultValue1; + const expectedHeaderRequestParams = `topic.name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + client.innerApiCalls.updateTopic = stubSimpleCall(expectedResponse); + const [response] = await client.updateTopic(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateTopic without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateTopicRequest() + ); + request.topic ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); + request.topic.name = defaultValue1; + const expectedHeaderRequestParams = `topic.name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + client.innerApiCalls.updateTopic = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateTopic( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ITopic|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateTopic with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateTopicRequest() + ); + request.topic ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); + request.topic.name = defaultValue1; + const expectedHeaderRequestParams = `topic.name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateTopic = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.updateTopic(request), expectedError); + const actualRequest = (client.innerApiCalls.updateTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateTopic with closed client', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateTopicRequest() + ); + request.topic ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); + request.topic.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.updateTopic(request), expectedError); + }); + }); + + describe('publish', () => { + it('invokes publish without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PublishRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.PublishResponse() + ); + client.innerApiCalls.publish = stubSimpleCall(expectedResponse); + const [response] = await client.publish(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.publish as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.publish as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes publish without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PublishRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.PublishResponse() + ); + client.innerApiCalls.publish = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.publish( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.IPublishResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.publish as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.publish as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes publish with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PublishRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.publish = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.publish(request), expectedError); + const actualRequest = (client.innerApiCalls.publish as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.publish as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes publish with closed client', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PublishRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); + request.topic = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.publish(request), expectedError); + }); + }); + + describe('getTopic', () => { + it('invokes getTopic without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + client.innerApiCalls.getTopic = stubSimpleCall(expectedResponse); + const [response] = await client.getTopic(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getTopic without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Topic() + ); + client.innerApiCalls.getTopic = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getTopic( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ITopic|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getTopic with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getTopic = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getTopic(request), expectedError); + const actualRequest = (client.innerApiCalls.getTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getTopic with closed client', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getTopic(request), expectedError); + }); + }); + + describe('deleteTopic', () => { + it('invokes deleteTopic without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteTopic = stubSimpleCall(expectedResponse); + const [response] = await client.deleteTopic(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.deleteTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteTopic without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteTopic = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteTopic( + 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.deleteTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteTopic with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteTopic = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.deleteTopic(request), expectedError); + const actualRequest = (client.innerApiCalls.deleteTopic as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteTopic as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteTopic with closed client', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteTopicRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); + request.topic = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.deleteTopic(request), expectedError); + }); + }); + + describe('detachSubscription', () => { + it('invokes detachSubscription without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DetachSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.DetachSubscriptionResponse() + ); + client.innerApiCalls.detachSubscription = stubSimpleCall(expectedResponse); + const [response] = await client.detachSubscription(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.detachSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.detachSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes detachSubscription without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DetachSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.DetachSubscriptionResponse() + ); + client.innerApiCalls.detachSubscription = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.detachSubscription( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.IDetachSubscriptionResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.detachSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.detachSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes detachSubscription with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DetachSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.detachSubscription = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.detachSubscription(request), expectedError); + const actualRequest = (client.innerApiCalls.detachSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.detachSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes detachSubscription with closed client', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DetachSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.detachSubscription(request), expectedError); + }); + }); + + describe('listTopics', () => { + it('invokes listTopics without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + ]; + client.innerApiCalls.listTopics = stubSimpleCall(expectedResponse); + const [response] = await client.listTopics(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listTopics as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopics as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopics without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + ]; + client.innerApiCalls.listTopics = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listTopics( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ITopic[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listTopics as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopics as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopics with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listTopics = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listTopics(request), expectedError); + const actualRequest = (client.innerApiCalls.listTopics as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopics as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicsStream without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + ]; + client.descriptors.page.listTopics.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listTopicsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Topic[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Topic) => { + 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.listTopics.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listTopics, request)); + assert( + (client.descriptors.page.listTopics.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listTopicsStream with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listTopics.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listTopicsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Topic[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Topic) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listTopics.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listTopics, request)); + assert( + (client.descriptors.page.listTopics.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listTopics without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + generateSampleMessage(new protos.google.pubsub.v1.Topic()), + ]; + client.descriptors.page.listTopics.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.pubsub.v1.ITopic[] = []; + const iterable = client.listTopicsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listTopics.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listTopics.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listTopics with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listTopics.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listTopicsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.pubsub.v1.ITopic[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listTopics.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listTopics.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + + describe('listTopicSubscriptions', () => { + it('invokes listTopicSubscriptions without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; + client.innerApiCalls.listTopicSubscriptions = stubSimpleCall(expectedResponse); + const [response] = await client.listTopicSubscriptions(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listTopicSubscriptions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopicSubscriptions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicSubscriptions without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; + client.innerApiCalls.listTopicSubscriptions = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listTopicSubscriptions( + request, + (err?: Error|null, result?: string[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listTopicSubscriptions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopicSubscriptions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicSubscriptions with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listTopicSubscriptions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listTopicSubscriptions(request), expectedError); + const actualRequest = (client.innerApiCalls.listTopicSubscriptions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopicSubscriptions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicSubscriptionsStream without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = [new String(), new String(), new String()]; + client.descriptors.page.listTopicSubscriptions.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listTopicSubscriptionsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: string[] = []; + stream.on('data', (response: string) => { + 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.listTopicSubscriptions.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listTopicSubscriptions, request)); + assert( + (client.descriptors.page.listTopicSubscriptions.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listTopicSubscriptionsStream with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listTopicSubscriptions.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listTopicSubscriptionsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: string[] = []; + stream.on('data', (response: string) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listTopicSubscriptions.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listTopicSubscriptions, request)); + assert( + (client.descriptors.page.listTopicSubscriptions.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listTopicSubscriptions without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = [new String(), new String(), new String()]; + client.descriptors.page.listTopicSubscriptions.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: string[] = []; + const iterable = client.listTopicSubscriptionsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listTopicSubscriptions with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listTopicSubscriptions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listTopicSubscriptionsAsync(request); + await assert.rejects(async () => { + const responses: string[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + + describe('listTopicSnapshots', () => { + it('invokes listTopicSnapshots without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; + client.innerApiCalls.listTopicSnapshots = stubSimpleCall(expectedResponse); + const [response] = await client.listTopicSnapshots(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listTopicSnapshots as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopicSnapshots as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicSnapshots without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; + client.innerApiCalls.listTopicSnapshots = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listTopicSnapshots( + request, + (err?: Error|null, result?: string[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listTopicSnapshots as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopicSnapshots as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicSnapshots with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listTopicSnapshots = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listTopicSnapshots(request), expectedError); + const actualRequest = (client.innerApiCalls.listTopicSnapshots as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listTopicSnapshots as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listTopicSnapshotsStream without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = [new String(), new String(), new String()]; + client.descriptors.page.listTopicSnapshots.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listTopicSnapshotsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: string[] = []; + stream.on('data', (response: string) => { + 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.listTopicSnapshots.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listTopicSnapshots, request)); + assert( + (client.descriptors.page.listTopicSnapshots.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listTopicSnapshotsStream with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listTopicSnapshots.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listTopicSnapshotsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: string[] = []; + stream.on('data', (response: string) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listTopicSnapshots.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listTopicSnapshots, request)); + assert( + (client.descriptors.page.listTopicSnapshots.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listTopicSnapshots without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedResponse = [new String(), new String(), new String()]; + client.descriptors.page.listTopicSnapshots.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: string[] = []; + const iterable = client.listTopicSnapshotsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listTopicSnapshots with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListTopicSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); + request.topic = defaultValue1; + const expectedHeaderRequestParams = `topic=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listTopicSnapshots.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listTopicSnapshotsAsync(request); + await assert.rejects(async () => { + const responses: string[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + describe('getIamPolicy', () => { + it('invokes getIamPolicy without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.getIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes getIamPolicy without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes getIamPolicy with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('setIamPolicy', () => { + it('invokes setIamPolicy without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.setIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes setIamPolicy without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.setIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes setIamPolicy with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('testIamPermissions', () => { + it('invokes testIamPermissions without error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); + const response = await client.testIamPermissions(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes testIamPermissions without error using callback', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.testIamPermissions( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0)); + }); + it('invokes testIamPermissions with error', async () => { + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('Path templates', () => { + + describe('project', () => { + const fakePath = "/rendered/path/project"; + const expectedParameters = { + project: "projectValue", + }; + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + 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('projectTopic', () => { + const fakePath = "/rendered/path/projectTopic"; + const expectedParameters = { + project: "projectValue", + topic: "topicValue", + }; + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.projectTopicPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.projectTopicPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('projectTopicPath', () => { + const result = client.projectTopicPath("projectValue", "topicValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.projectTopicPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromProjectTopicName', () => { + const result = client.matchProjectFromProjectTopicName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchTopicFromProjectTopicName', () => { + const result = client.matchTopicFromProjectTopicName(fakePath); + assert.strictEqual(result, "topicValue"); + assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('schema', () => { + const fakePath = "/rendered/path/schema"; + const expectedParameters = { + project: "projectValue", + schema: "schemaValue", + }; + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.schemaPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.schemaPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('schemaPath', () => { + const result = client.schemaPath("projectValue", "schemaValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.schemaPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSchemaName', () => { + const result = client.matchProjectFromSchemaName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSchemaFromSchemaName', () => { + const result = client.matchSchemaFromSchemaName(fakePath); + assert.strictEqual(result, "schemaValue"); + assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('snapshot', () => { + const fakePath = "/rendered/path/snapshot"; + const expectedParameters = { + project: "projectValue", + snapshot: "snapshotValue", + }; + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.snapshotPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.snapshotPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('snapshotPath', () => { + const result = client.snapshotPath("projectValue", "snapshotValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.snapshotPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSnapshotName', () => { + const result = client.matchProjectFromSnapshotName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSnapshotFromSnapshotName', () => { + const result = client.matchSnapshotFromSnapshotName(fakePath); + assert.strictEqual(result, "snapshotValue"); + assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('subscription', () => { + const fakePath = "/rendered/path/subscription"; + const expectedParameters = { + project: "projectValue", + subscription: "subscriptionValue", + }; + const client = new publisherModule.v1.PublisherClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.subscriptionPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.subscriptionPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('subscriptionPath', () => { + const result = client.subscriptionPath("projectValue", "subscriptionValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.subscriptionPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSubscriptionName', () => { + const result = client.matchProjectFromSubscriptionName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSubscriptionFromSubscriptionName', () => { + const result = client.matchSubscriptionFromSubscriptionName(fakePath); + assert.strictEqual(result, "subscriptionValue"); + assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + }); +}); diff --git a/owl-bot-staging/v1/test/gapic_schema_service_v1.ts b/owl-bot-staging/v1/test/gapic_schema_service_v1.ts new file mode 100644 index 000000000..517c88cb1 --- /dev/null +++ b/owl-bot-staging/v1/test/gapic_schema_service_v1.ts @@ -0,0 +1,2012 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as schemaserviceModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, IamProtos} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.SchemaServiceClient', () => { + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = schemaserviceModule.v1.SchemaServiceClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = schemaserviceModule.v1.SchemaServiceClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = schemaserviceModule.v1.SchemaServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new schemaserviceModule.v1.SchemaServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.schemaServiceStub, undefined); + await client.initialize(); + assert(client.schemaServiceStub); + }); + + it('has close method for the initialized client', done => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.schemaServiceStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.schemaServiceStub, undefined); + client.close().then(() => { + done(); + }); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new schemaserviceModule.v1.SchemaServiceClient({ + 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 schemaserviceModule.v1.SchemaServiceClient({ + 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('createSchema', () => { + it('invokes createSchema without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.createSchema = stubSimpleCall(expectedResponse); + const [response] = await client.createSchema(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSchema without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.createSchema = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createSchema( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSchema with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createSchema = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.createSchema(request), expectedError); + const actualRequest = (client.innerApiCalls.createSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSchema with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.createSchema(request), expectedError); + }); + }); + + describe('getSchema', () => { + it('invokes getSchema without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.getSchema = stubSimpleCall(expectedResponse); + const [response] = await client.getSchema(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSchema without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.getSchema = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getSchema( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSchema with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getSchema = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getSchema(request), expectedError); + const actualRequest = (client.innerApiCalls.getSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSchema with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getSchema(request), expectedError); + }); + }); + + describe('commitSchema', () => { + it('invokes commitSchema without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CommitSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.commitSchema = stubSimpleCall(expectedResponse); + const [response] = await client.commitSchema(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.commitSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.commitSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes commitSchema without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CommitSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.commitSchema = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.commitSchema( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.commitSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.commitSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes commitSchema with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CommitSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.commitSchema = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.commitSchema(request), expectedError); + const actualRequest = (client.innerApiCalls.commitSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.commitSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes commitSchema with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CommitSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.commitSchema(request), expectedError); + }); + }); + + describe('rollbackSchema', () => { + it('invokes rollbackSchema without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.RollbackSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.rollbackSchema = stubSimpleCall(expectedResponse); + const [response] = await client.rollbackSchema(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.rollbackSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.rollbackSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rollbackSchema without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.RollbackSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.rollbackSchema = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.rollbackSchema( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.rollbackSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.rollbackSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rollbackSchema with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.RollbackSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.rollbackSchema = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.rollbackSchema(request), expectedError); + const actualRequest = (client.innerApiCalls.rollbackSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.rollbackSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes rollbackSchema with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.RollbackSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.rollbackSchema(request), expectedError); + }); + }); + + describe('deleteSchemaRevision', () => { + it('invokes deleteSchemaRevision without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.deleteSchemaRevision = stubSimpleCall(expectedResponse); + const [response] = await client.deleteSchemaRevision(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.deleteSchemaRevision as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSchemaRevision as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSchemaRevision without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Schema() + ); + client.innerApiCalls.deleteSchemaRevision = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteSchemaRevision( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.deleteSchemaRevision as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSchemaRevision as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSchemaRevision with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteSchemaRevision = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.deleteSchemaRevision(request), expectedError); + const actualRequest = (client.innerApiCalls.deleteSchemaRevision as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSchemaRevision as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSchemaRevision with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.deleteSchemaRevision(request), expectedError); + }); + }); + + describe('deleteSchema', () => { + it('invokes deleteSchema without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteSchema = stubSimpleCall(expectedResponse); + const [response] = await client.deleteSchema(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.deleteSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSchema without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteSchema = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteSchema( + 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.deleteSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSchema with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteSchema = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.deleteSchema(request), expectedError); + const actualRequest = (client.innerApiCalls.deleteSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSchema with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.deleteSchema(request), expectedError); + }); + }); + + describe('validateSchema', () => { + it('invokes validateSchema without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.ValidateSchemaResponse() + ); + client.innerApiCalls.validateSchema = stubSimpleCall(expectedResponse); + const [response] = await client.validateSchema(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.validateSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.validateSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes validateSchema without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.ValidateSchemaResponse() + ); + client.innerApiCalls.validateSchema = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.validateSchema( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.IValidateSchemaResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.validateSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.validateSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes validateSchema with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.validateSchema = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.validateSchema(request), expectedError); + const actualRequest = (client.innerApiCalls.validateSchema as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.validateSchema as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes validateSchema with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateSchemaRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.validateSchema(request), expectedError); + }); + }); + + describe('validateMessage', () => { + it('invokes validateMessage without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateMessageRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.ValidateMessageResponse() + ); + client.innerApiCalls.validateMessage = stubSimpleCall(expectedResponse); + const [response] = await client.validateMessage(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.validateMessage as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.validateMessage as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes validateMessage without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateMessageRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.ValidateMessageResponse() + ); + client.innerApiCalls.validateMessage = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.validateMessage( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.IValidateMessageResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.validateMessage as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.validateMessage as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes validateMessage with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateMessageRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.validateMessage = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.validateMessage(request), expectedError); + const actualRequest = (client.innerApiCalls.validateMessage as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.validateMessage as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes validateMessage with closed client', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ValidateMessageRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); + request.parent = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.validateMessage(request), expectedError); + }); + }); + + describe('listSchemas', () => { + it('invokes listSchemas without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.innerApiCalls.listSchemas = stubSimpleCall(expectedResponse); + const [response] = await client.listSchemas(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSchemas as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSchemas as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSchemas without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.innerApiCalls.listSchemas = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listSchemas( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSchemas as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSchemas as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSchemas with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listSchemas = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listSchemas(request), expectedError); + const actualRequest = (client.innerApiCalls.listSchemas as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSchemas as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSchemasStream without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.descriptors.page.listSchemas.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listSchemasStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Schema[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Schema) => { + 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.listSchemas.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSchemas, request)); + assert( + (client.descriptors.page.listSchemas.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listSchemasStream with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSchemas.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listSchemasStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Schema[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Schema) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listSchemas.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSchemas, request)); + assert( + (client.descriptors.page.listSchemas.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSchemas without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.descriptors.page.listSchemas.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.pubsub.v1.ISchema[] = []; + const iterable = client.listSchemasAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listSchemas.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSchemas.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSchemas with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemasRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSchemas.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listSchemasAsync(request); + await assert.rejects(async () => { + const responses: protos.google.pubsub.v1.ISchema[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listSchemas.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSchemas.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + + describe('listSchemaRevisions', () => { + it('invokes listSchemaRevisions without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.innerApiCalls.listSchemaRevisions = stubSimpleCall(expectedResponse); + const [response] = await client.listSchemaRevisions(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSchemaRevisions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSchemaRevisions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSchemaRevisions without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.innerApiCalls.listSchemaRevisions = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listSchemaRevisions( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISchema[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSchemaRevisions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSchemaRevisions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSchemaRevisions with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listSchemaRevisions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listSchemaRevisions(request), expectedError); + const actualRequest = (client.innerApiCalls.listSchemaRevisions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSchemaRevisions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSchemaRevisionsStream without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.descriptors.page.listSchemaRevisions.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listSchemaRevisionsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Schema[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Schema) => { + 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.listSchemaRevisions.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSchemaRevisions, request)); + assert( + (client.descriptors.page.listSchemaRevisions.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listSchemaRevisionsStream with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSchemaRevisions.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listSchemaRevisionsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Schema[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Schema) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listSchemaRevisions.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSchemaRevisions, request)); + assert( + (client.descriptors.page.listSchemaRevisions.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSchemaRevisions without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + generateSampleMessage(new protos.google.pubsub.v1.Schema()), + ]; + client.descriptors.page.listSchemaRevisions.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.pubsub.v1.ISchema[] = []; + const iterable = client.listSchemaRevisionsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSchemaRevisions with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSchemaRevisionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSchemaRevisions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listSchemaRevisionsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.pubsub.v1.ISchema[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + describe('getIamPolicy', () => { + it('invokes getIamPolicy without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.getIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes getIamPolicy without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes getIamPolicy with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('setIamPolicy', () => { + it('invokes setIamPolicy without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.setIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes setIamPolicy without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.setIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes setIamPolicy with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('testIamPermissions', () => { + it('invokes testIamPermissions without error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); + const response = await client.testIamPermissions(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes testIamPermissions without error using callback', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.testIamPermissions( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0)); + }); + it('invokes testIamPermissions with error', async () => { + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('Path templates', () => { + + describe('project', () => { + const fakePath = "/rendered/path/project"; + const expectedParameters = { + project: "projectValue", + }; + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + 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('projectTopic', () => { + const fakePath = "/rendered/path/projectTopic"; + const expectedParameters = { + project: "projectValue", + topic: "topicValue", + }; + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.projectTopicPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.projectTopicPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('projectTopicPath', () => { + const result = client.projectTopicPath("projectValue", "topicValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.projectTopicPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromProjectTopicName', () => { + const result = client.matchProjectFromProjectTopicName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchTopicFromProjectTopicName', () => { + const result = client.matchTopicFromProjectTopicName(fakePath); + assert.strictEqual(result, "topicValue"); + assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('schema', () => { + const fakePath = "/rendered/path/schema"; + const expectedParameters = { + project: "projectValue", + schema: "schemaValue", + }; + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.schemaPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.schemaPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('schemaPath', () => { + const result = client.schemaPath("projectValue", "schemaValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.schemaPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSchemaName', () => { + const result = client.matchProjectFromSchemaName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSchemaFromSchemaName', () => { + const result = client.matchSchemaFromSchemaName(fakePath); + assert.strictEqual(result, "schemaValue"); + assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('snapshot', () => { + const fakePath = "/rendered/path/snapshot"; + const expectedParameters = { + project: "projectValue", + snapshot: "snapshotValue", + }; + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.snapshotPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.snapshotPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('snapshotPath', () => { + const result = client.snapshotPath("projectValue", "snapshotValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.snapshotPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSnapshotName', () => { + const result = client.matchProjectFromSnapshotName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSnapshotFromSnapshotName', () => { + const result = client.matchSnapshotFromSnapshotName(fakePath); + assert.strictEqual(result, "snapshotValue"); + assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('subscription', () => { + const fakePath = "/rendered/path/subscription"; + const expectedParameters = { + project: "projectValue", + subscription: "subscriptionValue", + }; + const client = new schemaserviceModule.v1.SchemaServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.subscriptionPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.subscriptionPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('subscriptionPath', () => { + const result = client.subscriptionPath("projectValue", "subscriptionValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.subscriptionPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSubscriptionName', () => { + const result = client.matchProjectFromSubscriptionName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSubscriptionFromSubscriptionName', () => { + const result = client.matchSubscriptionFromSubscriptionName(fakePath); + assert.strictEqual(result, "subscriptionValue"); + assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + }); +}); diff --git a/owl-bot-staging/v1/test/gapic_subscriber_v1.ts b/owl-bot-staging/v1/test/gapic_subscriber_v1.ts new file mode 100644 index 000000000..d08c709e2 --- /dev/null +++ b/owl-bot-staging/v1/test/gapic_subscriber_v1.ts @@ -0,0 +1,2633 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as subscriberModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, IamProtos} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubBidiStreamingCall(response?: ResponseType, error?: Error) { + const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + return sinon.stub().returns(mockStream); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.SubscriberClient', () => { + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = subscriberModule.v1.SubscriberClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = subscriberModule.v1.SubscriberClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = subscriberModule.v1.SubscriberClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new subscriberModule.v1.SubscriberClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new subscriberModule.v1.SubscriberClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.subscriberStub, undefined); + await client.initialize(); + assert(client.subscriberStub); + }); + + it('has close method for the initialized client', done => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.subscriberStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.subscriberStub, undefined); + client.close().then(() => { + done(); + }); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new subscriberModule.v1.SubscriberClient({ + 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 subscriberModule.v1.SubscriberClient({ + 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('createSubscription', () => { + it('invokes createSubscription without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + client.innerApiCalls.createSubscription = stubSimpleCall(expectedResponse); + const [response] = await client.createSubscription(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSubscription without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + client.innerApiCalls.createSubscription = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createSubscription( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSubscription with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createSubscription = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.createSubscription(request), expectedError); + const actualRequest = (client.innerApiCalls.createSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSubscription with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.createSubscription(request), expectedError); + }); + }); + + describe('getSubscription', () => { + it('invokes getSubscription without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + client.innerApiCalls.getSubscription = stubSimpleCall(expectedResponse); + const [response] = await client.getSubscription(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSubscription without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + client.innerApiCalls.getSubscription = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getSubscription( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSubscription with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getSubscription = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getSubscription(request), expectedError); + const actualRequest = (client.innerApiCalls.getSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSubscription with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getSubscription(request), expectedError); + }); + }); + + describe('updateSubscription', () => { + it('invokes updateSubscription without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSubscriptionRequest() + ); + request.subscription ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); + request.subscription.name = defaultValue1; + const expectedHeaderRequestParams = `subscription.name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + client.innerApiCalls.updateSubscription = stubSimpleCall(expectedResponse); + const [response] = await client.updateSubscription(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateSubscription without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSubscriptionRequest() + ); + request.subscription ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); + request.subscription.name = defaultValue1; + const expectedHeaderRequestParams = `subscription.name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Subscription() + ); + client.innerApiCalls.updateSubscription = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateSubscription( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateSubscription with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSubscriptionRequest() + ); + request.subscription ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); + request.subscription.name = defaultValue1; + const expectedHeaderRequestParams = `subscription.name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateSubscription = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.updateSubscription(request), expectedError); + const actualRequest = (client.innerApiCalls.updateSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateSubscription with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSubscriptionRequest() + ); + request.subscription ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); + request.subscription.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.updateSubscription(request), expectedError); + }); + }); + + describe('deleteSubscription', () => { + it('invokes deleteSubscription without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteSubscription = stubSimpleCall(expectedResponse); + const [response] = await client.deleteSubscription(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.deleteSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSubscription without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteSubscription = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteSubscription( + 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.deleteSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSubscription with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteSubscription = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.deleteSubscription(request), expectedError); + const actualRequest = (client.innerApiCalls.deleteSubscription as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSubscription as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSubscription with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSubscriptionRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.deleteSubscription(request), expectedError); + }); + }); + + describe('modifyAckDeadline', () => { + it('invokes modifyAckDeadline without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyAckDeadlineRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.modifyAckDeadline = stubSimpleCall(expectedResponse); + const [response] = await client.modifyAckDeadline(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.modifyAckDeadline as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.modifyAckDeadline as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes modifyAckDeadline without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyAckDeadlineRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.modifyAckDeadline = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.modifyAckDeadline( + 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.modifyAckDeadline as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.modifyAckDeadline as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes modifyAckDeadline with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyAckDeadlineRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.modifyAckDeadline = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.modifyAckDeadline(request), expectedError); + const actualRequest = (client.innerApiCalls.modifyAckDeadline as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.modifyAckDeadline as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes modifyAckDeadline with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyAckDeadlineRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.modifyAckDeadline(request), expectedError); + }); + }); + + describe('acknowledge', () => { + it('invokes acknowledge without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.AcknowledgeRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.acknowledge = stubSimpleCall(expectedResponse); + const [response] = await client.acknowledge(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.acknowledge as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.acknowledge as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes acknowledge without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.AcknowledgeRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.acknowledge = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.acknowledge( + 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.acknowledge as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.acknowledge as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes acknowledge with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.AcknowledgeRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.acknowledge = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.acknowledge(request), expectedError); + const actualRequest = (client.innerApiCalls.acknowledge as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.acknowledge as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes acknowledge with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.AcknowledgeRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.acknowledge(request), expectedError); + }); + }); + + describe('pull', () => { + it('invokes pull without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PullRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.PullResponse() + ); + client.innerApiCalls.pull = stubSimpleCall(expectedResponse); + const [response] = await client.pull(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.pull as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.pull as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes pull without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PullRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.PullResponse() + ); + client.innerApiCalls.pull = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.pull( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.IPullResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.pull as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.pull as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes pull with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PullRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.pull = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.pull(request), expectedError); + const actualRequest = (client.innerApiCalls.pull as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.pull as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes pull with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.PullRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.pull(request), expectedError); + }); + }); + + describe('modifyPushConfig', () => { + it('invokes modifyPushConfig without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyPushConfigRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.modifyPushConfig = stubSimpleCall(expectedResponse); + const [response] = await client.modifyPushConfig(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.modifyPushConfig as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.modifyPushConfig as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes modifyPushConfig without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyPushConfigRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.modifyPushConfig = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.modifyPushConfig( + 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.modifyPushConfig as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.modifyPushConfig as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes modifyPushConfig with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyPushConfigRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.modifyPushConfig = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.modifyPushConfig(request), expectedError); + const actualRequest = (client.innerApiCalls.modifyPushConfig as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.modifyPushConfig as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes modifyPushConfig with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ModifyPushConfigRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.modifyPushConfig(request), expectedError); + }); + }); + + describe('getSnapshot', () => { + it('invokes getSnapshot without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Snapshot() + ); + client.innerApiCalls.getSnapshot = stubSimpleCall(expectedResponse); + const [response] = await client.getSnapshot(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSnapshot without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Snapshot() + ); + client.innerApiCalls.getSnapshot = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getSnapshot( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSnapshot with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getSnapshot = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getSnapshot(request), expectedError); + const actualRequest = (client.innerApiCalls.getSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getSnapshot with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.GetSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getSnapshot(request), expectedError); + }); + }); + + describe('createSnapshot', () => { + it('invokes createSnapshot without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Snapshot() + ); + client.innerApiCalls.createSnapshot = stubSimpleCall(expectedResponse); + const [response] = await client.createSnapshot(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSnapshot without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Snapshot() + ); + client.innerApiCalls.createSnapshot = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createSnapshot( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.createSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSnapshot with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.createSnapshot = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.createSnapshot(request), expectedError); + const actualRequest = (client.innerApiCalls.createSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.createSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes createSnapshot with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.CreateSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.createSnapshot(request), expectedError); + }); + }); + + describe('updateSnapshot', () => { + it('invokes updateSnapshot without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSnapshotRequest() + ); + request.snapshot ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); + request.snapshot.name = defaultValue1; + const expectedHeaderRequestParams = `snapshot.name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Snapshot() + ); + client.innerApiCalls.updateSnapshot = stubSimpleCall(expectedResponse); + const [response] = await client.updateSnapshot(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateSnapshot without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSnapshotRequest() + ); + request.snapshot ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); + request.snapshot.name = defaultValue1; + const expectedHeaderRequestParams = `snapshot.name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.Snapshot() + ); + client.innerApiCalls.updateSnapshot = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateSnapshot( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateSnapshot with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSnapshotRequest() + ); + request.snapshot ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); + request.snapshot.name = defaultValue1; + const expectedHeaderRequestParams = `snapshot.name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateSnapshot = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.updateSnapshot(request), expectedError); + const actualRequest = (client.innerApiCalls.updateSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateSnapshot with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.UpdateSnapshotRequest() + ); + request.snapshot ??= {}; + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); + request.snapshot.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.updateSnapshot(request), expectedError); + }); + }); + + describe('deleteSnapshot', () => { + it('invokes deleteSnapshot without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteSnapshot = stubSimpleCall(expectedResponse); + const [response] = await client.deleteSnapshot(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.deleteSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSnapshot without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteSnapshot = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deleteSnapshot( + 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.deleteSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSnapshot with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteSnapshot = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.deleteSnapshot(request), expectedError); + const actualRequest = (client.innerApiCalls.deleteSnapshot as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.deleteSnapshot as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes deleteSnapshot with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.DeleteSnapshotRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); + request.snapshot = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.deleteSnapshot(request), expectedError); + }); + }); + + describe('seek', () => { + it('invokes seek without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.SeekRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.SeekResponse() + ); + client.innerApiCalls.seek = stubSimpleCall(expectedResponse); + const [response] = await client.seek(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.seek as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.seek as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes seek without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.SeekRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.SeekResponse() + ); + client.innerApiCalls.seek = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.seek( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISeekResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.seek as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.seek as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes seek with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.SeekRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedHeaderRequestParams = `subscription=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.seek = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.seek(request), expectedError); + const actualRequest = (client.innerApiCalls.seek as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.seek as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes seek with closed client', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.SeekRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); + request.subscription = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.seek(request), expectedError); + }); + }); + + describe('streamingPull', () => { + it('invokes streamingPull without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.StreamingPullRequest() + ); + + const expectedResponse = generateSampleMessage( + new protos.google.pubsub.v1.StreamingPullResponse() + ); + client.innerApiCalls.streamingPull = stubBidiStreamingCall(expectedResponse); + const stream = client.streamingPull(); + const promise = new Promise((resolve, reject) => { + stream.on('data', (response: protos.google.pubsub.v1.StreamingPullResponse) => { + resolve(response); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + stream.write(request); + stream.end(); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.streamingPull as SinonStub) + .getCall(0).calledWith(null)); + assert.deepStrictEqual(((stream as unknown as PassThrough) + ._transform as SinonStub).getCall(0).args[0], request); + }); + + it('invokes streamingPull with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.StreamingPullRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.streamingPull = stubBidiStreamingCall(undefined, expectedError); + const stream = client.streamingPull(); + const promise = new Promise((resolve, reject) => { + stream.on('data', (response: protos.google.pubsub.v1.StreamingPullResponse) => { + resolve(response); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + stream.write(request); + stream.end(); + }); + await assert.rejects(promise, expectedError); + assert((client.innerApiCalls.streamingPull as SinonStub) + .getCall(0).calledWith(null)); + assert.deepStrictEqual(((stream as unknown as PassThrough) + ._transform as SinonStub).getCall(0).args[0], request); + }); + }); + + describe('listSubscriptions', () => { + it('invokes listSubscriptions without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + ]; + client.innerApiCalls.listSubscriptions = stubSimpleCall(expectedResponse); + const [response] = await client.listSubscriptions(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSubscriptions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSubscriptions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSubscriptions without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + ]; + client.innerApiCalls.listSubscriptions = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listSubscriptions( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSubscriptions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSubscriptions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSubscriptions with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listSubscriptions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listSubscriptions(request), expectedError); + const actualRequest = (client.innerApiCalls.listSubscriptions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSubscriptions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSubscriptionsStream without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + ]; + client.descriptors.page.listSubscriptions.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listSubscriptionsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Subscription[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Subscription) => { + 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.listSubscriptions.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSubscriptions, request)); + assert( + (client.descriptors.page.listSubscriptions.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listSubscriptionsStream with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSubscriptions.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listSubscriptionsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Subscription[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Subscription) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listSubscriptions.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSubscriptions, request)); + assert( + (client.descriptors.page.listSubscriptions.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSubscriptions without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + generateSampleMessage(new protos.google.pubsub.v1.Subscription()), + ]; + client.descriptors.page.listSubscriptions.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.pubsub.v1.ISubscription[] = []; + const iterable = client.listSubscriptionsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSubscriptions with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSubscriptionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSubscriptions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listSubscriptionsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.pubsub.v1.ISubscription[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + + describe('listSnapshots', () => { + it('invokes listSnapshots without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + ]; + client.innerApiCalls.listSnapshots = stubSimpleCall(expectedResponse); + const [response] = await client.listSnapshots(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSnapshots as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSnapshots as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSnapshots without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + ]; + client.innerApiCalls.listSnapshots = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listSnapshots( + request, + (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSnapshots as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSnapshots as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSnapshots with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listSnapshots = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listSnapshots(request), expectedError); + const actualRequest = (client.innerApiCalls.listSnapshots as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSnapshots as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSnapshotsStream without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + ]; + client.descriptors.page.listSnapshots.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listSnapshotsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Snapshot[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Snapshot) => { + 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.listSnapshots.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSnapshots, request)); + assert( + (client.descriptors.page.listSnapshots.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listSnapshotsStream with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSnapshots.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listSnapshotsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.pubsub.v1.Snapshot[] = []; + stream.on('data', (response: protos.google.pubsub.v1.Snapshot) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listSnapshots.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSnapshots, request)); + assert( + (client.descriptors.page.listSnapshots.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSnapshots without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), + ]; + client.descriptors.page.listSnapshots.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.pubsub.v1.ISnapshot[] = []; + const iterable = client.listSnapshotsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSnapshots with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.pubsub.v1.ListSnapshotsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); + request.project = defaultValue1; + const expectedHeaderRequestParams = `project=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSnapshots.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listSnapshotsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.pubsub.v1.ISnapshot[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + describe('getIamPolicy', () => { + it('invokes getIamPolicy without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.getIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes getIamPolicy without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes getIamPolicy with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.GetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.getIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('setIamPolicy', () => { + it('invokes setIamPolicy without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.setIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes setIamPolicy without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.setIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes setIamPolicy with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('testIamPermissions', () => { + it('invokes testIamPermissions without error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); + const response = await client.testIamPermissions(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes testIamPermissions without error using callback', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.testIamPermissions( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0)); + }); + it('invokes testIamPermissions with error', async () => { + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('Path templates', () => { + + describe('project', () => { + const fakePath = "/rendered/path/project"; + const expectedParameters = { + project: "projectValue", + }; + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + 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('projectTopic', () => { + const fakePath = "/rendered/path/projectTopic"; + const expectedParameters = { + project: "projectValue", + topic: "topicValue", + }; + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.projectTopicPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.projectTopicPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('projectTopicPath', () => { + const result = client.projectTopicPath("projectValue", "topicValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.projectTopicPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromProjectTopicName', () => { + const result = client.matchProjectFromProjectTopicName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchTopicFromProjectTopicName', () => { + const result = client.matchTopicFromProjectTopicName(fakePath); + assert.strictEqual(result, "topicValue"); + assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('schema', () => { + const fakePath = "/rendered/path/schema"; + const expectedParameters = { + project: "projectValue", + schema: "schemaValue", + }; + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.schemaPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.schemaPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('schemaPath', () => { + const result = client.schemaPath("projectValue", "schemaValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.schemaPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSchemaName', () => { + const result = client.matchProjectFromSchemaName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSchemaFromSchemaName', () => { + const result = client.matchSchemaFromSchemaName(fakePath); + assert.strictEqual(result, "schemaValue"); + assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('snapshot', () => { + const fakePath = "/rendered/path/snapshot"; + const expectedParameters = { + project: "projectValue", + snapshot: "snapshotValue", + }; + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.snapshotPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.snapshotPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('snapshotPath', () => { + const result = client.snapshotPath("projectValue", "snapshotValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.snapshotPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSnapshotName', () => { + const result = client.matchProjectFromSnapshotName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSnapshotFromSnapshotName', () => { + const result = client.matchSnapshotFromSnapshotName(fakePath); + assert.strictEqual(result, "snapshotValue"); + assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('subscription', () => { + const fakePath = "/rendered/path/subscription"; + const expectedParameters = { + project: "projectValue", + subscription: "subscriptionValue", + }; + const client = new subscriberModule.v1.SubscriberClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.subscriptionPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.subscriptionPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('subscriptionPath', () => { + const result = client.subscriptionPath("projectValue", "subscriptionValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.subscriptionPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromSubscriptionName', () => { + const result = client.matchProjectFromSubscriptionName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSubscriptionFromSubscriptionName', () => { + const result = client.matchSubscriptionFromSubscriptionName(fakePath); + assert.strictEqual(result, "subscriptionValue"); + assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + }); +}); diff --git a/owl-bot-staging/v1/tsconfig.json b/owl-bot-staging/v1/tsconfig.json new file mode 100644 index 000000000..c78f1c884 --- /dev/null +++ b/owl-bot-staging/v1/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build", + "resolveJsonModule": true, + "lib": [ + "es2018", + "dom" + ] + }, + "include": [ + "src/*.ts", + "src/**/*.ts", + "test/*.ts", + "test/**/*.ts", + "system-test/*.ts" + ] +} diff --git a/owl-bot-staging/v1/webpack.config.js b/owl-bot-staging/v1/webpack.config.js new file mode 100644 index 000000000..3575e0eba --- /dev/null +++ b/owl-bot-staging/v1/webpack.config.js @@ -0,0 +1,64 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const path = require('path'); + +module.exports = { + entry: './src/index.ts', + output: { + library: 'pubsub', + filename: './pubsub.js', + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + resolve: { + alias: { + '../../../package.json': path.resolve(__dirname, 'package.json'), + }, + extensions: ['.js', '.json', '.ts'], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/ + }, + { + test: /node_modules[\\/]@grpc[\\/]grpc-js/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]grpc/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]retry-request/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]https?-proxy-agent/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]gtoken/, + use: 'null-loader' + }, + ], + }, + mode: 'production', +}; From 78e088b9a5bfd2f974c09c0de9610e36018e5cf8 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 26 Sep 2023 22:53:55 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 16 +- owl-bot-staging/v1/.eslintignore | 7 - owl-bot-staging/v1/.eslintrc.json | 3 - owl-bot-staging/v1/.gitignore | 14 - owl-bot-staging/v1/.jsdoc.js | 55 - owl-bot-staging/v1/.mocharc.js | 33 - owl-bot-staging/v1/.prettierrc.js | 22 - owl-bot-staging/v1/README.md | 1 - owl-bot-staging/v1/package.json | 60 - .../v1/protos/google/pubsub/v1/pubsub.proto | 1591 ---------- .../v1/protos/google/pubsub/v1/schema.proto | 410 --- owl-bot-staging/v1/src/index.ts | 29 - owl-bot-staging/v1/src/v1/index.ts | 21 - owl-bot-staging/v1/src/v1/publisher_client.ts | 1668 ----------- .../v1/src/v1/publisher_client_config.json | 103 - .../v1/src/v1/publisher_proto_list.json | 4 - .../v1/src/v1/schema_service_client.ts | 1615 ---------- .../src/v1/schema_service_client_config.json | 79 - .../v1/src/v1/schema_service_proto_list.json | 4 - .../v1/src/v1/subscriber_client.ts | 2204 -------------- .../v1/src/v1/subscriber_client_config.json | 136 - .../v1/src/v1/subscriber_proto_list.json | 4 - owl-bot-staging/v1/test/gapic_publisher_v1.ts | 2013 ------------- .../v1/test/gapic_schema_service_v1.ts | 2012 ------------- .../v1/test/gapic_subscriber_v1.ts | 2633 ----------------- owl-bot-staging/v1/tsconfig.json | 19 - owl-bot-staging/v1/webpack.config.js | 64 - 27 files changed, 8 insertions(+), 14812 deletions(-) delete mode 100644 owl-bot-staging/v1/.eslintignore delete mode 100644 owl-bot-staging/v1/.eslintrc.json delete mode 100644 owl-bot-staging/v1/.gitignore delete mode 100644 owl-bot-staging/v1/.jsdoc.js delete mode 100644 owl-bot-staging/v1/.mocharc.js delete mode 100644 owl-bot-staging/v1/.prettierrc.js delete mode 100644 owl-bot-staging/v1/README.md delete mode 100644 owl-bot-staging/v1/package.json delete mode 100644 owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto delete mode 100644 owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto delete mode 100644 owl-bot-staging/v1/src/index.ts delete mode 100644 owl-bot-staging/v1/src/v1/index.ts delete mode 100644 owl-bot-staging/v1/src/v1/publisher_client.ts delete mode 100644 owl-bot-staging/v1/src/v1/publisher_client_config.json delete mode 100644 owl-bot-staging/v1/src/v1/publisher_proto_list.json delete mode 100644 owl-bot-staging/v1/src/v1/schema_service_client.ts delete mode 100644 owl-bot-staging/v1/src/v1/schema_service_client_config.json delete mode 100644 owl-bot-staging/v1/src/v1/schema_service_proto_list.json delete mode 100644 owl-bot-staging/v1/src/v1/subscriber_client.ts delete mode 100644 owl-bot-staging/v1/src/v1/subscriber_client_config.json delete mode 100644 owl-bot-staging/v1/src/v1/subscriber_proto_list.json delete mode 100644 owl-bot-staging/v1/test/gapic_publisher_v1.ts delete mode 100644 owl-bot-staging/v1/test/gapic_schema_service_v1.ts delete mode 100644 owl-bot-staging/v1/test/gapic_subscriber_v1.ts delete mode 100644 owl-bot-staging/v1/tsconfig.json delete mode 100644 owl-bot-staging/v1/webpack.config.js diff --git a/README.md b/README.md index ceefb3891..6ae22d7da 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,15 @@ npm install @google-cloud/pubsub ```javascript // Imports the Google Cloud client library -const {PubSub} = require('@google-cloud/pubsub'); +const { PubSub } = require("@google-cloud/pubsub"); async function quickstart( - projectId = 'your-project-id', // Your Google Cloud Platform project ID - topicNameOrId = 'my-topic', // Name for the new topic to create - subscriptionName = 'my-sub' // Name for the new subscription to create +projectId = 'your-project-id', // Your Google Cloud Platform project ID +topicNameOrId = 'my-topic', // Name for the new topic to create +subscriptionName = 'my-sub' // Name for the new subscription to create ) { // Instantiates a client - const pubsub = new PubSub({projectId}); + const pubsub = new PubSub({ projectId }); // Creates a new topic const [topic] = await pubsub.createTopic(topicNameOrId); @@ -84,19 +84,19 @@ async function quickstart( const [subscription] = await topic.createSubscription(subscriptionName); // Receive callbacks for new messages on the subscription - subscription.on('message', message => { + subscription.on('message', (message) => { console.log('Received message:', message.data.toString()); process.exit(0); }); // Receive callbacks for errors on the subscription - subscription.on('error', error => { + subscription.on('error', (error) => { console.error('Received error:', error); process.exit(1); }); // Send a message to the topic - topic.publishMessage({data: Buffer.from('Test message!')}); + topic.publishMessage({ data: Buffer.from('Test message!') }); } ``` diff --git a/owl-bot-staging/v1/.eslintignore b/owl-bot-staging/v1/.eslintignore deleted file mode 100644 index cfc348ec4..000000000 --- a/owl-bot-staging/v1/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -**/node_modules -**/.coverage -build/ -docs/ -protos/ -system-test/ -samples/generated/ diff --git a/owl-bot-staging/v1/.eslintrc.json b/owl-bot-staging/v1/.eslintrc.json deleted file mode 100644 index 782153495..000000000 --- a/owl-bot-staging/v1/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./node_modules/gts" -} diff --git a/owl-bot-staging/v1/.gitignore b/owl-bot-staging/v1/.gitignore deleted file mode 100644 index d4f03a0df..000000000 --- a/owl-bot-staging/v1/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -**/*.log -**/node_modules -/.coverage -/coverage -/.nyc_output -/docs/ -/out/ -/build/ -system-test/secrets.js -system-test/*key.json -*.lock -.DS_Store -package-lock.json -__pycache__ diff --git a/owl-bot-staging/v1/.jsdoc.js b/owl-bot-staging/v1/.jsdoc.js deleted file mode 100644 index 6618d0cc4..000000000 --- a/owl-bot-staging/v1/.jsdoc.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -'use strict'; - -module.exports = { - opts: { - readme: './README.md', - package: './package.json', - template: './node_modules/jsdoc-fresh', - recurse: true, - verbose: true, - destination: './docs/' - }, - plugins: [ - 'plugins/markdown', - 'jsdoc-region-tag' - ], - source: { - excludePattern: '(^|\\/|\\\\)[._]', - include: [ - 'build/src', - 'protos' - ], - includePattern: '\\.js$' - }, - templates: { - copyright: 'Copyright 2023 Google LLC', - includeDate: false, - sourceFiles: false, - systemName: '@google-cloud/pubsub', - theme: 'lumen', - default: { - outputSourceFiles: false - } - }, - markdown: { - idInHeadings: true - } -}; diff --git a/owl-bot-staging/v1/.mocharc.js b/owl-bot-staging/v1/.mocharc.js deleted file mode 100644 index 1a38f257d..000000000 --- a/owl-bot-staging/v1/.mocharc.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/owl-bot-staging/v1/.prettierrc.js b/owl-bot-staging/v1/.prettierrc.js deleted file mode 100644 index 55639e70f..000000000 --- a/owl-bot-staging/v1/.prettierrc.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -module.exports = { - ...require('gts/.prettierrc.json') -} diff --git a/owl-bot-staging/v1/README.md b/owl-bot-staging/v1/README.md deleted file mode 100644 index cdb58308f..000000000 --- a/owl-bot-staging/v1/README.md +++ /dev/null @@ -1 +0,0 @@ -Pubsub: Nodejs Client diff --git a/owl-bot-staging/v1/package.json b/owl-bot-staging/v1/package.json deleted file mode 100644 index 06d5a3816..000000000 --- a/owl-bot-staging/v1/package.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "name": "@google-cloud/pubsub", - "version": "0.1.0", - "description": "Pubsub client for Node.js", - "repository": "googleapis/nodejs-pubsub", - "license": "Apache-2.0", - "author": "Google LLC", - "main": "build/src/index.js", - "files": [ - "build/src", - "build/protos" - ], - "keywords": [ - "google apis client", - "google api client", - "google apis", - "google api", - "google", - "google cloud platform", - "google cloud", - "cloud", - "google pubsub", - "pubsub", - "publisher", - "schema service", - "subscriber" - ], - "scripts": { - "clean": "gts clean", - "compile": "tsc -p . && cp -r protos build/ && minifyProtoJson", - "compile-protos": "compileProtos src", - "docs": "jsdoc -c .jsdoc.js", - "fix": "gts fix", - "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" - }, - "dependencies": { - "google-gax": "^4.0.4" - }, - "devDependencies": { - "@types/mocha": "^10.0.1", - "@types/node": "^18.11.18", - "@types/sinon": "^10.0.17", - "c8": "^8.0.1", - "gapic-tools": "^0.2.0", - "gts": "5.0.1", - "jsdoc": "^4.0.2", - "jsdoc-fresh": "^3.0.0", - "jsdoc-region-tag": "^3.0.0", - "mocha": "^10.2.0", - "pack-n-play": "^1.0.0-2", - "sinon": "^15.2.0", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=v14" - } -} diff --git a/owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto b/owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto deleted file mode 100644 index 4468de178..000000000 --- a/owl-bot-staging/v1/protos/google/pubsub/v1/pubsub.proto +++ /dev/null @@ -1,1591 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.pubsub.v1; - -import "google/api/annotations.proto"; -import "google/api/client.proto"; -import "google/api/field_behavior.proto"; -import "google/api/resource.proto"; -import "google/protobuf/duration.proto"; -import "google/protobuf/empty.proto"; -import "google/protobuf/field_mask.proto"; -import "google/protobuf/timestamp.proto"; -import "google/pubsub/v1/schema.proto"; - -option cc_enable_arenas = true; -option csharp_namespace = "Google.Cloud.PubSub.V1"; -option go_package = "cloud.google.com/go/pubsub/apiv1/pubsubpb;pubsubpb"; -option java_multiple_files = true; -option java_outer_classname = "PubsubProto"; -option java_package = "com.google.pubsub.v1"; -option php_namespace = "Google\\Cloud\\PubSub\\V1"; -option ruby_package = "Google::Cloud::PubSub::V1"; - -// The service that an application uses to manipulate topics, and to send -// messages to a topic. -service Publisher { - option (google.api.default_host) = "pubsub.googleapis.com"; - option (google.api.oauth_scopes) = - "https://www.googleapis.com/auth/cloud-platform," - "https://www.googleapis.com/auth/pubsub"; - - // Creates the given topic with the given name. See the [resource name rules] - // (https://cloud.google.com/pubsub/docs/admin#resource_names). - rpc CreateTopic(Topic) returns (Topic) { - option (google.api.http) = { - put: "/v1/{name=projects/*/topics/*}" - body: "*" - }; - option (google.api.method_signature) = "name"; - } - - // Updates an existing topic. Note that certain properties of a - // topic are not modifiable. - rpc UpdateTopic(UpdateTopicRequest) returns (Topic) { - option (google.api.http) = { - patch: "/v1/{topic.name=projects/*/topics/*}" - body: "*" - }; - option (google.api.method_signature) = "topic,update_mask"; - } - - // Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic - // does not exist. - rpc Publish(PublishRequest) returns (PublishResponse) { - option (google.api.http) = { - post: "/v1/{topic=projects/*/topics/*}:publish" - body: "*" - }; - option (google.api.method_signature) = "topic,messages"; - } - - // Gets the configuration of a topic. - rpc GetTopic(GetTopicRequest) returns (Topic) { - option (google.api.http) = { - get: "/v1/{topic=projects/*/topics/*}" - }; - option (google.api.method_signature) = "topic"; - } - - // Lists matching topics. - rpc ListTopics(ListTopicsRequest) returns (ListTopicsResponse) { - option (google.api.http) = { - get: "/v1/{project=projects/*}/topics" - }; - option (google.api.method_signature) = "project"; - } - - // Lists the names of the attached subscriptions on this topic. - rpc ListTopicSubscriptions(ListTopicSubscriptionsRequest) - returns (ListTopicSubscriptionsResponse) { - option (google.api.http) = { - get: "/v1/{topic=projects/*/topics/*}/subscriptions" - }; - option (google.api.method_signature) = "topic"; - } - - // Lists the names of the snapshots on this topic. Snapshots are used in - // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - // which allow you to manage message acknowledgments in bulk. That is, you can - // set the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. - rpc ListTopicSnapshots(ListTopicSnapshotsRequest) - returns (ListTopicSnapshotsResponse) { - option (google.api.http) = { - get: "/v1/{topic=projects/*/topics/*}/snapshots" - }; - option (google.api.method_signature) = "topic"; - } - - // Deletes the topic with the given name. Returns `NOT_FOUND` if the topic - // does not exist. After a topic is deleted, a new topic may be created with - // the same name; this is an entirely new topic with none of the old - // configuration or subscriptions. Existing subscriptions to this topic are - // not deleted, but their `topic` field is set to `_deleted-topic_`. - rpc DeleteTopic(DeleteTopicRequest) returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v1/{topic=projects/*/topics/*}" - }; - option (google.api.method_signature) = "topic"; - } - - // Detaches a subscription from this topic. All messages retained in the - // subscription are dropped. Subsequent `Pull` and `StreamingPull` requests - // will return FAILED_PRECONDITION. If the subscription is a push - // subscription, pushes to the endpoint will stop. - rpc DetachSubscription(DetachSubscriptionRequest) - returns (DetachSubscriptionResponse) { - option (google.api.http) = { - post: "/v1/{subscription=projects/*/subscriptions/*}:detach" - }; - } -} - -// A policy constraining the storage of messages published to the topic. -message MessageStoragePolicy { - // A list of IDs of GCP regions where messages that are published to the topic - // may be persisted in storage. Messages published by publishers running in - // non-allowed GCP regions (or running outside of GCP altogether) will be - // routed for storage in one of the allowed regions. An empty list means that - // no regions are allowed, and is not a valid configuration. - repeated string allowed_persistence_regions = 1; -} - -// Settings for validating messages published against a schema. -message SchemaSettings { - // Required. The name of the schema that messages published should be - // validated against. Format is `projects/{project}/schemas/{schema}`. The - // value of this field will be `_deleted-schema_` if the schema has been - // deleted. - string schema = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // The encoding of messages validated against `schema`. - Encoding encoding = 2; - - // The minimum (inclusive) revision allowed for validating messages. If empty - // or not present, allow any revision to be validated against last_revision or - // any revision created before. - string first_revision_id = 3; - - // The maximum (inclusive) revision allowed for validating messages. If empty - // or not present, allow any revision to be validated against first_revision - // or any revision created after. - string last_revision_id = 4; -} - -// A topic resource. -message Topic { - option (google.api.resource) = { - type: "pubsub.googleapis.com/Topic" - pattern: "projects/{project}/topics/{topic}" - pattern: "_deleted-topic_" - }; - - // Required. The name of the topic. It must have the format - // `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, - // and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), - // underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent - // signs (`%`). It must be between 3 and 255 characters in length, and it - // must not start with `"goog"`. - string name = 1 [(google.api.field_behavior) = REQUIRED]; - - // See [Creating and managing labels] - // (https://cloud.google.com/pubsub/docs/labels). - map labels = 2; - - // Policy constraining the set of Google Cloud Platform regions where messages - // published to the topic may be stored. If not present, then no constraints - // are in effect. - MessageStoragePolicy message_storage_policy = 3; - - // The resource name of the Cloud KMS CryptoKey to be used to protect access - // to messages published on this topic. - // - // The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`. - string kms_key_name = 5; - - // Settings for validating messages published against a schema. - SchemaSettings schema_settings = 6; - - // Reserved for future use. This field is set only in responses from the - // server; it is ignored if it is set in any requests. - bool satisfies_pzs = 7; - - // Indicates the minimum duration to retain a message after it is published to - // the topic. If this field is set, messages published to the topic in the - // last `message_retention_duration` are always available to subscribers. For - // instance, it allows any attached subscription to [seek to a - // timestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) - // that is up to `message_retention_duration` in the past. If this field is - // not set, message retention is controlled by settings on individual - // subscriptions. Cannot be more than 31 days or less than 10 minutes. - google.protobuf.Duration message_retention_duration = 8; -} - -// A message that is published by publishers and consumed by subscribers. The -// message must contain either a non-empty data field or at least one attribute. -// Note that client libraries represent this object differently -// depending on the language. See the corresponding [client library -// documentation](https://cloud.google.com/pubsub/docs/reference/libraries) for -// more information. See [quotas and limits] -// (https://cloud.google.com/pubsub/quotas) for more information about message -// limits. -message PubsubMessage { - // The message data field. If this field is empty, the message must contain - // at least one attribute. - bytes data = 1; - - // Attributes for this message. If this field is empty, the message must - // contain non-empty data. This can be used to filter messages on the - // subscription. - map attributes = 2; - - // ID of this message, assigned by the server when the message is published. - // Guaranteed to be unique within the topic. This value may be read by a - // subscriber that receives a `PubsubMessage` via a `Pull` call or a push - // delivery. It must not be populated by the publisher in a `Publish` call. - string message_id = 3; - - // The time at which the message was published, populated by the server when - // it receives the `Publish` call. It must not be populated by the - // publisher in a `Publish` call. - google.protobuf.Timestamp publish_time = 4; - - // If non-empty, identifies related messages for which publish order should be - // respected. If a `Subscription` has `enable_message_ordering` set to `true`, - // messages published with the same non-empty `ordering_key` value will be - // delivered to subscribers in the order in which they are received by the - // Pub/Sub system. All `PubsubMessage`s published in a given `PublishRequest` - // must specify the same `ordering_key` value. - // For more information, see [ordering - // messages](https://cloud.google.com/pubsub/docs/ordering). - string ordering_key = 5; -} - -// Request for the GetTopic method. -message GetTopicRequest { - // Required. The name of the topic to get. - // Format is `projects/{project}/topics/{topic}`. - string topic = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; -} - -// Request for the UpdateTopic method. -message UpdateTopicRequest { - // Required. The updated topic object. - Topic topic = 1 [(google.api.field_behavior) = REQUIRED]; - - // Required. Indicates which fields in the provided topic to update. Must be - // specified and non-empty. Note that if `update_mask` contains - // "message_storage_policy" but the `message_storage_policy` is not set in - // the `topic` provided above, then the updated value is determined by the - // policy configured at the project or organization level. - google.protobuf.FieldMask update_mask = 2 - [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the Publish method. -message PublishRequest { - // Required. The messages in the request will be published on this topic. - // Format is `projects/{project}/topics/{topic}`. - string topic = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; - - // Required. The messages to publish. - repeated PubsubMessage messages = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// Response for the `Publish` method. -message PublishResponse { - // The server-assigned ID of each published message, in the same order as - // the messages in the request. IDs are guaranteed to be unique within - // the topic. - repeated string message_ids = 1; -} - -// Request for the `ListTopics` method. -message ListTopicsRequest { - // Required. The name of the project in which to list topics. - // Format is `projects/{project-id}`. - string project = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "cloudresourcemanager.googleapis.com/Project" - } - ]; - - // Maximum number of topics to return. - int32 page_size = 2; - - // The value returned by the last `ListTopicsResponse`; indicates that this is - // a continuation of a prior `ListTopics` call, and that the system should - // return the next page of data. - string page_token = 3; -} - -// Response for the `ListTopics` method. -message ListTopicsResponse { - // The resulting topics. - repeated Topic topics = 1; - - // If not empty, indicates that there may be more topics that match the - // request; this value should be passed in a new `ListTopicsRequest`. - string next_page_token = 2; -} - -// Request for the `ListTopicSubscriptions` method. -message ListTopicSubscriptionsRequest { - // Required. The name of the topic that subscriptions are attached to. - // Format is `projects/{project}/topics/{topic}`. - string topic = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; - - // Maximum number of subscription names to return. - int32 page_size = 2; - - // The value returned by the last `ListTopicSubscriptionsResponse`; indicates - // that this is a continuation of a prior `ListTopicSubscriptions` call, and - // that the system should return the next page of data. - string page_token = 3; -} - -// Response for the `ListTopicSubscriptions` method. -message ListTopicSubscriptionsResponse { - // The names of subscriptions attached to the topic specified in the request. - repeated string subscriptions = 1 [(google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - }]; - - // If not empty, indicates that there may be more subscriptions that match - // the request; this value should be passed in a new - // `ListTopicSubscriptionsRequest` to get more subscriptions. - string next_page_token = 2; -} - -// Request for the `ListTopicSnapshots` method. -message ListTopicSnapshotsRequest { - // Required. The name of the topic that snapshots are attached to. - // Format is `projects/{project}/topics/{topic}`. - string topic = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; - - // Maximum number of snapshot names to return. - int32 page_size = 2; - - // The value returned by the last `ListTopicSnapshotsResponse`; indicates - // that this is a continuation of a prior `ListTopicSnapshots` call, and - // that the system should return the next page of data. - string page_token = 3; -} - -// Response for the `ListTopicSnapshots` method. -message ListTopicSnapshotsResponse { - // The names of the snapshots that match the request. - repeated string snapshots = 1; - - // If not empty, indicates that there may be more snapshots that match - // the request; this value should be passed in a new - // `ListTopicSnapshotsRequest` to get more snapshots. - string next_page_token = 2; -} - -// Request for the `DeleteTopic` method. -message DeleteTopicRequest { - // Required. Name of the topic to delete. - // Format is `projects/{project}/topics/{topic}`. - string topic = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; -} - -// Request for the DetachSubscription method. -message DetachSubscriptionRequest { - // Required. The subscription to detach. - // Format is `projects/{project}/subscriptions/{subscription}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; -} - -// Response for the DetachSubscription method. -// Reserved for future use. -message DetachSubscriptionResponse {} - -// The service that an application uses to manipulate subscriptions and to -// consume messages from a subscription via the `Pull` method or by -// establishing a bi-directional stream using the `StreamingPull` method. -service Subscriber { - option (google.api.default_host) = "pubsub.googleapis.com"; - option (google.api.oauth_scopes) = - "https://www.googleapis.com/auth/cloud-platform," - "https://www.googleapis.com/auth/pubsub"; - - // Creates a subscription to a given topic. See the [resource name rules] - // (https://cloud.google.com/pubsub/docs/admin#resource_names). - // If the subscription already exists, returns `ALREADY_EXISTS`. - // If the corresponding topic doesn't exist, returns `NOT_FOUND`. - // - // If the name is not provided in the request, the server will assign a random - // name for this subscription on the same project as the topic, conforming - // to the [resource name format] - // (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated - // name is populated in the returned Subscription object. Note that for REST - // API requests, you must specify a name in the request. - rpc CreateSubscription(Subscription) returns (Subscription) { - option (google.api.http) = { - put: "/v1/{name=projects/*/subscriptions/*}" - body: "*" - }; - option (google.api.method_signature) = - "name,topic,push_config,ack_deadline_seconds"; - } - - // Gets the configuration details of a subscription. - rpc GetSubscription(GetSubscriptionRequest) returns (Subscription) { - option (google.api.http) = { - get: "/v1/{subscription=projects/*/subscriptions/*}" - }; - option (google.api.method_signature) = "subscription"; - } - - // Updates an existing subscription. Note that certain properties of a - // subscription, such as its topic, are not modifiable. - rpc UpdateSubscription(UpdateSubscriptionRequest) returns (Subscription) { - option (google.api.http) = { - patch: "/v1/{subscription.name=projects/*/subscriptions/*}" - body: "*" - }; - option (google.api.method_signature) = "subscription,update_mask"; - } - - // Lists matching subscriptions. - rpc ListSubscriptions(ListSubscriptionsRequest) - returns (ListSubscriptionsResponse) { - option (google.api.http) = { - get: "/v1/{project=projects/*}/subscriptions" - }; - option (google.api.method_signature) = "project"; - } - - // Deletes an existing subscription. All messages retained in the subscription - // are immediately dropped. Calls to `Pull` after deletion will return - // `NOT_FOUND`. After a subscription is deleted, a new one may be created with - // the same name, but the new one has no association with the old - // subscription or its topic unless the same topic is specified. - rpc DeleteSubscription(DeleteSubscriptionRequest) - returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v1/{subscription=projects/*/subscriptions/*}" - }; - option (google.api.method_signature) = "subscription"; - } - - // Modifies the ack deadline for a specific message. This method is useful - // to indicate that more time is needed to process a message by the - // subscriber, or to make the message available for redelivery if the - // processing was interrupted. Note that this does not modify the - // subscription-level `ackDeadlineSeconds` used for subsequent messages. - rpc ModifyAckDeadline(ModifyAckDeadlineRequest) - returns (google.protobuf.Empty) { - option (google.api.http) = { - post: "/v1/{subscription=projects/*/subscriptions/*}:modifyAckDeadline" - body: "*" - }; - option (google.api.method_signature) = - "subscription,ack_ids,ack_deadline_seconds"; - } - - // Acknowledges the messages associated with the `ack_ids` in the - // `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages - // from the subscription. - // - // Acknowledging a message whose ack deadline has expired may succeed, - // but such a message may be redelivered later. Acknowledging a message more - // than once will not result in an error. - rpc Acknowledge(AcknowledgeRequest) returns (google.protobuf.Empty) { - option (google.api.http) = { - post: "/v1/{subscription=projects/*/subscriptions/*}:acknowledge" - body: "*" - }; - option (google.api.method_signature) = "subscription,ack_ids"; - } - - // Pulls messages from the server. - rpc Pull(PullRequest) returns (PullResponse) { - option (google.api.http) = { - post: "/v1/{subscription=projects/*/subscriptions/*}:pull" - body: "*" - }; - option (google.api.method_signature) = - "subscription,return_immediately,max_messages"; - option (google.api.method_signature) = "subscription,max_messages"; - } - - // Establishes a stream with the server, which sends messages down to the - // client. The client streams acknowledgements and ack deadline modifications - // back to the server. The server will close the stream and return the status - // on any error. The server may close the stream with status `UNAVAILABLE` to - // reassign server-side resources, in which case, the client should - // re-establish the stream. Flow control can be achieved by configuring the - // underlying RPC channel. - rpc StreamingPull(stream StreamingPullRequest) - returns (stream StreamingPullResponse) {} - - // Modifies the `PushConfig` for a specified subscription. - // - // This may be used to change a push subscription to a pull one (signified by - // an empty `PushConfig`) or vice versa, or change the endpoint URL and other - // attributes of a push subscription. Messages will accumulate for delivery - // continuously through the call regardless of changes to the `PushConfig`. - rpc ModifyPushConfig(ModifyPushConfigRequest) - returns (google.protobuf.Empty) { - option (google.api.http) = { - post: "/v1/{subscription=projects/*/subscriptions/*}:modifyPushConfig" - body: "*" - }; - option (google.api.method_signature) = "subscription,push_config"; - } - - // Gets the configuration details of a snapshot. Snapshots are used in - // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - // which allow you to manage message acknowledgments in bulk. That is, you can - // set the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. - rpc GetSnapshot(GetSnapshotRequest) returns (Snapshot) { - option (google.api.http) = { - get: "/v1/{snapshot=projects/*/snapshots/*}" - }; - option (google.api.method_signature) = "snapshot"; - } - - // Lists the existing snapshots. Snapshots are used in [Seek]( - // https://cloud.google.com/pubsub/docs/replay-overview) operations, which - // allow you to manage message acknowledgments in bulk. That is, you can set - // the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. - rpc ListSnapshots(ListSnapshotsRequest) returns (ListSnapshotsResponse) { - option (google.api.http) = { - get: "/v1/{project=projects/*}/snapshots" - }; - option (google.api.method_signature) = "project"; - } - - // Creates a snapshot from the requested subscription. Snapshots are used in - // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - // which allow you to manage message acknowledgments in bulk. That is, you can - // set the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. - // If the snapshot already exists, returns `ALREADY_EXISTS`. - // If the requested subscription doesn't exist, returns `NOT_FOUND`. - // If the backlog in the subscription is too old -- and the resulting snapshot - // would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. - // See also the `Snapshot.expire_time` field. If the name is not provided in - // the request, the server will assign a random - // name for this snapshot on the same project as the subscription, conforming - // to the [resource name format] - // (https://cloud.google.com/pubsub/docs/admin#resource_names). The - // generated name is populated in the returned Snapshot object. Note that for - // REST API requests, you must specify a name in the request. - rpc CreateSnapshot(CreateSnapshotRequest) returns (Snapshot) { - option (google.api.http) = { - put: "/v1/{name=projects/*/snapshots/*}" - body: "*" - }; - option (google.api.method_signature) = "name,subscription"; - } - - // Updates an existing snapshot. Snapshots are used in - // [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - // which allow you to manage message acknowledgments in bulk. That is, you can - // set the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. - rpc UpdateSnapshot(UpdateSnapshotRequest) returns (Snapshot) { - option (google.api.http) = { - patch: "/v1/{snapshot.name=projects/*/snapshots/*}" - body: "*" - }; - option (google.api.method_signature) = "snapshot,update_mask"; - } - - // Removes an existing snapshot. Snapshots are used in [Seek] - // (https://cloud.google.com/pubsub/docs/replay-overview) operations, which - // allow you to manage message acknowledgments in bulk. That is, you can set - // the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. - // When the snapshot is deleted, all messages retained in the snapshot - // are immediately dropped. After a snapshot is deleted, a new one may be - // created with the same name, but the new one has no association with the old - // snapshot or its subscription, unless the same subscription is specified. - rpc DeleteSnapshot(DeleteSnapshotRequest) returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v1/{snapshot=projects/*/snapshots/*}" - }; - option (google.api.method_signature) = "snapshot"; - } - - // Seeks an existing subscription to a point in time or to a given snapshot, - // whichever is provided in the request. Snapshots are used in [Seek] - // (https://cloud.google.com/pubsub/docs/replay-overview) operations, which - // allow you to manage message acknowledgments in bulk. That is, you can set - // the acknowledgment state of messages in an existing subscription to the - // state captured by a snapshot. Note that both the subscription and the - // snapshot must be on the same topic. - rpc Seek(SeekRequest) returns (SeekResponse) { - option (google.api.http) = { - post: "/v1/{subscription=projects/*/subscriptions/*}:seek" - body: "*" - }; - } -} - -// A subscription resource. If none of `push_config`, `bigquery_config`, or -// `cloud_storage_config` is set, then the subscriber will pull and ack messages -// using API methods. At most one of these fields may be set. -message Subscription { - option (google.api.resource) = { - type: "pubsub.googleapis.com/Subscription" - pattern: "projects/{project}/subscriptions/{subscription}" - }; - - // Possible states for a subscription. - enum State { - // Default value. This value is unused. - STATE_UNSPECIFIED = 0; - - // The subscription can actively receive messages - ACTIVE = 1; - - // The subscription cannot receive messages because of an error with the - // resource to which it pushes messages. See the more detailed error state - // in the corresponding configuration. - RESOURCE_ERROR = 2; - } - - // Required. The name of the subscription. It must have the format - // `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must - // start with a letter, and contain only letters (`[A-Za-z]`), numbers - // (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), - // plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters - // in length, and it must not start with `"goog"`. - string name = 1 [(google.api.field_behavior) = REQUIRED]; - - // Required. The name of the topic from which this subscription is receiving - // messages. Format is `projects/{project}/topics/{topic}`. The value of this - // field will be `_deleted-topic_` if the topic has been deleted. - string topic = 2 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; - - // If push delivery is used with this subscription, this field is - // used to configure it. - PushConfig push_config = 4; - - // If delivery to BigQuery is used with this subscription, this field is - // used to configure it. - BigQueryConfig bigquery_config = 18; - - // If delivery to Google Cloud Storage is used with this subscription, this - // field is used to configure it. - CloudStorageConfig cloud_storage_config = 22; - - // The approximate amount of time (on a best-effort basis) Pub/Sub waits for - // the subscriber to acknowledge receipt before resending the message. In the - // interval after the message is delivered and before it is acknowledged, it - // is considered to be _outstanding_. During that time period, the - // message will not be redelivered (on a best-effort basis). - // - // For pull subscriptions, this value is used as the initial value for the ack - // deadline. To override this value for a given message, call - // `ModifyAckDeadline` with the corresponding `ack_id` if using - // non-streaming pull or send the `ack_id` in a - // `StreamingModifyAckDeadlineRequest` if using streaming pull. - // The minimum custom deadline you can specify is 10 seconds. - // The maximum custom deadline you can specify is 600 seconds (10 minutes). - // If this parameter is 0, a default value of 10 seconds is used. - // - // For push delivery, this value is also used to set the request timeout for - // the call to the push endpoint. - // - // If the subscriber never acknowledges the message, the Pub/Sub - // system will eventually redeliver the message. - int32 ack_deadline_seconds = 5; - - // Indicates whether to retain acknowledged messages. If true, then - // messages are not expunged from the subscription's backlog, even if they are - // acknowledged, until they fall out of the `message_retention_duration` - // window. This must be true if you would like to [`Seek` to a timestamp] - // (https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) in - // the past to replay previously-acknowledged messages. - bool retain_acked_messages = 7; - - // How long to retain unacknowledged messages in the subscription's backlog, - // from the moment a message is published. - // If `retain_acked_messages` is true, then this also configures the retention - // of acknowledged messages, and thus configures how far back in time a `Seek` - // can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 - // minutes. - google.protobuf.Duration message_retention_duration = 8; - - // See [Creating and managing - // labels](https://cloud.google.com/pubsub/docs/labels). - map labels = 9; - - // If true, messages published with the same `ordering_key` in `PubsubMessage` - // will be delivered to the subscribers in the order in which they - // are received by the Pub/Sub system. Otherwise, they may be delivered in - // any order. - bool enable_message_ordering = 10; - - // A policy that specifies the conditions for this subscription's expiration. - // A subscription is considered active as long as any connected subscriber is - // successfully consuming messages from the subscription or is issuing - // operations on the subscription. If `expiration_policy` is not set, a - // *default policy* with `ttl` of 31 days will be used. The minimum allowed - // value for `expiration_policy.ttl` is 1 day. If `expiration_policy` is set, - // but `expiration_policy.ttl` is not set, the subscription never expires. - ExpirationPolicy expiration_policy = 11; - - // An expression written in the Pub/Sub [filter - // language](https://cloud.google.com/pubsub/docs/filtering). If non-empty, - // then only `PubsubMessage`s whose `attributes` field matches the filter are - // delivered on this subscription. If empty, then no messages are filtered - // out. - string filter = 12; - - // A policy that specifies the conditions for dead lettering messages in - // this subscription. If dead_letter_policy is not set, dead lettering - // is disabled. - // - // The Cloud Pub/Sub service account associated with this subscriptions's - // parent project (i.e., - // service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have - // permission to Acknowledge() messages on this subscription. - DeadLetterPolicy dead_letter_policy = 13; - - // A policy that specifies how Pub/Sub retries message delivery for this - // subscription. - // - // If not set, the default retry policy is applied. This generally implies - // that messages will be retried as soon as possible for healthy subscribers. - // RetryPolicy will be triggered on NACKs or acknowledgement deadline - // exceeded events for a given message. - RetryPolicy retry_policy = 14; - - // Indicates whether the subscription is detached from its topic. Detached - // subscriptions don't receive messages from their topic and don't retain any - // backlog. `Pull` and `StreamingPull` requests will return - // FAILED_PRECONDITION. If the subscription is a push subscription, pushes to - // the endpoint will not be made. - bool detached = 15; - - // If true, Pub/Sub provides the following guarantees for the delivery of - // a message with a given value of `message_id` on this subscription: - // - // * The message sent to a subscriber is guaranteed not to be resent - // before the message's acknowledgement deadline expires. - // * An acknowledged message will not be resent to a subscriber. - // - // Note that subscribers may still receive multiple copies of a message - // when `enable_exactly_once_delivery` is true if the message was published - // multiple times by a publisher client. These copies are considered distinct - // by Pub/Sub and have distinct `message_id` values. - bool enable_exactly_once_delivery = 16; - - // Output only. Indicates the minimum duration for which a message is retained - // after it is published to the subscription's topic. If this field is set, - // messages published to the subscription's topic in the last - // `topic_message_retention_duration` are always available to subscribers. See - // the `message_retention_duration` field in `Topic`. This field is set only - // in responses from the server; it is ignored if it is set in any requests. - google.protobuf.Duration topic_message_retention_duration = 17 - [(google.api.field_behavior) = OUTPUT_ONLY]; - - // Output only. An output-only field indicating whether or not the - // subscription can receive messages. - State state = 19 [(google.api.field_behavior) = OUTPUT_ONLY]; -} - -// A policy that specifies how Cloud Pub/Sub retries message delivery. -// -// Retry delay will be exponential based on provided minimum and maximum -// backoffs. https://en.wikipedia.org/wiki/Exponential_backoff. -// -// RetryPolicy will be triggered on NACKs or acknowledgement deadline exceeded -// events for a given message. -// -// Retry Policy is implemented on a best effort basis. At times, the delay -// between consecutive deliveries may not match the configuration. That is, -// delay can be more or less than configured backoff. -message RetryPolicy { - // The minimum delay between consecutive deliveries of a given message. - // Value should be between 0 and 600 seconds. Defaults to 10 seconds. - google.protobuf.Duration minimum_backoff = 1; - - // The maximum delay between consecutive deliveries of a given message. - // Value should be between 0 and 600 seconds. Defaults to 600 seconds. - google.protobuf.Duration maximum_backoff = 2; -} - -// Dead lettering is done on a best effort basis. The same message might be -// dead lettered multiple times. -// -// If validation on any of the fields fails at subscription creation/updation, -// the create/update subscription request will fail. -message DeadLetterPolicy { - // The name of the topic to which dead letter messages should be published. - // Format is `projects/{project}/topics/{topic}`.The Cloud Pub/Sub service - // account associated with the enclosing subscription's parent project (i.e., - // service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have - // permission to Publish() to this topic. - // - // The operation will fail if the topic does not exist. - // Users should ensure that there is a subscription attached to this topic - // since messages published to a topic with no subscriptions are lost. - string dead_letter_topic = 1; - - // The maximum number of delivery attempts for any message. The value must be - // between 5 and 100. - // - // The number of delivery attempts is defined as 1 + (the sum of number of - // NACKs and number of times the acknowledgement deadline has been exceeded - // for the message). - // - // A NACK is any call to ModifyAckDeadline with a 0 deadline. Note that - // client libraries may automatically extend ack_deadlines. - // - // This field will be honored on a best effort basis. - // - // If this parameter is 0, a default value of 5 is used. - int32 max_delivery_attempts = 2; -} - -// A policy that specifies the conditions for resource expiration (i.e., -// automatic resource deletion). -message ExpirationPolicy { - // Specifies the "time-to-live" duration for an associated resource. The - // resource expires if it is not active for a period of `ttl`. The definition - // of "activity" depends on the type of the associated resource. The minimum - // and maximum allowed values for `ttl` depend on the type of the associated - // resource, as well. If `ttl` is not set, the associated resource never - // expires. - google.protobuf.Duration ttl = 1; -} - -// Configuration for a push delivery endpoint. -message PushConfig { - // Contains information needed for generating an - // [OpenID Connect - // token](https://developers.google.com/identity/protocols/OpenIDConnect). - message OidcToken { - // [Service account - // email](https://cloud.google.com/iam/docs/service-accounts) - // used for generating the OIDC token. For more information - // on setting up authentication, see - // [Push subscriptions](https://cloud.google.com/pubsub/docs/push). - string service_account_email = 1; - - // Audience to be used when generating OIDC token. The audience claim - // identifies the recipients that the JWT is intended for. The audience - // value is a single case-sensitive string. Having multiple values (array) - // for the audience field is not supported. More info about the OIDC JWT - // token audience here: https://tools.ietf.org/html/rfc7519#section-4.1.3 - // Note: if not specified, the Push endpoint URL will be used. - string audience = 2; - } - - // The payload to the push endpoint is in the form of the JSON representation - // of a PubsubMessage - // (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). - message PubsubWrapper {} - - // Sets the `data` field as the HTTP body for delivery. - message NoWrapper { - // When true, writes the Pub/Sub message metadata to - // `x-goog-pubsub-:` headers of the HTTP request. Writes the - // Pub/Sub message attributes to `:` headers of the HTTP request. - bool write_metadata = 1; - } - - // A URL locating the endpoint to which messages should be pushed. - // For example, a Webhook endpoint might use `https://example.com/push`. - string push_endpoint = 1; - - // Endpoint configuration attributes that can be used to control different - // aspects of the message delivery. - // - // The only currently supported attribute is `x-goog-version`, which you can - // use to change the format of the pushed message. This attribute - // indicates the version of the data expected by the endpoint. This - // controls the shape of the pushed message (i.e., its fields and metadata). - // - // If not present during the `CreateSubscription` call, it will default to - // the version of the Pub/Sub API used to make such call. If not present in a - // `ModifyPushConfig` call, its value will not be changed. `GetSubscription` - // calls will always return a valid version, even if the subscription was - // created without this attribute. - // - // The only supported values for the `x-goog-version` attribute are: - // - // * `v1beta1`: uses the push format defined in the v1beta1 Pub/Sub API. - // * `v1` or `v1beta2`: uses the push format defined in the v1 Pub/Sub API. - // - // For example: - // `attributes { "x-goog-version": "v1" }` - map attributes = 2; - - // An authentication method used by push endpoints to verify the source of - // push requests. This can be used with push endpoints that are private by - // default to allow requests only from the Cloud Pub/Sub system, for example. - // This field is optional and should be set only by users interested in - // authenticated push. - oneof authentication_method { - // If specified, Pub/Sub will generate and attach an OIDC JWT token as an - // `Authorization` header in the HTTP request for every pushed message. - OidcToken oidc_token = 3; - } - - // The format of the delivered message to the push endpoint is defined by - // the chosen wrapper. When unset, `PubsubWrapper` is used. - oneof wrapper { - // When set, the payload to the push endpoint is in the form of the JSON - // representation of a PubsubMessage - // (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage). - PubsubWrapper pubsub_wrapper = 4; - - // When set, the payload to the push endpoint is not wrapped. - NoWrapper no_wrapper = 5; - } -} - -// Configuration for a BigQuery subscription. -message BigQueryConfig { - // Possible states for a BigQuery subscription. - enum State { - // Default value. This value is unused. - STATE_UNSPECIFIED = 0; - - // The subscription can actively send messages to BigQuery - ACTIVE = 1; - - // Cannot write to the BigQuery table because of permission denied errors. - // This can happen if - // - Pub/Sub SA has not been granted the [appropriate BigQuery IAM - // permissions](https://cloud.google.com/pubsub/docs/create-subscription#assign_bigquery_service_account) - // - bigquery.googleapis.com API is not enabled for the project - // ([instructions](https://cloud.google.com/service-usage/docs/enable-disable)) - PERMISSION_DENIED = 2; - - // Cannot write to the BigQuery table because it does not exist. - NOT_FOUND = 3; - - // Cannot write to the BigQuery table due to a schema mismatch. - SCHEMA_MISMATCH = 4; - } - - // The name of the table to which to write data, of the form - // {projectId}.{datasetId}.{tableId} - string table = 1; - - // When true, use the topic's schema as the columns to write to in BigQuery, - // if it exists. - bool use_topic_schema = 2; - - // When true, write the subscription name, message_id, publish_time, - // attributes, and ordering_key to additional columns in the table. The - // subscription name, message_id, and publish_time fields are put in their own - // columns while all other message properties (other than data) are written to - // a JSON object in the attributes column. - bool write_metadata = 3; - - // When true and use_topic_schema is true, any fields that are a part of the - // topic schema that are not part of the BigQuery table schema are dropped - // when writing to BigQuery. Otherwise, the schemas must be kept in sync and - // any messages with extra fields are not written and remain in the - // subscription's backlog. - bool drop_unknown_fields = 4; - - // Output only. An output-only field that indicates whether or not the - // subscription can receive messages. - State state = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; -} - -// Configuration for a Cloud Storage subscription. -message CloudStorageConfig { - // Configuration for writing message data in text format. - // Message payloads will be written to files as raw text, separated by a - // newline. - message TextConfig {} - - // Configuration for writing message data in Avro format. - // Message payloads and metadata will be written to files as an Avro binary. - message AvroConfig { - // When true, write the subscription name, message_id, publish_time, - // attributes, and ordering_key as additional fields in the output. The - // subscription name, message_id, and publish_time fields are put in their - // own fields while all other message properties other than data (for - // example, an ordering_key, if present) are added as entries in the - // attributes map. - bool write_metadata = 1; - } - - // Possible states for a Cloud Storage subscription. - enum State { - // Default value. This value is unused. - STATE_UNSPECIFIED = 0; - - // The subscription can actively send messages to Cloud Storage. - ACTIVE = 1; - - // Cannot write to the Cloud Storage bucket because of permission denied - // errors. - PERMISSION_DENIED = 2; - - // Cannot write to the Cloud Storage bucket because it does not exist. - NOT_FOUND = 3; - } - - // Required. User-provided name for the Cloud Storage bucket. - // The bucket must be created by the user. The bucket name must be without - // any prefix like "gs://". See the [bucket naming - // requirements] (https://cloud.google.com/storage/docs/buckets#naming). - string bucket = 1 [(google.api.field_behavior) = REQUIRED]; - - // User-provided prefix for Cloud Storage filename. See the [object naming - // requirements](https://cloud.google.com/storage/docs/objects#naming). - string filename_prefix = 2; - - // User-provided suffix for Cloud Storage filename. See the [object naming - // requirements](https://cloud.google.com/storage/docs/objects#naming). Must - // not end in "/". - string filename_suffix = 3; - - // Defaults to text format. - oneof output_format { - // If set, message data will be written to Cloud Storage in text format. - TextConfig text_config = 4; - - // If set, message data will be written to Cloud Storage in Avro format. - AvroConfig avro_config = 5; - } - - // The maximum duration that can elapse before a new Cloud Storage file is - // created. Min 1 minute, max 10 minutes, default 5 minutes. May not exceed - // the subscription's acknowledgement deadline. - google.protobuf.Duration max_duration = 6; - - // The maximum bytes that can be written to a Cloud Storage file before a new - // file is created. Min 1 KB, max 10 GiB. The max_bytes limit may be exceeded - // in cases where messages are larger than the limit. - int64 max_bytes = 7; - - // Output only. An output-only field that indicates whether or not the - // subscription can receive messages. - State state = 9 [(google.api.field_behavior) = OUTPUT_ONLY]; -} - -// A message and its corresponding acknowledgment ID. -message ReceivedMessage { - // This ID can be used to acknowledge the received message. - string ack_id = 1; - - // The message. - PubsubMessage message = 2; - - // The approximate number of times that Cloud Pub/Sub has attempted to deliver - // the associated message to a subscriber. - // - // More precisely, this is 1 + (number of NACKs) + - // (number of ack_deadline exceeds) for this message. - // - // A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline - // exceeds event is whenever a message is not acknowledged within - // ack_deadline. Note that ack_deadline is initially - // Subscription.ackDeadlineSeconds, but may get extended automatically by - // the client library. - // - // Upon the first delivery of a given message, `delivery_attempt` will have a - // value of 1. The value is calculated at best effort and is approximate. - // - // If a DeadLetterPolicy is not set on the subscription, this will be 0. - int32 delivery_attempt = 3; -} - -// Request for the GetSubscription method. -message GetSubscriptionRequest { - // Required. The name of the subscription to get. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; -} - -// Request for the UpdateSubscription method. -message UpdateSubscriptionRequest { - // Required. The updated subscription object. - Subscription subscription = 1 [(google.api.field_behavior) = REQUIRED]; - - // Required. Indicates which fields in the provided subscription to update. - // Must be specified and non-empty. - google.protobuf.FieldMask update_mask = 2 - [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the `ListSubscriptions` method. -message ListSubscriptionsRequest { - // Required. The name of the project in which to list subscriptions. - // Format is `projects/{project-id}`. - string project = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "cloudresourcemanager.googleapis.com/Project" - } - ]; - - // Maximum number of subscriptions to return. - int32 page_size = 2; - - // The value returned by the last `ListSubscriptionsResponse`; indicates that - // this is a continuation of a prior `ListSubscriptions` call, and that the - // system should return the next page of data. - string page_token = 3; -} - -// Response for the `ListSubscriptions` method. -message ListSubscriptionsResponse { - // The subscriptions that match the request. - repeated Subscription subscriptions = 1; - - // If not empty, indicates that there may be more subscriptions that match - // the request; this value should be passed in a new - // `ListSubscriptionsRequest` to get more subscriptions. - string next_page_token = 2; -} - -// Request for the DeleteSubscription method. -message DeleteSubscriptionRequest { - // Required. The subscription to delete. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; -} - -// Request for the ModifyPushConfig method. -message ModifyPushConfigRequest { - // Required. The name of the subscription. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - // Required. The push configuration for future deliveries. - // - // An empty `pushConfig` indicates that the Pub/Sub system should - // stop pushing messages from the given subscription and allow - // messages to be pulled and acknowledged - effectively pausing - // the subscription if `Pull` or `StreamingPull` is not called. - PushConfig push_config = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the `Pull` method. -message PullRequest { - // Required. The subscription from which messages should be pulled. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - // Optional. If this field set to true, the system will respond immediately - // even if it there are no messages available to return in the `Pull` - // response. Otherwise, the system may wait (for a bounded amount of time) - // until at least one message is available, rather than returning no messages. - // Warning: setting this field to `true` is discouraged because it adversely - // impacts the performance of `Pull` operations. We recommend that users do - // not set this field. - bool return_immediately = 2 - [deprecated = true, (google.api.field_behavior) = OPTIONAL]; - - // Required. The maximum number of messages to return for this request. Must - // be a positive integer. The Pub/Sub system may return fewer than the number - // specified. - int32 max_messages = 3 [(google.api.field_behavior) = REQUIRED]; -} - -// Response for the `Pull` method. -message PullResponse { - // Received Pub/Sub messages. The list will be empty if there are no more - // messages available in the backlog, or if no messages could be returned - // before the request timeout. For JSON, the response can be entirely - // empty. The Pub/Sub system may return fewer than the `maxMessages` requested - // even if there are more messages available in the backlog. - repeated ReceivedMessage received_messages = 1; -} - -// Request for the ModifyAckDeadline method. -message ModifyAckDeadlineRequest { - // Required. The name of the subscription. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - // Required. List of acknowledgment IDs. - repeated string ack_ids = 4 [(google.api.field_behavior) = REQUIRED]; - - // Required. The new ack deadline with respect to the time this request was - // sent to the Pub/Sub system. For example, if the value is 10, the new ack - // deadline will expire 10 seconds after the `ModifyAckDeadline` call was - // made. Specifying zero might immediately make the message available for - // delivery to another subscriber client. This typically results in an - // increase in the rate of message redeliveries (that is, duplicates). - // The minimum deadline you can specify is 0 seconds. - // The maximum deadline you can specify is 600 seconds (10 minutes). - int32 ack_deadline_seconds = 3 [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the Acknowledge method. -message AcknowledgeRequest { - // Required. The subscription whose message is being acknowledged. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - // Required. The acknowledgment ID for the messages being acknowledged that - // was returned by the Pub/Sub system in the `Pull` response. Must not be - // empty. - repeated string ack_ids = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the `StreamingPull` streaming RPC method. This request is used to -// establish the initial stream as well as to stream acknowledgements and ack -// deadline modifications from the client to the server. -message StreamingPullRequest { - // Required. The subscription for which to initialize the new stream. This - // must be provided in the first request on the stream, and must not be set in - // subsequent requests from client to server. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - // List of acknowledgement IDs for acknowledging previously received messages - // (received on this stream or a different stream). If an ack ID has expired, - // the corresponding message may be redelivered later. Acknowledging a message - // more than once will not result in an error. If the acknowledgement ID is - // malformed, the stream will be aborted with status `INVALID_ARGUMENT`. - repeated string ack_ids = 2; - - // The list of new ack deadlines for the IDs listed in - // `modify_deadline_ack_ids`. The size of this list must be the same as the - // size of `modify_deadline_ack_ids`. If it differs the stream will be aborted - // with `INVALID_ARGUMENT`. Each element in this list is applied to the - // element in the same position in `modify_deadline_ack_ids`. The new ack - // deadline is with respect to the time this request was sent to the Pub/Sub - // system. Must be >= 0. For example, if the value is 10, the new ack deadline - // will expire 10 seconds after this request is received. If the value is 0, - // the message is immediately made available for another streaming or - // non-streaming pull request. If the value is < 0 (an error), the stream will - // be aborted with status `INVALID_ARGUMENT`. - repeated int32 modify_deadline_seconds = 3; - - // List of acknowledgement IDs whose deadline will be modified based on the - // corresponding element in `modify_deadline_seconds`. This field can be used - // to indicate that more time is needed to process a message by the - // subscriber, or to make the message available for redelivery if the - // processing was interrupted. - repeated string modify_deadline_ack_ids = 4; - - // Required. The ack deadline to use for the stream. This must be provided in - // the first request on the stream, but it can also be updated on subsequent - // requests from client to server. The minimum deadline you can specify is 10 - // seconds. The maximum deadline you can specify is 600 seconds (10 minutes). - int32 stream_ack_deadline_seconds = 5 - [(google.api.field_behavior) = REQUIRED]; - - // A unique identifier that is used to distinguish client instances from each - // other. Only needs to be provided on the initial request. When a stream - // disconnects and reconnects for the same stream, the client_id should be set - // to the same value so that state associated with the old stream can be - // transferred to the new stream. The same client_id should not be used for - // different client instances. - string client_id = 6; - - // Flow control settings for the maximum number of outstanding messages. When - // there are `max_outstanding_messages` or more currently sent to the - // streaming pull client that have not yet been acked or nacked, the server - // stops sending more messages. The sending of messages resumes once the - // number of outstanding messages is less than this value. If the value is - // <= 0, there is no limit to the number of outstanding messages. This - // property can only be set on the initial StreamingPullRequest. If it is set - // on a subsequent request, the stream will be aborted with status - // `INVALID_ARGUMENT`. - int64 max_outstanding_messages = 7; - - // Flow control settings for the maximum number of outstanding bytes. When - // there are `max_outstanding_bytes` or more worth of messages currently sent - // to the streaming pull client that have not yet been acked or nacked, the - // server will stop sending more messages. The sending of messages resumes - // once the number of outstanding bytes is less than this value. If the value - // is <= 0, there is no limit to the number of outstanding bytes. This - // property can only be set on the initial StreamingPullRequest. If it is set - // on a subsequent request, the stream will be aborted with status - // `INVALID_ARGUMENT`. - int64 max_outstanding_bytes = 8; -} - -// Response for the `StreamingPull` method. This response is used to stream -// messages from the server to the client. -message StreamingPullResponse { - // Acknowledgement IDs sent in one or more previous requests to acknowledge a - // previously received message. - message AcknowledgeConfirmation { - // Successfully processed acknowledgement IDs. - repeated string ack_ids = 1; - - // List of acknowledgement IDs that were malformed or whose acknowledgement - // deadline has expired. - repeated string invalid_ack_ids = 2; - - // List of acknowledgement IDs that were out of order. - repeated string unordered_ack_ids = 3; - - // List of acknowledgement IDs that failed processing with temporary issues. - repeated string temporary_failed_ack_ids = 4; - } - - // Acknowledgement IDs sent in one or more previous requests to modify the - // deadline for a specific message. - message ModifyAckDeadlineConfirmation { - // Successfully processed acknowledgement IDs. - repeated string ack_ids = 1; - - // List of acknowledgement IDs that were malformed or whose acknowledgement - // deadline has expired. - repeated string invalid_ack_ids = 2; - - // List of acknowledgement IDs that failed processing with temporary issues. - repeated string temporary_failed_ack_ids = 3; - } - - // Subscription properties sent as part of the response. - message SubscriptionProperties { - // True iff exactly once delivery is enabled for this subscription. - bool exactly_once_delivery_enabled = 1; - - // True iff message ordering is enabled for this subscription. - bool message_ordering_enabled = 2; - } - - // Received Pub/Sub messages. This will not be empty. - repeated ReceivedMessage received_messages = 1; - - // This field will only be set if `enable_exactly_once_delivery` is set to - // `true`. - AcknowledgeConfirmation acknowledge_confirmation = 5; - - // This field will only be set if `enable_exactly_once_delivery` is set to - // `true`. - ModifyAckDeadlineConfirmation modify_ack_deadline_confirmation = 3; - - // Properties associated with this subscription. - SubscriptionProperties subscription_properties = 4; -} - -// Request for the `CreateSnapshot` method. -message CreateSnapshotRequest { - // Required. User-provided name for this snapshot. If the name is not provided - // in the request, the server will assign a random name for this snapshot on - // the same project as the subscription. Note that for REST API requests, you - // must specify a name. See the [resource name - // rules](https://cloud.google.com/pubsub/docs/admin#resource_names). Format - // is `projects/{project}/snapshots/{snap}`. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Snapshot" } - ]; - - // Required. The subscription whose backlog the snapshot retains. - // Specifically, the created snapshot is guaranteed to retain: - // (a) The existing backlog on the subscription. More precisely, this is - // defined as the messages in the subscription's backlog that are - // unacknowledged upon the successful completion of the - // `CreateSnapshot` request; as well as: - // (b) Any messages published to the subscription's topic following the - // successful completion of the CreateSnapshot request. - // Format is `projects/{project}/subscriptions/{sub}`. - string subscription = 2 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - // See [Creating and managing - // labels](https://cloud.google.com/pubsub/docs/labels). - map labels = 3; -} - -// Request for the UpdateSnapshot method. -message UpdateSnapshotRequest { - // Required. The updated snapshot object. - Snapshot snapshot = 1 [(google.api.field_behavior) = REQUIRED]; - - // Required. Indicates which fields in the provided snapshot to update. - // Must be specified and non-empty. - google.protobuf.FieldMask update_mask = 2 - [(google.api.field_behavior) = REQUIRED]; -} - -// A snapshot resource. Snapshots are used in -// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) -// operations, which allow you to manage message acknowledgments in bulk. That -// is, you can set the acknowledgment state of messages in an existing -// subscription to the state captured by a snapshot. -message Snapshot { - option (google.api.resource) = { - type: "pubsub.googleapis.com/Snapshot" - pattern: "projects/{project}/snapshots/{snapshot}" - }; - - // The name of the snapshot. - string name = 1; - - // The name of the topic from which this snapshot is retaining messages. - string topic = 2 [ - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; - - // The snapshot is guaranteed to exist up until this time. - // A newly-created snapshot expires no later than 7 days from the time of its - // creation. Its exact lifetime is determined at creation by the existing - // backlog in the source subscription. Specifically, the lifetime of the - // snapshot is `7 days - (age of oldest unacked message in the subscription)`. - // For example, consider a subscription whose oldest unacked message is 3 days - // old. If a snapshot is created from this subscription, the snapshot -- which - // will always capture this 3-day-old backlog as long as the snapshot - // exists -- will expire in 4 days. The service will refuse to create a - // snapshot that would expire in less than 1 hour after creation. - google.protobuf.Timestamp expire_time = 3; - - // See [Creating and managing labels] - // (https://cloud.google.com/pubsub/docs/labels). - map labels = 4; -} - -// Request for the GetSnapshot method. -message GetSnapshotRequest { - // Required. The name of the snapshot to get. - // Format is `projects/{project}/snapshots/{snap}`. - string snapshot = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Snapshot" } - ]; -} - -// Request for the `ListSnapshots` method. -message ListSnapshotsRequest { - // Required. The name of the project in which to list snapshots. - // Format is `projects/{project-id}`. - string project = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "cloudresourcemanager.googleapis.com/Project" - } - ]; - - // Maximum number of snapshots to return. - int32 page_size = 2; - - // The value returned by the last `ListSnapshotsResponse`; indicates that this - // is a continuation of a prior `ListSnapshots` call, and that the system - // should return the next page of data. - string page_token = 3; -} - -// Response for the `ListSnapshots` method. -message ListSnapshotsResponse { - // The resulting snapshots. - repeated Snapshot snapshots = 1; - - // If not empty, indicates that there may be more snapshot that match the - // request; this value should be passed in a new `ListSnapshotsRequest`. - string next_page_token = 2; -} - -// Request for the `DeleteSnapshot` method. -message DeleteSnapshotRequest { - // Required. The name of the snapshot to delete. - // Format is `projects/{project}/snapshots/{snap}`. - string snapshot = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Snapshot" } - ]; -} - -// Request for the `Seek` method. -message SeekRequest { - // Required. The subscription to affect. - string subscription = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "pubsub.googleapis.com/Subscription" - } - ]; - - oneof target { - // The time to seek to. - // Messages retained in the subscription that were published before this - // time are marked as acknowledged, and messages retained in the - // subscription that were published after this time are marked as - // unacknowledged. Note that this operation affects only those messages - // retained in the subscription (configured by the combination of - // `message_retention_duration` and `retain_acked_messages`). For example, - // if `time` corresponds to a point before the message retention - // window (or to a point before the system's notion of the subscription - // creation time), only retained messages will be marked as unacknowledged, - // and already-expunged messages will not be restored. - google.protobuf.Timestamp time = 2; - - // The snapshot to seek to. The snapshot's topic must be the same as that of - // the provided subscription. - // Format is `projects/{project}/snapshots/{snap}`. - string snapshot = 3 [(google.api.resource_reference) = { - type: "pubsub.googleapis.com/Snapshot" - }]; - } -} - -// Response for the `Seek` method (this response is empty). -message SeekResponse {} diff --git a/owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto b/owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto deleted file mode 100644 index 32aa0d75c..000000000 --- a/owl-bot-staging/v1/protos/google/pubsub/v1/schema.proto +++ /dev/null @@ -1,410 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.pubsub.v1; - -import "google/api/annotations.proto"; -import "google/api/client.proto"; -import "google/api/field_behavior.proto"; -import "google/api/resource.proto"; -import "google/protobuf/empty.proto"; -import "google/protobuf/timestamp.proto"; - -option cc_enable_arenas = true; -option csharp_namespace = "Google.Cloud.PubSub.V1"; -option go_package = "cloud.google.com/go/pubsub/apiv1/pubsubpb;pubsubpb"; -option java_multiple_files = true; -option java_outer_classname = "SchemaProto"; -option java_package = "com.google.pubsub.v1"; -option php_namespace = "Google\\Cloud\\PubSub\\V1"; -option ruby_package = "Google::Cloud::PubSub::V1"; - -// Service for doing schema-related operations. -service SchemaService { - option (google.api.default_host) = "pubsub.googleapis.com"; - option (google.api.oauth_scopes) = - "https://www.googleapis.com/auth/cloud-platform," - "https://www.googleapis.com/auth/pubsub"; - - // Creates a schema. - rpc CreateSchema(CreateSchemaRequest) returns (Schema) { - option (google.api.http) = { - post: "/v1/{parent=projects/*}/schemas" - body: "schema" - }; - option (google.api.method_signature) = "parent,schema,schema_id"; - } - - // Gets a schema. - rpc GetSchema(GetSchemaRequest) returns (Schema) { - option (google.api.http) = { - get: "/v1/{name=projects/*/schemas/*}" - }; - option (google.api.method_signature) = "name"; - } - - // Lists schemas in a project. - rpc ListSchemas(ListSchemasRequest) returns (ListSchemasResponse) { - option (google.api.http) = { - get: "/v1/{parent=projects/*}/schemas" - }; - option (google.api.method_signature) = "parent"; - } - - // Lists all schema revisions for the named schema. - rpc ListSchemaRevisions(ListSchemaRevisionsRequest) - returns (ListSchemaRevisionsResponse) { - option (google.api.http) = { - get: "/v1/{name=projects/*/schemas/*}:listRevisions" - }; - option (google.api.method_signature) = "name"; - } - - // Commits a new schema revision to an existing schema. - rpc CommitSchema(CommitSchemaRequest) returns (Schema) { - option (google.api.http) = { - post: "/v1/{name=projects/*/schemas/*}:commit" - body: "*" - }; - option (google.api.method_signature) = "name,schema"; - } - - // Creates a new schema revision that is a copy of the provided revision_id. - rpc RollbackSchema(RollbackSchemaRequest) returns (Schema) { - option (google.api.http) = { - post: "/v1/{name=projects/*/schemas/*}:rollback" - body: "*" - }; - option (google.api.method_signature) = "name,revision_id"; - } - - // Deletes a specific schema revision. - rpc DeleteSchemaRevision(DeleteSchemaRevisionRequest) returns (Schema) { - option (google.api.http) = { - delete: "/v1/{name=projects/*/schemas/*}:deleteRevision" - }; - option (google.api.method_signature) = "name,revision_id"; - } - - // Deletes a schema. - rpc DeleteSchema(DeleteSchemaRequest) returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v1/{name=projects/*/schemas/*}" - }; - option (google.api.method_signature) = "name"; - } - - // Validates a schema. - rpc ValidateSchema(ValidateSchemaRequest) returns (ValidateSchemaResponse) { - option (google.api.http) = { - post: "/v1/{parent=projects/*}/schemas:validate" - body: "*" - }; - option (google.api.method_signature) = "parent,schema"; - } - - // Validates a message against a schema. - rpc ValidateMessage(ValidateMessageRequest) - returns (ValidateMessageResponse) { - option (google.api.http) = { - post: "/v1/{parent=projects/*}/schemas:validateMessage" - body: "*" - }; - } -} - -// A schema resource. -message Schema { - option (google.api.resource) = { - type: "pubsub.googleapis.com/Schema" - pattern: "projects/{project}/schemas/{schema}" - }; - - // Possible schema definition types. - enum Type { - // Default value. This value is unused. - TYPE_UNSPECIFIED = 0; - - // A Protocol Buffer schema definition. - PROTOCOL_BUFFER = 1; - - // An Avro schema definition. - AVRO = 2; - } - - // Required. Name of the schema. - // Format is `projects/{project}/schemas/{schema}`. - string name = 1 [(google.api.field_behavior) = REQUIRED]; - - // The type of the schema definition. - Type type = 2; - - // The definition of the schema. This should contain a string representing - // the full definition of the schema that is a valid schema definition of - // the type specified in `type`. - string definition = 3; - - // Output only. Immutable. The revision ID of the schema. - string revision_id = 4 [ - (google.api.field_behavior) = IMMUTABLE, - (google.api.field_behavior) = OUTPUT_ONLY - ]; - - // Output only. The timestamp that the revision was created. - google.protobuf.Timestamp revision_create_time = 6 - [(google.api.field_behavior) = OUTPUT_ONLY]; -} - -// View of Schema object fields to be returned by GetSchema and ListSchemas. -enum SchemaView { - // The default / unset value. - // The API will default to the BASIC view. - SCHEMA_VIEW_UNSPECIFIED = 0; - - // Include the name and type of the schema, but not the definition. - BASIC = 1; - - // Include all Schema object fields. - FULL = 2; -} - -// Request for the CreateSchema method. -message CreateSchemaRequest { - // Required. The name of the project in which to create the schema. - // Format is `projects/{project-id}`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "pubsub.googleapis.com/Schema" - } - ]; - - // Required. The schema object to create. - // - // This schema's `name` parameter is ignored. The schema object returned - // by CreateSchema will have a `name` made using the given `parent` and - // `schema_id`. - Schema schema = 2 [(google.api.field_behavior) = REQUIRED]; - - // The ID to use for the schema, which will become the final component of - // the schema's resource name. - // - // See https://cloud.google.com/pubsub/docs/admin#resource_names for resource - // name constraints. - string schema_id = 3; -} - -// Request for the GetSchema method. -message GetSchemaRequest { - // Required. The name of the schema to get. - // Format is `projects/{project}/schemas/{schema}`. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // The set of fields to return in the response. If not set, returns a Schema - // with all fields filled out. Set to `BASIC` to omit the `definition`. - SchemaView view = 2; -} - -// Request for the `ListSchemas` method. -message ListSchemasRequest { - // Required. The name of the project in which to list schemas. - // Format is `projects/{project-id}`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "cloudresourcemanager.googleapis.com/Project" - } - ]; - - // The set of Schema fields to return in the response. If not set, returns - // Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - // retrieve all fields. - SchemaView view = 2; - - // Maximum number of schemas to return. - int32 page_size = 3; - - // The value returned by the last `ListSchemasResponse`; indicates that - // this is a continuation of a prior `ListSchemas` call, and that the - // system should return the next page of data. - string page_token = 4; -} - -// Response for the `ListSchemas` method. -message ListSchemasResponse { - // The resulting schemas. - repeated Schema schemas = 1; - - // If not empty, indicates that there may be more schemas that match the - // request; this value should be passed in a new `ListSchemasRequest`. - string next_page_token = 2; -} - -// Request for the `ListSchemaRevisions` method. -message ListSchemaRevisionsRequest { - // Required. The name of the schema to list revisions for. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // The set of Schema fields to return in the response. If not set, returns - // Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - // retrieve all fields. - SchemaView view = 2; - - // The maximum number of revisions to return per page. - int32 page_size = 3; - - // The page token, received from a previous ListSchemaRevisions call. - // Provide this to retrieve the subsequent page. - string page_token = 4; -} - -// Response for the `ListSchemaRevisions` method. -message ListSchemaRevisionsResponse { - // The revisions of the schema. - repeated Schema schemas = 1; - - // A token that can be sent as `page_token` to retrieve the next page. - // If this field is empty, there are no subsequent pages. - string next_page_token = 2; -} - -// Request for CommitSchema method. -message CommitSchemaRequest { - // Required. The name of the schema we are revising. - // Format is `projects/{project}/schemas/{schema}`. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // Required. The schema revision to commit. - Schema schema = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the `RollbackSchema` method. -message RollbackSchemaRequest { - // Required. The schema being rolled back with revision id. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // Required. The revision ID to roll back to. - // It must be a revision of the same schema. - // - // Example: c7cfa2a8 - string revision_id = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// Request for the `DeleteSchemaRevision` method. -message DeleteSchemaRevisionRequest { - // Required. The name of the schema revision to be deleted, with a revision ID - // explicitly included. - // - // Example: `projects/123/schemas/my-schema@c7cfa2a8` - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // Optional. This field is deprecated and should not be used for specifying - // the revision ID. The revision ID should be specified via the `name` - // parameter. - string revision_id = 2 - [deprecated = true, (google.api.field_behavior) = OPTIONAL]; -} - -// Request for the `DeleteSchema` method. -message DeleteSchemaRequest { - // Required. Name of the schema to delete. - // Format is `projects/{project}/schemas/{schema}`. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; -} - -// Request for the `ValidateSchema` method. -message ValidateSchemaRequest { - // Required. The name of the project in which to validate schemas. - // Format is `projects/{project-id}`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "cloudresourcemanager.googleapis.com/Project" - } - ]; - - // Required. The schema object to validate. - Schema schema = 2 [(google.api.field_behavior) = REQUIRED]; -} - -// Response for the `ValidateSchema` method. -// Empty for now. -message ValidateSchemaResponse {} - -// Request for the `ValidateMessage` method. -message ValidateMessageRequest { - // Required. The name of the project in which to validate schemas. - // Format is `projects/{project-id}`. - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "cloudresourcemanager.googleapis.com/Project" - } - ]; - - oneof schema_spec { - // Name of the schema against which to validate. - // - // Format is `projects/{project}/schemas/{schema}`. - string name = 2 [ - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" } - ]; - - // Ad-hoc schema against which to validate - Schema schema = 3; - } - - // Message to validate against the provided `schema_spec`. - bytes message = 4; - - // The encoding expected for messages - Encoding encoding = 5; -} - -// Response for the `ValidateMessage` method. -// Empty for now. -message ValidateMessageResponse {} - -// Possible encoding types for messages. -enum Encoding { - // Unspecified - ENCODING_UNSPECIFIED = 0; - - // JSON encoding - JSON = 1; - - // Binary encoding, as defined by the schema type. For some schema types, - // binary encoding may not be available. - BINARY = 2; -} diff --git a/owl-bot-staging/v1/src/index.ts b/owl-bot-staging/v1/src/index.ts deleted file mode 100644 index c304135e4..000000000 --- a/owl-bot-staging/v1/src/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as v1 from './v1'; -const PublisherClient = v1.PublisherClient; -type PublisherClient = v1.PublisherClient; -const SchemaServiceClient = v1.SchemaServiceClient; -type SchemaServiceClient = v1.SchemaServiceClient; -const SubscriberClient = v1.SubscriberClient; -type SubscriberClient = v1.SubscriberClient; -export {v1, PublisherClient, SchemaServiceClient, SubscriberClient}; -export default {v1, PublisherClient, SchemaServiceClient, SubscriberClient}; -import * as protos from '../protos/protos'; -export {protos} diff --git a/owl-bot-staging/v1/src/v1/index.ts b/owl-bot-staging/v1/src/v1/index.ts deleted file mode 100644 index 8bcd06706..000000000 --- a/owl-bot-staging/v1/src/v1/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -export {PublisherClient} from './publisher_client'; -export {SchemaServiceClient} from './schema_service_client'; -export {SubscriberClient} from './subscriber_client'; diff --git a/owl-bot-staging/v1/src/v1/publisher_client.ts b/owl-bot-staging/v1/src/v1/publisher_client.ts deleted file mode 100644 index abb8b5001..000000000 --- a/owl-bot-staging/v1/src/v1/publisher_client.ts +++ /dev/null @@ -1,1668 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos} from 'google-gax'; -import {Transform} from 'stream'; -import * as protos from '../../protos/protos'; -import jsonProtos = require('../../protos/protos.json'); -/** - * Client JSON configuration object, loaded from - * `src/v1/publisher_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './publisher_client_config.json'; -const version = require('../../../package.json').version; - -/** - * The service that an application uses to manipulate topics, and to send - * messages to a topic. - * @class - * @memberof v1 - */ -export class PublisherClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - iamClient: IamClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - publisherStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of PublisherClient. - * - * @param {object} [options] - The configuration object. - * The options accepted by the constructor are described in detail - * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. - * For more information, please check the - * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. - * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you - * need to avoid loading the default gRPC version and want to use the fallback - * HTTP implementation. Load only fallback version and pass it to the constructor: - * ``` - * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC - * const client = new PublisherClient({fallback: true}, gax); - * ``` - */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof PublisherClient; - const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.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); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { - opts['scopes'] = staticMembers.scopes; - } - - // Load google-gax module synchronously if needed - if (!gaxInstance) { - gaxInstance = require('google-gax') as typeof gax; - } - - // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); - - - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; - if (typeof process !== 'undefined' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' - ), - projectTopicPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/topics/{topic}' - ), - schemaPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/schemas/{schema}' - ), - snapshotPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/snapshots/{snapshot}' - ), - subscriptionPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/subscriptions/{subscription}' - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listTopics: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'topics'), - listTopicSubscriptions: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'), - listTopicSnapshots: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots') - }; - - const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos); - // Some methods on this API support automatically batching - // requests; denote this. - - this.descriptors.batching = { - publish: new this._gaxModule.BundleDescriptor( - 'messages', - ['topic'], - 'message_ids', - this._gaxModule.GrpcClient.createByteLengthFunction( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - protoFilesRoot.lookupType('google.pubsub.v1.PubsubMessage') as any - ) - ), - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.pubsub.v1.Publisher', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.publisherStub) { - return this.publisherStub; - } - - // Put together the "service stub" for - // google.pubsub.v1.Publisher. - this.publisherStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.pubsub.v1.Publisher') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.pubsub.v1.Publisher, - 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 publisherStubMethods = - ['createTopic', 'updateTopic', 'publish', 'getTopic', 'listTopics', 'listTopicSubscriptions', 'listTopicSnapshots', 'deleteTopic', 'detachSubscription']; - for (const methodName of publisherStubMethods) { - const callPromise = this.publisherStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error|null|undefined) => () => { - throw err; - }); - - const descriptor = - this.descriptors.page[methodName] || - this.descriptors.batching?.[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.publisherStub; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - return 'pubsub.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - return 'pubsub.googleapis.com'; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/pubsub' - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId(callback?: Callback): - Promise|void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- -/** - * Creates the given topic with the given name. See the [resource name rules] - * (https://cloud.google.com/pubsub/docs/admin#resource_names). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the topic. It must have the format - * `"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, - * and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), - * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent - * signs (`%`). It must be between 3 and 255 characters in length, and it - * must not start with `"goog"`. - * @param {number[]} request.labels - * See [Creating and managing labels] - * (https://cloud.google.com/pubsub/docs/labels). - * @param {google.pubsub.v1.MessageStoragePolicy} request.messageStoragePolicy - * Policy constraining the set of Google Cloud Platform regions where messages - * published to the topic may be stored. If not present, then no constraints - * are in effect. - * @param {string} request.kmsKeyName - * The resource name of the Cloud KMS CryptoKey to be used to protect access - * to messages published on this topic. - * - * The expected format is `projects/* /locations/* /keyRings/* /cryptoKeys/*`. - * @param {google.pubsub.v1.SchemaSettings} request.schemaSettings - * Settings for validating messages published against a schema. - * @param {boolean} request.satisfiesPzs - * Reserved for future use. This field is set only in responses from the - * server; it is ignored if it is set in any requests. - * @param {google.protobuf.Duration} request.messageRetentionDuration - * Indicates the minimum duration to retain a message after it is published to - * the topic. If this field is set, messages published to the topic in the - * last `message_retention_duration` are always available to subscribers. For - * instance, it allows any attached subscription to [seek to a - * timestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) - * that is up to `message_retention_duration` in the past. If this field is - * not set, message retention is controlled by settings on individual - * subscriptions. Cannot be more than 31 days or less than 10 minutes. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Topic|Topic}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - createTopic( - request?: protos.google.pubsub.v1.ITopic, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.ITopic|undefined, {}|undefined - ]>; - createTopic( - request: protos.google.pubsub.v1.ITopic, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.ITopic|null|undefined, - {}|null|undefined>): void; - createTopic( - request: protos.google.pubsub.v1.ITopic, - callback: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.ITopic|null|undefined, - {}|null|undefined>): void; - createTopic( - request?: protos.google.pubsub.v1.ITopic, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.ITopic|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.ITopic|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.ITopic|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.createTopic(request, options, callback); - } -/** - * Updates an existing topic. Note that certain properties of a - * topic are not modifiable. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.pubsub.v1.Topic} request.topic - * Required. The updated topic object. - * @param {google.protobuf.FieldMask} request.updateMask - * Required. Indicates which fields in the provided topic to update. Must be - * specified and non-empty. Note that if `update_mask` contains - * "message_storage_policy" but the `message_storage_policy` is not set in - * the `topic` provided above, then the updated value is determined by the - * policy configured at the project or organization level. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Topic|Topic}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - updateTopic( - request?: protos.google.pubsub.v1.IUpdateTopicRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IUpdateTopicRequest|undefined, {}|undefined - ]>; - updateTopic( - request: protos.google.pubsub.v1.IUpdateTopicRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, - {}|null|undefined>): void; - updateTopic( - request: protos.google.pubsub.v1.IUpdateTopicRequest, - callback: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, - {}|null|undefined>): void; - updateTopic( - request?: protos.google.pubsub.v1.IUpdateTopicRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IUpdateTopicRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IUpdateTopicRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'topic.name': request.topic!.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.updateTopic(request, options, callback); - } -/** - * Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic - * does not exist. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. The messages in the request will be published on this topic. - * Format is `projects/{project}/topics/{topic}`. - * @param {number[]} request.messages - * Required. The messages to publish. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.PublishResponse|PublishResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - publish( - request?: protos.google.pubsub.v1.IPublishRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.IPublishResponse, - protos.google.pubsub.v1.IPublishRequest|undefined, {}|undefined - ]>; - publish( - request: protos.google.pubsub.v1.IPublishRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.IPublishResponse, - protos.google.pubsub.v1.IPublishRequest|null|undefined, - {}|null|undefined>): void; - publish( - request: protos.google.pubsub.v1.IPublishRequest, - callback: Callback< - protos.google.pubsub.v1.IPublishResponse, - protos.google.pubsub.v1.IPublishRequest|null|undefined, - {}|null|undefined>): void; - publish( - request?: protos.google.pubsub.v1.IPublishRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.IPublishResponse, - protos.google.pubsub.v1.IPublishRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.IPublishResponse, - protos.google.pubsub.v1.IPublishRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.IPublishResponse, - protos.google.pubsub.v1.IPublishRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'topic': request.topic ?? '', - }); - this.initialize(); - return this.innerApiCalls.publish(request, options, callback); - } -/** - * Gets the configuration of a topic. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. The name of the topic to get. - * Format is `projects/{project}/topics/{topic}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Topic|Topic}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - getTopic( - request?: protos.google.pubsub.v1.IGetTopicRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IGetTopicRequest|undefined, {}|undefined - ]>; - getTopic( - request: protos.google.pubsub.v1.IGetTopicRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IGetTopicRequest|null|undefined, - {}|null|undefined>): void; - getTopic( - request: protos.google.pubsub.v1.IGetTopicRequest, - callback: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IGetTopicRequest|null|undefined, - {}|null|undefined>): void; - getTopic( - request?: protos.google.pubsub.v1.IGetTopicRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IGetTopicRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IGetTopicRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ITopic, - protos.google.pubsub.v1.IGetTopicRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'topic': request.topic ?? '', - }); - this.initialize(); - return this.innerApiCalls.getTopic(request, options, callback); - } -/** - * Deletes the topic with the given name. Returns `NOT_FOUND` if the topic - * does not exist. After a topic is deleted, a new topic may be created with - * the same name; this is an entirely new topic with none of the old - * configuration or subscriptions. Existing subscriptions to this topic are - * not deleted, but their `topic` field is set to `_deleted-topic_`. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. Name of the topic to delete. - * Format is `projects/{project}/topics/{topic}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - deleteTopic( - request?: protos.google.pubsub.v1.IDeleteTopicRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteTopicRequest|undefined, {}|undefined - ]>; - deleteTopic( - request: protos.google.pubsub.v1.IDeleteTopicRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, - {}|null|undefined>): void; - deleteTopic( - request: protos.google.pubsub.v1.IDeleteTopicRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, - {}|null|undefined>): void; - deleteTopic( - request?: protos.google.pubsub.v1.IDeleteTopicRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteTopicRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteTopicRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'topic': request.topic ?? '', - }); - this.initialize(); - return this.innerApiCalls.deleteTopic(request, options, callback); - } -/** - * Detaches a subscription from this topic. All messages retained in the - * subscription are dropped. Subsequent `Pull` and `StreamingPull` requests - * will return FAILED_PRECONDITION. If the subscription is a push - * subscription, pushes to the endpoint will stop. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The subscription to detach. - * Format is `projects/{project}/subscriptions/{subscription}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.DetachSubscriptionResponse|DetachSubscriptionResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - detachSubscription( - request?: protos.google.pubsub.v1.IDetachSubscriptionRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.IDetachSubscriptionResponse, - protos.google.pubsub.v1.IDetachSubscriptionRequest|undefined, {}|undefined - ]>; - detachSubscription( - request: protos.google.pubsub.v1.IDetachSubscriptionRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.IDetachSubscriptionResponse, - protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - detachSubscription( - request: protos.google.pubsub.v1.IDetachSubscriptionRequest, - callback: Callback< - protos.google.pubsub.v1.IDetachSubscriptionResponse, - protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - detachSubscription( - request?: protos.google.pubsub.v1.IDetachSubscriptionRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.IDetachSubscriptionResponse, - protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.IDetachSubscriptionResponse, - protos.google.pubsub.v1.IDetachSubscriptionRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.IDetachSubscriptionResponse, - protos.google.pubsub.v1.IDetachSubscriptionRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.detachSubscription(request, options, callback); - } - - /** - * Lists matching topics. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Required. The name of the project in which to list topics. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of topics to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicsResponse`; indicates that this is - * a continuation of a prior `ListTopics` call, and that the system should - * return the next page of data. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Topic|Topic}. - * 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 `listTopicsAsync()` - * 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. - */ - listTopics( - request?: protos.google.pubsub.v1.IListTopicsRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ITopic[], - protos.google.pubsub.v1.IListTopicsRequest|null, - protos.google.pubsub.v1.IListTopicsResponse - ]>; - listTopics( - request: protos.google.pubsub.v1.IListTopicsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListTopicsRequest, - protos.google.pubsub.v1.IListTopicsResponse|null|undefined, - protos.google.pubsub.v1.ITopic>): void; - listTopics( - request: protos.google.pubsub.v1.IListTopicsRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListTopicsRequest, - protos.google.pubsub.v1.IListTopicsResponse|null|undefined, - protos.google.pubsub.v1.ITopic>): void; - listTopics( - request?: protos.google.pubsub.v1.IListTopicsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListTopicsRequest, - protos.google.pubsub.v1.IListTopicsResponse|null|undefined, - protos.google.pubsub.v1.ITopic>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListTopicsRequest, - protos.google.pubsub.v1.IListTopicsResponse|null|undefined, - protos.google.pubsub.v1.ITopic>): - Promise<[ - protos.google.pubsub.v1.ITopic[], - protos.google.pubsub.v1.IListTopicsRequest|null, - protos.google.pubsub.v1.IListTopicsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'project': request.project ?? '', - }); - this.initialize(); - return this.innerApiCalls.listTopics(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Required. The name of the project in which to list topics. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of topics to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicsResponse`; indicates that this is - * a continuation of a prior `ListTopics` call, and that the system should - * return the next page of data. - * @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.pubsub.v1.Topic|Topic} 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 `listTopicsAsync()` - * 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. - */ - listTopicsStream( - request?: protos.google.pubsub.v1.IListTopicsRequest, - 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({ - 'project': request.project ?? '', - }); - const defaultCallSettings = this._defaults['listTopics']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listTopics.createStream( - this.innerApiCalls.listTopics as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listTopics`, 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.project - * Required. The name of the project in which to list topics. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of topics to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicsResponse`; indicates that this is - * a continuation of a prior `ListTopics` call, and that the system should - * return the next page of data. - * @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.pubsub.v1.Topic|Topic}. 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. - */ - listTopicsAsync( - request?: protos.google.pubsub.v1.IListTopicsRequest, - 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({ - 'project': request.project ?? '', - }); - const defaultCallSettings = this._defaults['listTopics']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listTopics.asyncIterate( - this.innerApiCalls['listTopics'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - /** - * Lists the names of the attached subscriptions on this topic. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. The name of the topic that subscriptions are attached to. - * Format is `projects/{project}/topics/{topic}`. - * @param {number} request.pageSize - * Maximum number of subscription names to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicSubscriptionsResponse`; indicates - * that this is a continuation of a prior `ListTopicSubscriptions` call, and - * that the system should return the next page of data. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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 string. - * 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 `listTopicSubscriptionsAsync()` - * 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. - */ - listTopicSubscriptions( - request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - options?: CallOptions): - Promise<[ - string[], - protos.google.pubsub.v1.IListTopicSubscriptionsRequest|null, - protos.google.pubsub.v1.IListTopicSubscriptionsResponse - ]>; - listTopicSubscriptions( - request: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, - string>): void; - listTopicSubscriptions( - request: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, - string>): void; - listTopicSubscriptions( - request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, - string>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - protos.google.pubsub.v1.IListTopicSubscriptionsResponse|null|undefined, - string>): - Promise<[ - string[], - protos.google.pubsub.v1.IListTopicSubscriptionsRequest|null, - protos.google.pubsub.v1.IListTopicSubscriptionsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'topic': request.topic ?? '', - }); - this.initialize(); - return this.innerApiCalls.listTopicSubscriptions(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. The name of the topic that subscriptions are attached to. - * Format is `projects/{project}/topics/{topic}`. - * @param {number} request.pageSize - * Maximum number of subscription names to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicSubscriptionsResponse`; indicates - * that this is a continuation of a prior `ListTopicSubscriptions` call, and - * that the system should return the next page of data. - * @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 string 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 `listTopicSubscriptionsAsync()` - * 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. - */ - listTopicSubscriptionsStream( - request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - 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({ - 'topic': request.topic ?? '', - }); - const defaultCallSettings = this._defaults['listTopicSubscriptions']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listTopicSubscriptions.createStream( - this.innerApiCalls.listTopicSubscriptions as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listTopicSubscriptions`, 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.topic - * Required. The name of the topic that subscriptions are attached to. - * Format is `projects/{project}/topics/{topic}`. - * @param {number} request.pageSize - * Maximum number of subscription names to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicSubscriptionsResponse`; indicates - * that this is a continuation of a prior `ListTopicSubscriptions` call, and - * that the system should return the next page of data. - * @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 - * string. 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. - */ - listTopicSubscriptionsAsync( - request?: protos.google.pubsub.v1.IListTopicSubscriptionsRequest, - 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({ - 'topic': request.topic ?? '', - }); - const defaultCallSettings = this._defaults['listTopicSubscriptions']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listTopicSubscriptions.asyncIterate( - this.innerApiCalls['listTopicSubscriptions'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - /** - * Lists the names of the snapshots on this topic. Snapshots are used in - * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - * which allow you to manage message acknowledgments in bulk. That is, you can - * set the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. The name of the topic that snapshots are attached to. - * Format is `projects/{project}/topics/{topic}`. - * @param {number} request.pageSize - * Maximum number of snapshot names to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicSnapshotsResponse`; indicates - * that this is a continuation of a prior `ListTopicSnapshots` call, and - * that the system should return the next page of data. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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 string. - * 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 `listTopicSnapshotsAsync()` - * 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. - */ - listTopicSnapshots( - request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, - options?: CallOptions): - Promise<[ - string[], - protos.google.pubsub.v1.IListTopicSnapshotsRequest|null, - protos.google.pubsub.v1.IListTopicSnapshotsResponse - ]>; - listTopicSnapshots( - request: protos.google.pubsub.v1.IListTopicSnapshotsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListTopicSnapshotsRequest, - protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, - string>): void; - listTopicSnapshots( - request: protos.google.pubsub.v1.IListTopicSnapshotsRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListTopicSnapshotsRequest, - protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, - string>): void; - listTopicSnapshots( - request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListTopicSnapshotsRequest, - protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, - string>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListTopicSnapshotsRequest, - protos.google.pubsub.v1.IListTopicSnapshotsResponse|null|undefined, - string>): - Promise<[ - string[], - protos.google.pubsub.v1.IListTopicSnapshotsRequest|null, - protos.google.pubsub.v1.IListTopicSnapshotsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'topic': request.topic ?? '', - }); - this.initialize(); - return this.innerApiCalls.listTopicSnapshots(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.topic - * Required. The name of the topic that snapshots are attached to. - * Format is `projects/{project}/topics/{topic}`. - * @param {number} request.pageSize - * Maximum number of snapshot names to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicSnapshotsResponse`; indicates - * that this is a continuation of a prior `ListTopicSnapshots` call, and - * that the system should return the next page of data. - * @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 string 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 `listTopicSnapshotsAsync()` - * 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. - */ - listTopicSnapshotsStream( - request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, - 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({ - 'topic': request.topic ?? '', - }); - const defaultCallSettings = this._defaults['listTopicSnapshots']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listTopicSnapshots.createStream( - this.innerApiCalls.listTopicSnapshots as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listTopicSnapshots`, 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.topic - * Required. The name of the topic that snapshots are attached to. - * Format is `projects/{project}/topics/{topic}`. - * @param {number} request.pageSize - * Maximum number of snapshot names to return. - * @param {string} request.pageToken - * The value returned by the last `ListTopicSnapshotsResponse`; indicates - * that this is a continuation of a prior `ListTopicSnapshots` call, and - * that the system should return the next page of data. - * @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 - * string. 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. - */ - listTopicSnapshotsAsync( - request?: protos.google.pubsub.v1.IListTopicSnapshotsRequest, - 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({ - 'topic': request.topic ?? '', - }); - const defaultCallSettings = this._defaults['listTopicSnapshots']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listTopicSnapshots.asyncIterate( - this.innerApiCalls['listTopicSnapshots'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } -/** - * Gets the access control policy for a resource. Returns an empty policy - * if the resource exists and does not have a policy set. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {Object} [request.options] - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. This field is only used by Cloud IAM. - * - * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ - getIamPolicy( - request: IamProtos.google.iam.v1.GetIamPolicyRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.Policy]> { - return this.iamClient.getIamPolicy(request, options, callback); - } - -/** - * Returns permissions that a caller has on the specified resource. If the - * resource does not exist, this will return an empty set of - * permissions, not a NOT_FOUND error. - * - * Note: This operation is designed to be used for building - * permission-aware UIs and command-line tools, not for authorization - * checking. This operation may "fail open" without warning. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ - setIamPolicy( - request: IamProtos.google.iam.v1.SetIamPolicyRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.Policy]> { - return this.iamClient.setIamPolicy(request, options, callback); - } - -/** - * Returns permissions that a caller has on the specified resource. If the - * resource does not exist, this will return an empty set of - * permissions, not a NOT_FOUND error. - * - * Note: This operation is designed to be used for building - * permission-aware UIs and command-line tools, not for authorization - * checking. This operation may "fail open" without warning. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - */ - testIamPermissions( - request: IamProtos.google.iam.v1.TestIamPermissionsRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.TestIamPermissionsResponse, - IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.TestIamPermissionsResponse, - IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { - return this.iamClient.testIamPermissions(request, options, callback); - } - - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified project resource name string. - * - * @param {string} project - * @returns {string} Resource name string. - */ - projectPath(project:string) { - return this.pathTemplates.projectPathTemplate.render({ - project: project, - }); - } - - /** - * Parse the project from Project resource. - * - * @param {string} projectName - * A fully-qualified path representing Project resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectName(projectName: string) { - return this.pathTemplates.projectPathTemplate.match(projectName).project; - } - - /** - * Return a fully-qualified projectTopic resource name string. - * - * @param {string} project - * @param {string} topic - * @returns {string} Resource name string. - */ - projectTopicPath(project:string,topic:string) { - return this.pathTemplates.projectTopicPathTemplate.render({ - project: project, - topic: topic, - }); - } - - /** - * Parse the project from ProjectTopic resource. - * - * @param {string} projectTopicName - * A fully-qualified path representing project_topic resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectTopicName(projectTopicName: string) { - return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).project; - } - - /** - * Parse the topic from ProjectTopic resource. - * - * @param {string} projectTopicName - * A fully-qualified path representing project_topic resource. - * @returns {string} A string representing the topic. - */ - matchTopicFromProjectTopicName(projectTopicName: string) { - return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).topic; - } - - /** - * Return a fully-qualified schema resource name string. - * - * @param {string} project - * @param {string} schema - * @returns {string} Resource name string. - */ - schemaPath(project:string,schema:string) { - return this.pathTemplates.schemaPathTemplate.render({ - project: project, - schema: schema, - }); - } - - /** - * Parse the project from Schema resource. - * - * @param {string} schemaName - * A fully-qualified path representing Schema resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSchemaName(schemaName: string) { - return this.pathTemplates.schemaPathTemplate.match(schemaName).project; - } - - /** - * Parse the schema from Schema resource. - * - * @param {string} schemaName - * A fully-qualified path representing Schema resource. - * @returns {string} A string representing the schema. - */ - matchSchemaFromSchemaName(schemaName: string) { - return this.pathTemplates.schemaPathTemplate.match(schemaName).schema; - } - - /** - * Return a fully-qualified snapshot resource name string. - * - * @param {string} project - * @param {string} snapshot - * @returns {string} Resource name string. - */ - snapshotPath(project:string,snapshot:string) { - return this.pathTemplates.snapshotPathTemplate.render({ - project: project, - snapshot: snapshot, - }); - } - - /** - * Parse the project from Snapshot resource. - * - * @param {string} snapshotName - * A fully-qualified path representing Snapshot resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSnapshotName(snapshotName: string) { - return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project; - } - - /** - * Parse the snapshot from Snapshot resource. - * - * @param {string} snapshotName - * A fully-qualified path representing Snapshot resource. - * @returns {string} A string representing the snapshot. - */ - matchSnapshotFromSnapshotName(snapshotName: string) { - return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot; - } - - /** - * Return a fully-qualified subscription resource name string. - * - * @param {string} project - * @param {string} subscription - * @returns {string} Resource name string. - */ - subscriptionPath(project:string,subscription:string) { - return this.pathTemplates.subscriptionPathTemplate.render({ - project: project, - subscription: subscription, - }); - } - - /** - * Parse the project from Subscription resource. - * - * @param {string} subscriptionName - * A fully-qualified path representing Subscription resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSubscriptionName(subscriptionName: string) { - return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).project; - } - - /** - * Parse the subscription from Subscription resource. - * - * @param {string} subscriptionName - * A fully-qualified path representing Subscription resource. - * @returns {string} A string representing the subscription. - */ - matchSubscriptionFromSubscriptionName(subscriptionName: string) { - return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).subscription; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.publisherStub && !this._terminated) { - return this.publisherStub.then(stub => { - this._terminated = true; - stub.close(); - this.iamClient.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/owl-bot-staging/v1/src/v1/publisher_client_config.json b/owl-bot-staging/v1/src/v1/publisher_client_config.json deleted file mode 100644 index 187d70936..000000000 --- a/owl-bot-staging/v1/src/v1/publisher_client_config.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "interfaces": { - "google.pubsub.v1.Publisher": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "unavailable": [ - "UNAVAILABLE" - ], - "cancelled_unknown_deadline_exceeded_resource_exhausted_aborted_internal_unavailable": [ - "CANCELLED", - "UNKNOWN", - "DEADLINE_EXCEEDED", - "RESOURCE_EXHAUSTED", - "ABORTED", - "INTERNAL", - "UNAVAILABLE" - ], - "unknown_aborted_unavailable": [ - "UNKNOWN", - "ABORTED", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - }, - "693222d32e887d96c8faeadca469f7763ccda85a": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 4, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "CreateTopic": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "UpdateTopic": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "Publish": { - "timeout_millis": 60000, - "retry_codes_name": "cancelled_unknown_deadline_exceeded_resource_exhausted_aborted_internal_unavailable", - "retry_params_name": "693222d32e887d96c8faeadca469f7763ccda85a", - "bundling": { - "element_count_threshold": 100, - "request_byte_threshold": 1048576, - "delay_threshold_millis": 10, - "element_count_limit": 1000 - } - }, - "GetTopic": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "ListTopics": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "ListTopicSubscriptions": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "ListTopicSnapshots": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "DeleteTopic": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "DetachSubscription": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - } - } - } - } -} diff --git a/owl-bot-staging/v1/src/v1/publisher_proto_list.json b/owl-bot-staging/v1/src/v1/publisher_proto_list.json deleted file mode 100644 index 91011aec1..000000000 --- a/owl-bot-staging/v1/src/v1/publisher_proto_list.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "../../protos/google/pubsub/v1/pubsub.proto", - "../../protos/google/pubsub/v1/schema.proto" -] diff --git a/owl-bot-staging/v1/src/v1/schema_service_client.ts b/owl-bot-staging/v1/src/v1/schema_service_client.ts deleted file mode 100644 index b0bea8a78..000000000 --- a/owl-bot-staging/v1/src/v1/schema_service_client.ts +++ /dev/null @@ -1,1615 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos} from 'google-gax'; -import {Transform} from 'stream'; -import * as protos from '../../protos/protos'; -import jsonProtos = require('../../protos/protos.json'); -/** - * Client JSON configuration object, loaded from - * `src/v1/schema_service_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './schema_service_client_config.json'; -const version = require('../../../package.json').version; - -/** - * Service for doing schema-related operations. - * @class - * @memberof v1 - */ -export class SchemaServiceClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - iamClient: IamClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - schemaServiceStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of SchemaServiceClient. - * - * @param {object} [options] - The configuration object. - * The options accepted by the constructor are described in detail - * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. - * For more information, please check the - * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. - * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you - * need to avoid loading the default gRPC version and want to use the fallback - * HTTP implementation. Load only fallback version and pass it to the constructor: - * ``` - * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC - * const client = new SchemaServiceClient({fallback: true}, gax); - * ``` - */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof SchemaServiceClient; - const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.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); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { - opts['scopes'] = staticMembers.scopes; - } - - // Load google-gax module synchronously if needed - if (!gaxInstance) { - gaxInstance = require('google-gax') as typeof gax; - } - - // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); - - - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; - if (typeof process !== 'undefined' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' - ), - projectTopicPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/topics/{topic}' - ), - schemaPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/schemas/{schema}' - ), - snapshotPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/snapshots/{snapshot}' - ), - subscriptionPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/subscriptions/{subscription}' - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listSchemas: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'schemas'), - listSchemaRevisions: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'schemas') - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.pubsub.v1.SchemaService', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.schemaServiceStub) { - return this.schemaServiceStub; - } - - // Put together the "service stub" for - // google.pubsub.v1.SchemaService. - this.schemaServiceStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.pubsub.v1.SchemaService') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.pubsub.v1.SchemaService, - 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 schemaServiceStubMethods = - ['createSchema', 'getSchema', 'listSchemas', 'listSchemaRevisions', 'commitSchema', 'rollbackSchema', 'deleteSchemaRevision', 'deleteSchema', 'validateSchema', 'validateMessage']; - for (const methodName of schemaServiceStubMethods) { - const callPromise = this.schemaServiceStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error|null|undefined) => () => { - throw err; - }); - - const descriptor = - this.descriptors.page[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.schemaServiceStub; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - return 'pubsub.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - return 'pubsub.googleapis.com'; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/pubsub' - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId(callback?: Callback): - Promise|void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- -/** - * Creates a schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the project in which to create the schema. - * Format is `projects/{project-id}`. - * @param {google.pubsub.v1.Schema} request.schema - * Required. The schema object to create. - * - * This schema's `name` parameter is ignored. The schema object returned - * by CreateSchema will have a `name` made using the given `parent` and - * `schema_id`. - * @param {string} request.schemaId - * The ID to use for the schema, which will become the final component of - * the schema's resource name. - * - * See https://cloud.google.com/pubsub/docs/admin#resource_names for resource - * name constraints. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - createSchema( - request?: protos.google.pubsub.v1.ICreateSchemaRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICreateSchemaRequest|undefined, {}|undefined - ]>; - createSchema( - request: protos.google.pubsub.v1.ICreateSchemaRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, - {}|null|undefined>): void; - createSchema( - request: protos.google.pubsub.v1.ICreateSchemaRequest, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, - {}|null|undefined>): void; - createSchema( - request?: protos.google.pubsub.v1.ICreateSchemaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICreateSchemaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICreateSchemaRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'parent': request.parent ?? '', - }); - this.initialize(); - return this.innerApiCalls.createSchema(request, options, callback); - } -/** - * Gets a schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the schema to get. - * Format is `projects/{project}/schemas/{schema}`. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of fields to return in the response. If not set, returns a Schema - * with all fields filled out. Set to `BASIC` to omit the `definition`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - getSchema( - request?: protos.google.pubsub.v1.IGetSchemaRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IGetSchemaRequest|undefined, {}|undefined - ]>; - getSchema( - request: protos.google.pubsub.v1.IGetSchemaRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, - {}|null|undefined>): void; - getSchema( - request: protos.google.pubsub.v1.IGetSchemaRequest, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, - {}|null|undefined>): void; - getSchema( - request?: protos.google.pubsub.v1.IGetSchemaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IGetSchemaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IGetSchemaRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.getSchema(request, options, callback); - } -/** - * Commits a new schema revision to an existing schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the schema we are revising. - * Format is `projects/{project}/schemas/{schema}`. - * @param {google.pubsub.v1.Schema} request.schema - * Required. The schema revision to commit. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - commitSchema( - request?: protos.google.pubsub.v1.ICommitSchemaRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICommitSchemaRequest|undefined, {}|undefined - ]>; - commitSchema( - request: protos.google.pubsub.v1.ICommitSchemaRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, - {}|null|undefined>): void; - commitSchema( - request: protos.google.pubsub.v1.ICommitSchemaRequest, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, - {}|null|undefined>): void; - commitSchema( - request?: protos.google.pubsub.v1.ICommitSchemaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICommitSchemaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.ICommitSchemaRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.commitSchema(request, options, callback); - } -/** - * Creates a new schema revision that is a copy of the provided revision_id. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The schema being rolled back with revision id. - * @param {string} request.revisionId - * Required. The revision ID to roll back to. - * It must be a revision of the same schema. - * - * Example: c7cfa2a8 - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - rollbackSchema( - request?: protos.google.pubsub.v1.IRollbackSchemaRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IRollbackSchemaRequest|undefined, {}|undefined - ]>; - rollbackSchema( - request: protos.google.pubsub.v1.IRollbackSchemaRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, - {}|null|undefined>): void; - rollbackSchema( - request: protos.google.pubsub.v1.IRollbackSchemaRequest, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, - {}|null|undefined>): void; - rollbackSchema( - request?: protos.google.pubsub.v1.IRollbackSchemaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IRollbackSchemaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IRollbackSchemaRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.rollbackSchema(request, options, callback); - } -/** - * Deletes a specific schema revision. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the schema revision to be deleted, with a revision ID - * explicitly included. - * - * Example: `projects/123/schemas/my-schema@c7cfa2a8` - * @param {string} [request.revisionId] - * Optional. This field is deprecated and should not be used for specifying - * the revision ID. The revision ID should be specified via the `name` - * parameter. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Schema|Schema}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - deleteSchemaRevision( - request?: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|undefined, {}|undefined - ]>; - deleteSchemaRevision( - request: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, - {}|null|undefined>): void; - deleteSchemaRevision( - request: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, - callback: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, - {}|null|undefined>): void; - deleteSchemaRevision( - request?: protos.google.pubsub.v1.IDeleteSchemaRevisionRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISchema, - protos.google.pubsub.v1.IDeleteSchemaRevisionRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.deleteSchemaRevision(request, options, callback); - } -/** - * Deletes a schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the schema to delete. - * Format is `projects/{project}/schemas/{schema}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - deleteSchema( - request?: protos.google.pubsub.v1.IDeleteSchemaRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSchemaRequest|undefined, {}|undefined - ]>; - deleteSchema( - request: protos.google.pubsub.v1.IDeleteSchemaRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, - {}|null|undefined>): void; - deleteSchema( - request: protos.google.pubsub.v1.IDeleteSchemaRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, - {}|null|undefined>): void; - deleteSchema( - request?: protos.google.pubsub.v1.IDeleteSchemaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSchemaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSchemaRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.deleteSchema(request, options, callback); - } -/** - * Validates a schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the project in which to validate schemas. - * Format is `projects/{project-id}`. - * @param {google.pubsub.v1.Schema} request.schema - * Required. The schema object to validate. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.ValidateSchemaResponse|ValidateSchemaResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - validateSchema( - request?: protos.google.pubsub.v1.IValidateSchemaRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.IValidateSchemaResponse, - protos.google.pubsub.v1.IValidateSchemaRequest|undefined, {}|undefined - ]>; - validateSchema( - request: protos.google.pubsub.v1.IValidateSchemaRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.IValidateSchemaResponse, - protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, - {}|null|undefined>): void; - validateSchema( - request: protos.google.pubsub.v1.IValidateSchemaRequest, - callback: Callback< - protos.google.pubsub.v1.IValidateSchemaResponse, - protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, - {}|null|undefined>): void; - validateSchema( - request?: protos.google.pubsub.v1.IValidateSchemaRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.IValidateSchemaResponse, - protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.IValidateSchemaResponse, - protos.google.pubsub.v1.IValidateSchemaRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.IValidateSchemaResponse, - protos.google.pubsub.v1.IValidateSchemaRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'parent': request.parent ?? '', - }); - this.initialize(); - return this.innerApiCalls.validateSchema(request, options, callback); - } -/** - * Validates a message against a schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the project in which to validate schemas. - * Format is `projects/{project-id}`. - * @param {string} request.name - * Name of the schema against which to validate. - * - * Format is `projects/{project}/schemas/{schema}`. - * @param {google.pubsub.v1.Schema} request.schema - * Ad-hoc schema against which to validate - * @param {Buffer} request.message - * Message to validate against the provided `schema_spec`. - * @param {google.pubsub.v1.Encoding} request.encoding - * The encoding expected for messages - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.ValidateMessageResponse|ValidateMessageResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - validateMessage( - request?: protos.google.pubsub.v1.IValidateMessageRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.IValidateMessageResponse, - protos.google.pubsub.v1.IValidateMessageRequest|undefined, {}|undefined - ]>; - validateMessage( - request: protos.google.pubsub.v1.IValidateMessageRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.IValidateMessageResponse, - protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, - {}|null|undefined>): void; - validateMessage( - request: protos.google.pubsub.v1.IValidateMessageRequest, - callback: Callback< - protos.google.pubsub.v1.IValidateMessageResponse, - protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, - {}|null|undefined>): void; - validateMessage( - request?: protos.google.pubsub.v1.IValidateMessageRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.IValidateMessageResponse, - protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.IValidateMessageResponse, - protos.google.pubsub.v1.IValidateMessageRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.IValidateMessageResponse, - protos.google.pubsub.v1.IValidateMessageRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'parent': request.parent ?? '', - }); - this.initialize(); - return this.innerApiCalls.validateMessage(request, options, callback); - } - - /** - * Lists schemas in a project. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the project in which to list schemas. - * Format is `projects/{project-id}`. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of Schema fields to return in the response. If not set, returns - * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - * retrieve all fields. - * @param {number} request.pageSize - * Maximum number of schemas to return. - * @param {string} request.pageToken - * The value returned by the last `ListSchemasResponse`; indicates that - * this is a continuation of a prior `ListSchemas` call, and that the - * system should return the next page of data. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Schema|Schema}. - * 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 `listSchemasAsync()` - * 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. - */ - listSchemas( - request?: protos.google.pubsub.v1.IListSchemasRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema[], - protos.google.pubsub.v1.IListSchemasRequest|null, - protos.google.pubsub.v1.IListSchemasResponse - ]>; - listSchemas( - request: protos.google.pubsub.v1.IListSchemasRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSchemasRequest, - protos.google.pubsub.v1.IListSchemasResponse|null|undefined, - protos.google.pubsub.v1.ISchema>): void; - listSchemas( - request: protos.google.pubsub.v1.IListSchemasRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSchemasRequest, - protos.google.pubsub.v1.IListSchemasResponse|null|undefined, - protos.google.pubsub.v1.ISchema>): void; - listSchemas( - request?: protos.google.pubsub.v1.IListSchemasRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListSchemasRequest, - protos.google.pubsub.v1.IListSchemasResponse|null|undefined, - protos.google.pubsub.v1.ISchema>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListSchemasRequest, - protos.google.pubsub.v1.IListSchemasResponse|null|undefined, - protos.google.pubsub.v1.ISchema>): - Promise<[ - protos.google.pubsub.v1.ISchema[], - protos.google.pubsub.v1.IListSchemasRequest|null, - protos.google.pubsub.v1.IListSchemasResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'parent': request.parent ?? '', - }); - this.initialize(); - return this.innerApiCalls.listSchemas(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the project in which to list schemas. - * Format is `projects/{project-id}`. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of Schema fields to return in the response. If not set, returns - * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - * retrieve all fields. - * @param {number} request.pageSize - * Maximum number of schemas to return. - * @param {string} request.pageToken - * The value returned by the last `ListSchemasResponse`; indicates that - * this is a continuation of a prior `ListSchemas` call, and that the - * system should return the next page of data. - * @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.pubsub.v1.Schema|Schema} 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 `listSchemasAsync()` - * 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. - */ - listSchemasStream( - request?: protos.google.pubsub.v1.IListSchemasRequest, - 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 ?? '', - }); - const defaultCallSettings = this._defaults['listSchemas']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSchemas.createStream( - this.innerApiCalls.listSchemas as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listSchemas`, 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 name of the project in which to list schemas. - * Format is `projects/{project-id}`. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of Schema fields to return in the response. If not set, returns - * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - * retrieve all fields. - * @param {number} request.pageSize - * Maximum number of schemas to return. - * @param {string} request.pageToken - * The value returned by the last `ListSchemasResponse`; indicates that - * this is a continuation of a prior `ListSchemas` call, and that the - * system should return the next page of data. - * @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.pubsub.v1.Schema|Schema}. 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. - */ - listSchemasAsync( - request?: protos.google.pubsub.v1.IListSchemasRequest, - 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 ?? '', - }); - const defaultCallSettings = this._defaults['listSchemas']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSchemas.asyncIterate( - this.innerApiCalls['listSchemas'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - /** - * Lists all schema revisions for the named schema. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the schema to list revisions for. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of Schema fields to return in the response. If not set, returns - * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - * retrieve all fields. - * @param {number} request.pageSize - * The maximum number of revisions to return per page. - * @param {string} request.pageToken - * The page token, received from a previous ListSchemaRevisions call. - * Provide this to retrieve the subsequent page. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Schema|Schema}. - * 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 `listSchemaRevisionsAsync()` - * 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. - */ - listSchemaRevisions( - request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISchema[], - protos.google.pubsub.v1.IListSchemaRevisionsRequest|null, - protos.google.pubsub.v1.IListSchemaRevisionsResponse - ]>; - listSchemaRevisions( - request: protos.google.pubsub.v1.IListSchemaRevisionsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSchemaRevisionsRequest, - protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, - protos.google.pubsub.v1.ISchema>): void; - listSchemaRevisions( - request: protos.google.pubsub.v1.IListSchemaRevisionsRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSchemaRevisionsRequest, - protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, - protos.google.pubsub.v1.ISchema>): void; - listSchemaRevisions( - request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListSchemaRevisionsRequest, - protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, - protos.google.pubsub.v1.ISchema>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListSchemaRevisionsRequest, - protos.google.pubsub.v1.IListSchemaRevisionsResponse|null|undefined, - protos.google.pubsub.v1.ISchema>): - Promise<[ - protos.google.pubsub.v1.ISchema[], - protos.google.pubsub.v1.IListSchemaRevisionsRequest|null, - protos.google.pubsub.v1.IListSchemaRevisionsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.listSchemaRevisions(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the schema to list revisions for. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of Schema fields to return in the response. If not set, returns - * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - * retrieve all fields. - * @param {number} request.pageSize - * The maximum number of revisions to return per page. - * @param {string} request.pageToken - * The page token, received from a previous ListSchemaRevisions call. - * Provide this to retrieve the subsequent page. - * @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.pubsub.v1.Schema|Schema} 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 `listSchemaRevisionsAsync()` - * 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. - */ - listSchemaRevisionsStream( - request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, - options?: CallOptions): - Transform{ - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - const defaultCallSettings = this._defaults['listSchemaRevisions']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSchemaRevisions.createStream( - this.innerApiCalls.listSchemaRevisions as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listSchemaRevisions`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the schema to list revisions for. - * @param {google.pubsub.v1.SchemaView} request.view - * The set of Schema fields to return in the response. If not set, returns - * Schemas with `name` and `type`, but not `definition`. Set to `FULL` to - * retrieve all fields. - * @param {number} request.pageSize - * The maximum number of revisions to return per page. - * @param {string} request.pageToken - * The page token, received from a previous ListSchemaRevisions call. - * Provide this to retrieve the subsequent page. - * @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.pubsub.v1.Schema|Schema}. 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. - */ - listSchemaRevisionsAsync( - request?: protos.google.pubsub.v1.IListSchemaRevisionsRequest, - options?: CallOptions): - AsyncIterable{ - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - const defaultCallSettings = this._defaults['listSchemaRevisions']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSchemaRevisions.asyncIterate( - this.innerApiCalls['listSchemaRevisions'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } -/** - * Gets the access control policy for a resource. Returns an empty policy - * if the resource exists and does not have a policy set. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {Object} [request.options] - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. This field is only used by Cloud IAM. - * - * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ - getIamPolicy( - request: IamProtos.google.iam.v1.GetIamPolicyRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.Policy]> { - return this.iamClient.getIamPolicy(request, options, callback); - } - -/** - * Returns permissions that a caller has on the specified resource. If the - * resource does not exist, this will return an empty set of - * permissions, not a NOT_FOUND error. - * - * Note: This operation is designed to be used for building - * permission-aware UIs and command-line tools, not for authorization - * checking. This operation may "fail open" without warning. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ - setIamPolicy( - request: IamProtos.google.iam.v1.SetIamPolicyRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.Policy]> { - return this.iamClient.setIamPolicy(request, options, callback); - } - -/** - * Returns permissions that a caller has on the specified resource. If the - * resource does not exist, this will return an empty set of - * permissions, not a NOT_FOUND error. - * - * Note: This operation is designed to be used for building - * permission-aware UIs and command-line tools, not for authorization - * checking. This operation may "fail open" without warning. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - */ - testIamPermissions( - request: IamProtos.google.iam.v1.TestIamPermissionsRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.TestIamPermissionsResponse, - IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.TestIamPermissionsResponse, - IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { - return this.iamClient.testIamPermissions(request, options, callback); - } - - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified project resource name string. - * - * @param {string} project - * @returns {string} Resource name string. - */ - projectPath(project:string) { - return this.pathTemplates.projectPathTemplate.render({ - project: project, - }); - } - - /** - * Parse the project from Project resource. - * - * @param {string} projectName - * A fully-qualified path representing Project resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectName(projectName: string) { - return this.pathTemplates.projectPathTemplate.match(projectName).project; - } - - /** - * Return a fully-qualified projectTopic resource name string. - * - * @param {string} project - * @param {string} topic - * @returns {string} Resource name string. - */ - projectTopicPath(project:string,topic:string) { - return this.pathTemplates.projectTopicPathTemplate.render({ - project: project, - topic: topic, - }); - } - - /** - * Parse the project from ProjectTopic resource. - * - * @param {string} projectTopicName - * A fully-qualified path representing project_topic resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectTopicName(projectTopicName: string) { - return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).project; - } - - /** - * Parse the topic from ProjectTopic resource. - * - * @param {string} projectTopicName - * A fully-qualified path representing project_topic resource. - * @returns {string} A string representing the topic. - */ - matchTopicFromProjectTopicName(projectTopicName: string) { - return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).topic; - } - - /** - * Return a fully-qualified schema resource name string. - * - * @param {string} project - * @param {string} schema - * @returns {string} Resource name string. - */ - schemaPath(project:string,schema:string) { - return this.pathTemplates.schemaPathTemplate.render({ - project: project, - schema: schema, - }); - } - - /** - * Parse the project from Schema resource. - * - * @param {string} schemaName - * A fully-qualified path representing Schema resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSchemaName(schemaName: string) { - return this.pathTemplates.schemaPathTemplate.match(schemaName).project; - } - - /** - * Parse the schema from Schema resource. - * - * @param {string} schemaName - * A fully-qualified path representing Schema resource. - * @returns {string} A string representing the schema. - */ - matchSchemaFromSchemaName(schemaName: string) { - return this.pathTemplates.schemaPathTemplate.match(schemaName).schema; - } - - /** - * Return a fully-qualified snapshot resource name string. - * - * @param {string} project - * @param {string} snapshot - * @returns {string} Resource name string. - */ - snapshotPath(project:string,snapshot:string) { - return this.pathTemplates.snapshotPathTemplate.render({ - project: project, - snapshot: snapshot, - }); - } - - /** - * Parse the project from Snapshot resource. - * - * @param {string} snapshotName - * A fully-qualified path representing Snapshot resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSnapshotName(snapshotName: string) { - return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project; - } - - /** - * Parse the snapshot from Snapshot resource. - * - * @param {string} snapshotName - * A fully-qualified path representing Snapshot resource. - * @returns {string} A string representing the snapshot. - */ - matchSnapshotFromSnapshotName(snapshotName: string) { - return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot; - } - - /** - * Return a fully-qualified subscription resource name string. - * - * @param {string} project - * @param {string} subscription - * @returns {string} Resource name string. - */ - subscriptionPath(project:string,subscription:string) { - return this.pathTemplates.subscriptionPathTemplate.render({ - project: project, - subscription: subscription, - }); - } - - /** - * Parse the project from Subscription resource. - * - * @param {string} subscriptionName - * A fully-qualified path representing Subscription resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSubscriptionName(subscriptionName: string) { - return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).project; - } - - /** - * Parse the subscription from Subscription resource. - * - * @param {string} subscriptionName - * A fully-qualified path representing Subscription resource. - * @returns {string} A string representing the subscription. - */ - matchSubscriptionFromSubscriptionName(subscriptionName: string) { - return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).subscription; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.schemaServiceStub && !this._terminated) { - return this.schemaServiceStub.then(stub => { - this._terminated = true; - stub.close(); - this.iamClient.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/owl-bot-staging/v1/src/v1/schema_service_client_config.json b/owl-bot-staging/v1/src/v1/schema_service_client_config.json deleted file mode 100644 index 5a2280962..000000000 --- a/owl-bot-staging/v1/src/v1/schema_service_client_config.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "interfaces": { - "google.pubsub.v1.SchemaService": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "unavailable": [ - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "CreateSchema": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "GetSchema": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "ListSchemas": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "ListSchemaRevisions": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "CommitSchema": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "RollbackSchema": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "DeleteSchemaRevision": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "DeleteSchema": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "ValidateSchema": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "ValidateMessage": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - } - } - } - } -} diff --git a/owl-bot-staging/v1/src/v1/schema_service_proto_list.json b/owl-bot-staging/v1/src/v1/schema_service_proto_list.json deleted file mode 100644 index 91011aec1..000000000 --- a/owl-bot-staging/v1/src/v1/schema_service_proto_list.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "../../protos/google/pubsub/v1/pubsub.proto", - "../../protos/google/pubsub/v1/schema.proto" -] diff --git a/owl-bot-staging/v1/src/v1/subscriber_client.ts b/owl-bot-staging/v1/src/v1/subscriber_client.ts deleted file mode 100644 index 6fe239510..000000000 --- a/owl-bot-staging/v1/src/v1/subscriber_client.ts +++ /dev/null @@ -1,2204 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos} from 'google-gax'; -import {Transform, PassThrough} from 'stream'; -import * as protos from '../../protos/protos'; -import jsonProtos = require('../../protos/protos.json'); -/** - * Client JSON configuration object, loaded from - * `src/v1/subscriber_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './subscriber_client_config.json'; -const version = require('../../../package.json').version; - -/** - * The service that an application uses to manipulate subscriptions and to - * consume messages from a subscription via the `Pull` method or by - * establishing a bi-directional stream using the `StreamingPull` method. - * @class - * @memberof v1 - */ -export class SubscriberClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - iamClient: IamClient; - pathTemplates: {[name: string]: gax.PathTemplate}; - subscriberStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of SubscriberClient. - * - * @param {object} [options] - The configuration object. - * The options accepted by the constructor are described in detail - * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. - * For more information, please check the - * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. - * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you - * need to avoid loading the default gRPC version and want to use the fallback - * HTTP implementation. Load only fallback version and pass it to the constructor: - * ``` - * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC - * const client = new SubscriberClient({fallback: true}, gax); - * ``` - */ - constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof SubscriberClient; - const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.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); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { - opts['scopes'] = staticMembers.scopes; - } - - // Load google-gax module synchronously if needed - if (!gaxInstance) { - gaxInstance = require('google-gax') as typeof gax; - } - - // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); - - - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; - if (typeof process !== 'undefined' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' - ), - projectTopicPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/topics/{topic}' - ), - schemaPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/schemas/{schema}' - ), - snapshotPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/snapshots/{snapshot}' - ), - subscriptionPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/subscriptions/{subscription}' - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listSubscriptions: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'subscriptions'), - listSnapshots: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'snapshots') - }; - - // Some of the methods on this service provide streaming responses. - // Provide descriptors for these. - this.descriptors.stream = { - streamingPull: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback) - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.pubsub.v1.Subscriber', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.subscriberStub) { - return this.subscriberStub; - } - - // Put together the "service stub" for - // google.pubsub.v1.Subscriber. - this.subscriberStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.pubsub.v1.Subscriber') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.pubsub.v1.Subscriber, - 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 subscriberStubMethods = - ['createSubscription', 'getSubscription', 'updateSubscription', 'listSubscriptions', 'deleteSubscription', 'modifyAckDeadline', 'acknowledge', 'pull', 'streamingPull', 'modifyPushConfig', 'getSnapshot', 'listSnapshots', 'createSnapshot', 'updateSnapshot', 'deleteSnapshot', 'seek']; - for (const methodName of subscriberStubMethods) { - const callPromise = this.subscriberStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - if (methodName in this.descriptors.stream) { - const stream = new PassThrough(); - setImmediate(() => { - stream.emit('error', new this._gaxModule.GoogleError('The client has already been closed.')); - }); - return stream; - } - 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] || - this.descriptors.stream[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.subscriberStub; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - return 'pubsub.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - return 'pubsub.googleapis.com'; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/pubsub' - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId(callback?: Callback): - Promise|void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- -/** - * Creates a subscription to a given topic. See the [resource name rules] - * (https://cloud.google.com/pubsub/docs/admin#resource_names). - * If the subscription already exists, returns `ALREADY_EXISTS`. - * If the corresponding topic doesn't exist, returns `NOT_FOUND`. - * - * If the name is not provided in the request, the server will assign a random - * name for this subscription on the same project as the topic, conforming - * to the [resource name format] - * (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated - * name is populated in the returned Subscription object. Note that for REST - * API requests, you must specify a name in the request. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the subscription. It must have the format - * `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must - * start with a letter, and contain only letters (`[A-Za-z]`), numbers - * (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), - * plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters - * in length, and it must not start with `"goog"`. - * @param {string} request.topic - * Required. The name of the topic from which this subscription is receiving - * messages. Format is `projects/{project}/topics/{topic}`. The value of this - * field will be `_deleted-topic_` if the topic has been deleted. - * @param {google.pubsub.v1.PushConfig} request.pushConfig - * If push delivery is used with this subscription, this field is - * used to configure it. - * @param {google.pubsub.v1.BigQueryConfig} request.bigqueryConfig - * If delivery to BigQuery is used with this subscription, this field is - * used to configure it. - * @param {google.pubsub.v1.CloudStorageConfig} request.cloudStorageConfig - * If delivery to Google Cloud Storage is used with this subscription, this - * field is used to configure it. - * @param {number} request.ackDeadlineSeconds - * The approximate amount of time (on a best-effort basis) Pub/Sub waits for - * the subscriber to acknowledge receipt before resending the message. In the - * interval after the message is delivered and before it is acknowledged, it - * is considered to be _outstanding_. During that time period, the - * message will not be redelivered (on a best-effort basis). - * - * For pull subscriptions, this value is used as the initial value for the ack - * deadline. To override this value for a given message, call - * `ModifyAckDeadline` with the corresponding `ack_id` if using - * non-streaming pull or send the `ack_id` in a - * `StreamingModifyAckDeadlineRequest` if using streaming pull. - * The minimum custom deadline you can specify is 10 seconds. - * The maximum custom deadline you can specify is 600 seconds (10 minutes). - * If this parameter is 0, a default value of 10 seconds is used. - * - * For push delivery, this value is also used to set the request timeout for - * the call to the push endpoint. - * - * If the subscriber never acknowledges the message, the Pub/Sub - * system will eventually redeliver the message. - * @param {boolean} request.retainAckedMessages - * Indicates whether to retain acknowledged messages. If true, then - * messages are not expunged from the subscription's backlog, even if they are - * acknowledged, until they fall out of the `message_retention_duration` - * window. This must be true if you would like to [`Seek` to a timestamp] - * (https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) in - * the past to replay previously-acknowledged messages. - * @param {google.protobuf.Duration} request.messageRetentionDuration - * How long to retain unacknowledged messages in the subscription's backlog, - * from the moment a message is published. - * If `retain_acked_messages` is true, then this also configures the retention - * of acknowledged messages, and thus configures how far back in time a `Seek` - * can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 - * minutes. - * @param {number[]} request.labels - * See [Creating and managing - * labels](https://cloud.google.com/pubsub/docs/labels). - * @param {boolean} request.enableMessageOrdering - * If true, messages published with the same `ordering_key` in `PubsubMessage` - * will be delivered to the subscribers in the order in which they - * are received by the Pub/Sub system. Otherwise, they may be delivered in - * any order. - * @param {google.pubsub.v1.ExpirationPolicy} request.expirationPolicy - * A policy that specifies the conditions for this subscription's expiration. - * A subscription is considered active as long as any connected subscriber is - * successfully consuming messages from the subscription or is issuing - * operations on the subscription. If `expiration_policy` is not set, a - * *default policy* with `ttl` of 31 days will be used. The minimum allowed - * value for `expiration_policy.ttl` is 1 day. If `expiration_policy` is set, - * but `expiration_policy.ttl` is not set, the subscription never expires. - * @param {string} request.filter - * An expression written in the Pub/Sub [filter - * language](https://cloud.google.com/pubsub/docs/filtering). If non-empty, - * then only `PubsubMessage`s whose `attributes` field matches the filter are - * delivered on this subscription. If empty, then no messages are filtered - * out. - * @param {google.pubsub.v1.DeadLetterPolicy} request.deadLetterPolicy - * A policy that specifies the conditions for dead lettering messages in - * this subscription. If dead_letter_policy is not set, dead lettering - * is disabled. - * - * The Cloud Pub/Sub service account associated with this subscriptions's - * parent project (i.e., - * service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have - * permission to Acknowledge() messages on this subscription. - * @param {google.pubsub.v1.RetryPolicy} request.retryPolicy - * A policy that specifies how Pub/Sub retries message delivery for this - * subscription. - * - * If not set, the default retry policy is applied. This generally implies - * that messages will be retried as soon as possible for healthy subscribers. - * RetryPolicy will be triggered on NACKs or acknowledgement deadline - * exceeded events for a given message. - * @param {boolean} request.detached - * Indicates whether the subscription is detached from its topic. Detached - * subscriptions don't receive messages from their topic and don't retain any - * backlog. `Pull` and `StreamingPull` requests will return - * FAILED_PRECONDITION. If the subscription is a push subscription, pushes to - * the endpoint will not be made. - * @param {boolean} request.enableExactlyOnceDelivery - * If true, Pub/Sub provides the following guarantees for the delivery of - * a message with a given value of `message_id` on this subscription: - * - * * The message sent to a subscriber is guaranteed not to be resent - * before the message's acknowledgement deadline expires. - * * An acknowledged message will not be resent to a subscriber. - * - * Note that subscribers may still receive multiple copies of a message - * when `enable_exactly_once_delivery` is true if the message was published - * multiple times by a publisher client. These copies are considered distinct - * by Pub/Sub and have distinct `message_id` values. - * @param {google.protobuf.Duration} request.topicMessageRetentionDuration - * Output only. Indicates the minimum duration for which a message is retained - * after it is published to the subscription's topic. If this field is set, - * messages published to the subscription's topic in the last - * `topic_message_retention_duration` are always available to subscribers. See - * the `message_retention_duration` field in `Topic`. This field is set only - * in responses from the server; it is ignored if it is set in any requests. - * @param {google.pubsub.v1.Subscription.State} request.state - * Output only. An output-only field indicating whether or not the - * subscription can receive messages. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Subscription|Subscription}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - createSubscription( - request?: protos.google.pubsub.v1.ISubscription, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.ISubscription|undefined, {}|undefined - ]>; - createSubscription( - request: protos.google.pubsub.v1.ISubscription, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.ISubscription|null|undefined, - {}|null|undefined>): void; - createSubscription( - request: protos.google.pubsub.v1.ISubscription, - callback: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.ISubscription|null|undefined, - {}|null|undefined>): void; - createSubscription( - request?: protos.google.pubsub.v1.ISubscription, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.ISubscription|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.ISubscription|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.ISubscription|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.createSubscription(request, options, callback); - } -/** - * Gets the configuration details of a subscription. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The name of the subscription to get. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Subscription|Subscription}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - getSubscription( - request?: protos.google.pubsub.v1.IGetSubscriptionRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IGetSubscriptionRequest|undefined, {}|undefined - ]>; - getSubscription( - request: protos.google.pubsub.v1.IGetSubscriptionRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - getSubscription( - request: protos.google.pubsub.v1.IGetSubscriptionRequest, - callback: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - getSubscription( - request?: protos.google.pubsub.v1.IGetSubscriptionRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IGetSubscriptionRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IGetSubscriptionRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.getSubscription(request, options, callback); - } -/** - * Updates an existing subscription. Note that certain properties of a - * subscription, such as its topic, are not modifiable. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.pubsub.v1.Subscription} request.subscription - * Required. The updated subscription object. - * @param {google.protobuf.FieldMask} request.updateMask - * Required. Indicates which fields in the provided subscription to update. - * Must be specified and non-empty. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Subscription|Subscription}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - updateSubscription( - request?: protos.google.pubsub.v1.IUpdateSubscriptionRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IUpdateSubscriptionRequest|undefined, {}|undefined - ]>; - updateSubscription( - request: protos.google.pubsub.v1.IUpdateSubscriptionRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - updateSubscription( - request: protos.google.pubsub.v1.IUpdateSubscriptionRequest, - callback: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - updateSubscription( - request?: protos.google.pubsub.v1.IUpdateSubscriptionRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IUpdateSubscriptionRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISubscription, - protos.google.pubsub.v1.IUpdateSubscriptionRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription.name': request.subscription!.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.updateSubscription(request, options, callback); - } -/** - * Deletes an existing subscription. All messages retained in the subscription - * are immediately dropped. Calls to `Pull` after deletion will return - * `NOT_FOUND`. After a subscription is deleted, a new one may be created with - * the same name, but the new one has no association with the old - * subscription or its topic unless the same topic is specified. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The subscription to delete. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - deleteSubscription( - request?: protos.google.pubsub.v1.IDeleteSubscriptionRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSubscriptionRequest|undefined, {}|undefined - ]>; - deleteSubscription( - request: protos.google.pubsub.v1.IDeleteSubscriptionRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - deleteSubscription( - request: protos.google.pubsub.v1.IDeleteSubscriptionRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, - {}|null|undefined>): void; - deleteSubscription( - request?: protos.google.pubsub.v1.IDeleteSubscriptionRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSubscriptionRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSubscriptionRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.deleteSubscription(request, options, callback); - } -/** - * Modifies the ack deadline for a specific message. This method is useful - * to indicate that more time is needed to process a message by the - * subscriber, or to make the message available for redelivery if the - * processing was interrupted. Note that this does not modify the - * subscription-level `ackDeadlineSeconds` used for subsequent messages. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The name of the subscription. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {string[]} request.ackIds - * Required. List of acknowledgment IDs. - * @param {number} request.ackDeadlineSeconds - * Required. The new ack deadline with respect to the time this request was - * sent to the Pub/Sub system. For example, if the value is 10, the new ack - * deadline will expire 10 seconds after the `ModifyAckDeadline` call was - * made. Specifying zero might immediately make the message available for - * delivery to another subscriber client. This typically results in an - * increase in the rate of message redeliveries (that is, duplicates). - * The minimum deadline you can specify is 0 seconds. - * The maximum deadline you can specify is 600 seconds (10 minutes). - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - modifyAckDeadline( - request?: protos.google.pubsub.v1.IModifyAckDeadlineRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyAckDeadlineRequest|undefined, {}|undefined - ]>; - modifyAckDeadline( - request: protos.google.pubsub.v1.IModifyAckDeadlineRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, - {}|null|undefined>): void; - modifyAckDeadline( - request: protos.google.pubsub.v1.IModifyAckDeadlineRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, - {}|null|undefined>): void; - modifyAckDeadline( - request?: protos.google.pubsub.v1.IModifyAckDeadlineRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyAckDeadlineRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyAckDeadlineRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.modifyAckDeadline(request, options, callback); - } -/** - * Acknowledges the messages associated with the `ack_ids` in the - * `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages - * from the subscription. - * - * Acknowledging a message whose ack deadline has expired may succeed, - * but such a message may be redelivered later. Acknowledging a message more - * than once will not result in an error. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The subscription whose message is being acknowledged. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {string[]} request.ackIds - * Required. The acknowledgment ID for the messages being acknowledged that - * was returned by the Pub/Sub system in the `Pull` response. Must not be - * empty. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - acknowledge( - request?: protos.google.pubsub.v1.IAcknowledgeRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IAcknowledgeRequest|undefined, {}|undefined - ]>; - acknowledge( - request: protos.google.pubsub.v1.IAcknowledgeRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, - {}|null|undefined>): void; - acknowledge( - request: protos.google.pubsub.v1.IAcknowledgeRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, - {}|null|undefined>): void; - acknowledge( - request?: protos.google.pubsub.v1.IAcknowledgeRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IAcknowledgeRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IAcknowledgeRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.acknowledge(request, options, callback); - } -/** - * Pulls messages from the server. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The subscription from which messages should be pulled. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {boolean} [request.returnImmediately] - * Optional. If this field set to true, the system will respond immediately - * even if it there are no messages available to return in the `Pull` - * response. Otherwise, the system may wait (for a bounded amount of time) - * until at least one message is available, rather than returning no messages. - * Warning: setting this field to `true` is discouraged because it adversely - * impacts the performance of `Pull` operations. We recommend that users do - * not set this field. - * @param {number} request.maxMessages - * Required. The maximum number of messages to return for this request. Must - * be a positive integer. The Pub/Sub system may return fewer than the number - * specified. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.PullResponse|PullResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - pull( - request?: protos.google.pubsub.v1.IPullRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.IPullResponse, - protos.google.pubsub.v1.IPullRequest|undefined, {}|undefined - ]>; - pull( - request: protos.google.pubsub.v1.IPullRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.IPullResponse, - protos.google.pubsub.v1.IPullRequest|null|undefined, - {}|null|undefined>): void; - pull( - request: protos.google.pubsub.v1.IPullRequest, - callback: Callback< - protos.google.pubsub.v1.IPullResponse, - protos.google.pubsub.v1.IPullRequest|null|undefined, - {}|null|undefined>): void; - pull( - request?: protos.google.pubsub.v1.IPullRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.IPullResponse, - protos.google.pubsub.v1.IPullRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.IPullResponse, - protos.google.pubsub.v1.IPullRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.IPullResponse, - protos.google.pubsub.v1.IPullRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.pull(request, options, callback); - } -/** - * Modifies the `PushConfig` for a specified subscription. - * - * This may be used to change a push subscription to a pull one (signified by - * an empty `PushConfig`) or vice versa, or change the endpoint URL and other - * attributes of a push subscription. Messages will accumulate for delivery - * continuously through the call regardless of changes to the `PushConfig`. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The name of the subscription. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {google.pubsub.v1.PushConfig} request.pushConfig - * Required. The push configuration for future deliveries. - * - * An empty `pushConfig` indicates that the Pub/Sub system should - * stop pushing messages from the given subscription and allow - * messages to be pulled and acknowledged - effectively pausing - * the subscription if `Pull` or `StreamingPull` is not called. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - modifyPushConfig( - request?: protos.google.pubsub.v1.IModifyPushConfigRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyPushConfigRequest|undefined, {}|undefined - ]>; - modifyPushConfig( - request: protos.google.pubsub.v1.IModifyPushConfigRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, - {}|null|undefined>): void; - modifyPushConfig( - request: protos.google.pubsub.v1.IModifyPushConfigRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, - {}|null|undefined>): void; - modifyPushConfig( - request?: protos.google.pubsub.v1.IModifyPushConfigRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyPushConfigRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IModifyPushConfigRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.modifyPushConfig(request, options, callback); - } -/** - * Gets the configuration details of a snapshot. Snapshots are used in - * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - * which allow you to manage message acknowledgments in bulk. That is, you can - * set the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.snapshot - * Required. The name of the snapshot to get. - * Format is `projects/{project}/snapshots/{snap}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - getSnapshot( - request?: protos.google.pubsub.v1.IGetSnapshotRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IGetSnapshotRequest|undefined, {}|undefined - ]>; - getSnapshot( - request: protos.google.pubsub.v1.IGetSnapshotRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, - {}|null|undefined>): void; - getSnapshot( - request: protos.google.pubsub.v1.IGetSnapshotRequest, - callback: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, - {}|null|undefined>): void; - getSnapshot( - request?: protos.google.pubsub.v1.IGetSnapshotRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IGetSnapshotRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IGetSnapshotRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'snapshot': request.snapshot ?? '', - }); - this.initialize(); - return this.innerApiCalls.getSnapshot(request, options, callback); - } -/** - * Creates a snapshot from the requested subscription. Snapshots are used in - * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - * which allow you to manage message acknowledgments in bulk. That is, you can - * set the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. - * If the snapshot already exists, returns `ALREADY_EXISTS`. - * If the requested subscription doesn't exist, returns `NOT_FOUND`. - * If the backlog in the subscription is too old -- and the resulting snapshot - * would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. - * See also the `Snapshot.expire_time` field. If the name is not provided in - * the request, the server will assign a random - * name for this snapshot on the same project as the subscription, conforming - * to the [resource name format] - * (https://cloud.google.com/pubsub/docs/admin#resource_names). The - * generated name is populated in the returned Snapshot object. Note that for - * REST API requests, you must specify a name in the request. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. User-provided name for this snapshot. If the name is not provided - * in the request, the server will assign a random name for this snapshot on - * the same project as the subscription. Note that for REST API requests, you - * must specify a name. See the [resource name - * rules](https://cloud.google.com/pubsub/docs/admin#resource_names). Format - * is `projects/{project}/snapshots/{snap}`. - * @param {string} request.subscription - * Required. The subscription whose backlog the snapshot retains. - * Specifically, the created snapshot is guaranteed to retain: - * (a) The existing backlog on the subscription. More precisely, this is - * defined as the messages in the subscription's backlog that are - * unacknowledged upon the successful completion of the - * `CreateSnapshot` request; as well as: - * (b) Any messages published to the subscription's topic following the - * successful completion of the CreateSnapshot request. - * Format is `projects/{project}/subscriptions/{sub}`. - * @param {number[]} request.labels - * See [Creating and managing - * labels](https://cloud.google.com/pubsub/docs/labels). - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - createSnapshot( - request?: protos.google.pubsub.v1.ICreateSnapshotRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.ICreateSnapshotRequest|undefined, {}|undefined - ]>; - createSnapshot( - request: protos.google.pubsub.v1.ICreateSnapshotRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, - {}|null|undefined>): void; - createSnapshot( - request: protos.google.pubsub.v1.ICreateSnapshotRequest, - callback: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, - {}|null|undefined>): void; - createSnapshot( - request?: protos.google.pubsub.v1.ICreateSnapshotRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.ICreateSnapshotRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.ICreateSnapshotRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'name': request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.createSnapshot(request, options, callback); - } -/** - * Updates an existing snapshot. Snapshots are used in - * [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, - * which allow you to manage message acknowledgments in bulk. That is, you can - * set the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.pubsub.v1.Snapshot} request.snapshot - * Required. The updated snapshot object. - * @param {google.protobuf.FieldMask} request.updateMask - * Required. Indicates which fields in the provided snapshot to update. - * Must be specified and non-empty. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.Snapshot|Snapshot}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - updateSnapshot( - request?: protos.google.pubsub.v1.IUpdateSnapshotRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IUpdateSnapshotRequest|undefined, {}|undefined - ]>; - updateSnapshot( - request: protos.google.pubsub.v1.IUpdateSnapshotRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, - {}|null|undefined>): void; - updateSnapshot( - request: protos.google.pubsub.v1.IUpdateSnapshotRequest, - callback: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, - {}|null|undefined>): void; - updateSnapshot( - request?: protos.google.pubsub.v1.IUpdateSnapshotRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IUpdateSnapshotRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISnapshot, - protos.google.pubsub.v1.IUpdateSnapshotRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'snapshot.name': request.snapshot!.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.updateSnapshot(request, options, callback); - } -/** - * Removes an existing snapshot. Snapshots are used in [Seek] - * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which - * allow you to manage message acknowledgments in bulk. That is, you can set - * the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. - * When the snapshot is deleted, all messages retained in the snapshot - * are immediately dropped. After a snapshot is deleted, a new one may be - * created with the same name, but the new one has no association with the old - * snapshot or its subscription, unless the same subscription is specified. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.snapshot - * Required. The name of the snapshot to delete. - * Format is `projects/{project}/snapshots/{snap}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for 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. - */ - deleteSnapshot( - request?: protos.google.pubsub.v1.IDeleteSnapshotRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSnapshotRequest|undefined, {}|undefined - ]>; - deleteSnapshot( - request: protos.google.pubsub.v1.IDeleteSnapshotRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, - {}|null|undefined>): void; - deleteSnapshot( - request: protos.google.pubsub.v1.IDeleteSnapshotRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, - {}|null|undefined>): void; - deleteSnapshot( - request?: protos.google.pubsub.v1.IDeleteSnapshotRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSnapshotRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.pubsub.v1.IDeleteSnapshotRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'snapshot': request.snapshot ?? '', - }); - this.initialize(); - return this.innerApiCalls.deleteSnapshot(request, options, callback); - } -/** - * Seeks an existing subscription to a point in time or to a given snapshot, - * whichever is provided in the request. Snapshots are used in [Seek] - * (https://cloud.google.com/pubsub/docs/replay-overview) operations, which - * allow you to manage message acknowledgments in bulk. That is, you can set - * the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. Note that both the subscription and the - * snapshot must be on the same topic. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.subscription - * Required. The subscription to affect. - * @param {google.protobuf.Timestamp} request.time - * The time to seek to. - * Messages retained in the subscription that were published before this - * time are marked as acknowledged, and messages retained in the - * subscription that were published after this time are marked as - * unacknowledged. Note that this operation affects only those messages - * retained in the subscription (configured by the combination of - * `message_retention_duration` and `retain_acked_messages`). For example, - * if `time` corresponds to a point before the message retention - * window (or to a point before the system's notion of the subscription - * creation time), only retained messages will be marked as unacknowledged, - * and already-expunged messages will not be restored. - * @param {string} request.snapshot - * The snapshot to seek to. The snapshot's topic must be the same as that of - * the provided subscription. - * Format is `projects/{project}/snapshots/{snap}`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link protos.google.pubsub.v1.SeekResponse|SeekResponse}. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } - * for more details and examples. - */ - seek( - request?: protos.google.pubsub.v1.ISeekRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISeekResponse, - protos.google.pubsub.v1.ISeekRequest|undefined, {}|undefined - ]>; - seek( - request: protos.google.pubsub.v1.ISeekRequest, - options: CallOptions, - callback: Callback< - protos.google.pubsub.v1.ISeekResponse, - protos.google.pubsub.v1.ISeekRequest|null|undefined, - {}|null|undefined>): void; - seek( - request: protos.google.pubsub.v1.ISeekRequest, - callback: Callback< - protos.google.pubsub.v1.ISeekResponse, - protos.google.pubsub.v1.ISeekRequest|null|undefined, - {}|null|undefined>): void; - seek( - request?: protos.google.pubsub.v1.ISeekRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.pubsub.v1.ISeekResponse, - protos.google.pubsub.v1.ISeekRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.pubsub.v1.ISeekResponse, - protos.google.pubsub.v1.ISeekRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.pubsub.v1.ISeekResponse, - protos.google.pubsub.v1.ISeekRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'subscription': request.subscription ?? '', - }); - this.initialize(); - return this.innerApiCalls.seek(request, options, callback); - } - -/** - * Establishes a stream with the server, which sends messages down to the - * client. The client streams acknowledgements and ack deadline modifications - * back to the server. The server will close the stream and return the status - * on any error. The server may close the stream with status `UNAVAILABLE` to - * reassign server-side resources, in which case, the client should - * re-establish the stream. Flow control can be achieved by configuring the - * underlying RPC channel. - * - * @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 is both readable and writable. It accepts objects - * representing {@link protos.google.pubsub.v1.StreamingPullRequest|StreamingPullRequest} for write() method, and - * will emit objects representing {@link protos.google.pubsub.v1.StreamingPullResponse|StreamingPullResponse} on 'data' event asynchronously. - * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation } - * for more details and examples. - */ - streamingPull( - options?: CallOptions): - gax.CancellableStream { - this.initialize(); - return this.innerApiCalls.streamingPull(null, options); - } - - /** - * Lists matching subscriptions. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Required. The name of the project in which to list subscriptions. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of subscriptions to return. - * @param {string} request.pageToken - * The value returned by the last `ListSubscriptionsResponse`; indicates that - * this is a continuation of a prior `ListSubscriptions` call, and that the - * system should return the next page of data. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Subscription|Subscription}. - * 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 `listSubscriptionsAsync()` - * 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. - */ - listSubscriptions( - request?: protos.google.pubsub.v1.IListSubscriptionsRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISubscription[], - protos.google.pubsub.v1.IListSubscriptionsRequest|null, - protos.google.pubsub.v1.IListSubscriptionsResponse - ]>; - listSubscriptions( - request: protos.google.pubsub.v1.IListSubscriptionsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSubscriptionsRequest, - protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, - protos.google.pubsub.v1.ISubscription>): void; - listSubscriptions( - request: protos.google.pubsub.v1.IListSubscriptionsRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSubscriptionsRequest, - protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, - protos.google.pubsub.v1.ISubscription>): void; - listSubscriptions( - request?: protos.google.pubsub.v1.IListSubscriptionsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListSubscriptionsRequest, - protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, - protos.google.pubsub.v1.ISubscription>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListSubscriptionsRequest, - protos.google.pubsub.v1.IListSubscriptionsResponse|null|undefined, - protos.google.pubsub.v1.ISubscription>): - Promise<[ - protos.google.pubsub.v1.ISubscription[], - protos.google.pubsub.v1.IListSubscriptionsRequest|null, - protos.google.pubsub.v1.IListSubscriptionsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'project': request.project ?? '', - }); - this.initialize(); - return this.innerApiCalls.listSubscriptions(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Required. The name of the project in which to list subscriptions. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of subscriptions to return. - * @param {string} request.pageToken - * The value returned by the last `ListSubscriptionsResponse`; indicates that - * this is a continuation of a prior `ListSubscriptions` call, and that the - * system should return the next page of data. - * @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.pubsub.v1.Subscription|Subscription} 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 `listSubscriptionsAsync()` - * 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. - */ - listSubscriptionsStream( - request?: protos.google.pubsub.v1.IListSubscriptionsRequest, - 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({ - 'project': request.project ?? '', - }); - const defaultCallSettings = this._defaults['listSubscriptions']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSubscriptions.createStream( - this.innerApiCalls.listSubscriptions as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listSubscriptions`, 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.project - * Required. The name of the project in which to list subscriptions. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of subscriptions to return. - * @param {string} request.pageToken - * The value returned by the last `ListSubscriptionsResponse`; indicates that - * this is a continuation of a prior `ListSubscriptions` call, and that the - * system should return the next page of data. - * @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.pubsub.v1.Subscription|Subscription}. 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. - */ - listSubscriptionsAsync( - request?: protos.google.pubsub.v1.IListSubscriptionsRequest, - 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({ - 'project': request.project ?? '', - }); - const defaultCallSettings = this._defaults['listSubscriptions']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSubscriptions.asyncIterate( - this.innerApiCalls['listSubscriptions'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - /** - * Lists the existing snapshots. Snapshots are used in [Seek]( - * https://cloud.google.com/pubsub/docs/replay-overview) operations, which - * allow you to manage message acknowledgments in bulk. That is, you can set - * the acknowledgment state of messages in an existing subscription to the - * state captured by a snapshot. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Required. The name of the project in which to list snapshots. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of snapshots to return. - * @param {string} request.pageToken - * The value returned by the last `ListSnapshotsResponse`; indicates that this - * is a continuation of a prior `ListSnapshots` call, and that the system - * should return the next page of data. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/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.pubsub.v1.Snapshot|Snapshot}. - * 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 `listSnapshotsAsync()` - * 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. - */ - listSnapshots( - request?: protos.google.pubsub.v1.IListSnapshotsRequest, - options?: CallOptions): - Promise<[ - protos.google.pubsub.v1.ISnapshot[], - protos.google.pubsub.v1.IListSnapshotsRequest|null, - protos.google.pubsub.v1.IListSnapshotsResponse - ]>; - listSnapshots( - request: protos.google.pubsub.v1.IListSnapshotsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSnapshotsRequest, - protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, - protos.google.pubsub.v1.ISnapshot>): void; - listSnapshots( - request: protos.google.pubsub.v1.IListSnapshotsRequest, - callback: PaginationCallback< - protos.google.pubsub.v1.IListSnapshotsRequest, - protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, - protos.google.pubsub.v1.ISnapshot>): void; - listSnapshots( - request?: protos.google.pubsub.v1.IListSnapshotsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.pubsub.v1.IListSnapshotsRequest, - protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, - protos.google.pubsub.v1.ISnapshot>, - callback?: PaginationCallback< - protos.google.pubsub.v1.IListSnapshotsRequest, - protos.google.pubsub.v1.IListSnapshotsResponse|null|undefined, - protos.google.pubsub.v1.ISnapshot>): - Promise<[ - protos.google.pubsub.v1.ISnapshot[], - protos.google.pubsub.v1.IListSnapshotsRequest|null, - protos.google.pubsub.v1.IListSnapshotsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = this._gaxModule.routingHeader.fromParams({ - 'project': request.project ?? '', - }); - this.initialize(); - return this.innerApiCalls.listSnapshots(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.project - * Required. The name of the project in which to list snapshots. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of snapshots to return. - * @param {string} request.pageToken - * The value returned by the last `ListSnapshotsResponse`; indicates that this - * is a continuation of a prior `ListSnapshots` call, and that the system - * should return the next page of data. - * @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.pubsub.v1.Snapshot|Snapshot} 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 `listSnapshotsAsync()` - * 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. - */ - listSnapshotsStream( - request?: protos.google.pubsub.v1.IListSnapshotsRequest, - 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({ - 'project': request.project ?? '', - }); - const defaultCallSettings = this._defaults['listSnapshots']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSnapshots.createStream( - this.innerApiCalls.listSnapshots as GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listSnapshots`, 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.project - * Required. The name of the project in which to list snapshots. - * Format is `projects/{project-id}`. - * @param {number} request.pageSize - * Maximum number of snapshots to return. - * @param {string} request.pageToken - * The value returned by the last `ListSnapshotsResponse`; indicates that this - * is a continuation of a prior `ListSnapshots` call, and that the system - * should return the next page of data. - * @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.pubsub.v1.Snapshot|Snapshot}. 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. - */ - listSnapshotsAsync( - request?: protos.google.pubsub.v1.IListSnapshotsRequest, - 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({ - 'project': request.project ?? '', - }); - const defaultCallSettings = this._defaults['listSnapshots']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSnapshots.asyncIterate( - this.innerApiCalls['listSnapshots'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } -/** - * Gets the access control policy for a resource. Returns an empty policy - * if the resource exists and does not have a policy set. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {Object} [request.options] - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. This field is only used by Cloud IAM. - * - * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.Policy | Policy}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ - getIamPolicy( - request: IamProtos.google.iam.v1.GetIamPolicyRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.GetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.Policy]> { - return this.iamClient.getIamPolicy(request, options, callback); - } - -/** - * Returns permissions that a caller has on the specified resource. If the - * resource does not exist, this will return an empty set of - * permissions, not a NOT_FOUND error. - * - * Note: This operation is designed to be used for building - * permission-aware UIs and command-line tools, not for authorization - * checking. This operation may "fail open" without warning. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ - setIamPolicy( - request: IamProtos.google.iam.v1.SetIamPolicyRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.Policy, - IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.Policy]> { - return this.iamClient.setIamPolicy(request, options, callback); - } - -/** - * Returns permissions that a caller has on the specified resource. If the - * resource does not exist, this will return an empty set of - * permissions, not a NOT_FOUND error. - * - * Note: This operation is designed to be used for building - * permission-aware UIs and command-line tools, not for authorization - * checking. This operation may "fail open" without warning. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. - * @param {Object} [options] - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html | gax.CallOptions} for the details. - * @param {function(?Error, ?Object)} [callback] - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - */ - testIamPermissions( - request: IamProtos.google.iam.v1.TestIamPermissionsRequest, - options?: - | gax.CallOptions - | Callback< - IamProtos.google.iam.v1.TestIamPermissionsResponse, - IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - IamProtos.google.iam.v1.TestIamPermissionsResponse, - IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, - {} | null | undefined - > - ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { - return this.iamClient.testIamPermissions(request, options, callback); - } - - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified project resource name string. - * - * @param {string} project - * @returns {string} Resource name string. - */ - projectPath(project:string) { - return this.pathTemplates.projectPathTemplate.render({ - project: project, - }); - } - - /** - * Parse the project from Project resource. - * - * @param {string} projectName - * A fully-qualified path representing Project resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectName(projectName: string) { - return this.pathTemplates.projectPathTemplate.match(projectName).project; - } - - /** - * Return a fully-qualified projectTopic resource name string. - * - * @param {string} project - * @param {string} topic - * @returns {string} Resource name string. - */ - projectTopicPath(project:string,topic:string) { - return this.pathTemplates.projectTopicPathTemplate.render({ - project: project, - topic: topic, - }); - } - - /** - * Parse the project from ProjectTopic resource. - * - * @param {string} projectTopicName - * A fully-qualified path representing project_topic resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectTopicName(projectTopicName: string) { - return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).project; - } - - /** - * Parse the topic from ProjectTopic resource. - * - * @param {string} projectTopicName - * A fully-qualified path representing project_topic resource. - * @returns {string} A string representing the topic. - */ - matchTopicFromProjectTopicName(projectTopicName: string) { - return this.pathTemplates.projectTopicPathTemplate.match(projectTopicName).topic; - } - - /** - * Return a fully-qualified schema resource name string. - * - * @param {string} project - * @param {string} schema - * @returns {string} Resource name string. - */ - schemaPath(project:string,schema:string) { - return this.pathTemplates.schemaPathTemplate.render({ - project: project, - schema: schema, - }); - } - - /** - * Parse the project from Schema resource. - * - * @param {string} schemaName - * A fully-qualified path representing Schema resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSchemaName(schemaName: string) { - return this.pathTemplates.schemaPathTemplate.match(schemaName).project; - } - - /** - * Parse the schema from Schema resource. - * - * @param {string} schemaName - * A fully-qualified path representing Schema resource. - * @returns {string} A string representing the schema. - */ - matchSchemaFromSchemaName(schemaName: string) { - return this.pathTemplates.schemaPathTemplate.match(schemaName).schema; - } - - /** - * Return a fully-qualified snapshot resource name string. - * - * @param {string} project - * @param {string} snapshot - * @returns {string} Resource name string. - */ - snapshotPath(project:string,snapshot:string) { - return this.pathTemplates.snapshotPathTemplate.render({ - project: project, - snapshot: snapshot, - }); - } - - /** - * Parse the project from Snapshot resource. - * - * @param {string} snapshotName - * A fully-qualified path representing Snapshot resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSnapshotName(snapshotName: string) { - return this.pathTemplates.snapshotPathTemplate.match(snapshotName).project; - } - - /** - * Parse the snapshot from Snapshot resource. - * - * @param {string} snapshotName - * A fully-qualified path representing Snapshot resource. - * @returns {string} A string representing the snapshot. - */ - matchSnapshotFromSnapshotName(snapshotName: string) { - return this.pathTemplates.snapshotPathTemplate.match(snapshotName).snapshot; - } - - /** - * Return a fully-qualified subscription resource name string. - * - * @param {string} project - * @param {string} subscription - * @returns {string} Resource name string. - */ - subscriptionPath(project:string,subscription:string) { - return this.pathTemplates.subscriptionPathTemplate.render({ - project: project, - subscription: subscription, - }); - } - - /** - * Parse the project from Subscription resource. - * - * @param {string} subscriptionName - * A fully-qualified path representing Subscription resource. - * @returns {string} A string representing the project. - */ - matchProjectFromSubscriptionName(subscriptionName: string) { - return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).project; - } - - /** - * Parse the subscription from Subscription resource. - * - * @param {string} subscriptionName - * A fully-qualified path representing Subscription resource. - * @returns {string} A string representing the subscription. - */ - matchSubscriptionFromSubscriptionName(subscriptionName: string) { - return this.pathTemplates.subscriptionPathTemplate.match(subscriptionName).subscription; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.subscriberStub && !this._terminated) { - return this.subscriberStub.then(stub => { - this._terminated = true; - stub.close(); - this.iamClient.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/owl-bot-staging/v1/src/v1/subscriber_client_config.json b/owl-bot-staging/v1/src/v1/subscriber_client_config.json deleted file mode 100644 index a549d3010..000000000 --- a/owl-bot-staging/v1/src/v1/subscriber_client_config.json +++ /dev/null @@ -1,136 +0,0 @@ -{ - "interfaces": { - "google.pubsub.v1.Subscriber": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ], - "unknown_aborted_unavailable": [ - "UNKNOWN", - "ABORTED", - "UNAVAILABLE" - ], - "unavailable": [ - "UNAVAILABLE" - ], - "unknown_aborted_internal_unavailable": [ - "UNKNOWN", - "ABORTED", - "INTERNAL", - "UNAVAILABLE" - ], - "deadline_exceeded_resource_exhausted_aborted_internal_unavailable": [ - "DEADLINE_EXCEEDED", - "RESOURCE_EXHAUSTED", - "ABORTED", - "INTERNAL", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - }, - "693222d32e887d96c8faeadca469f7763ccda85a": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 4, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "CreateSubscription": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "GetSubscription": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "UpdateSubscription": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "ListSubscriptions": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "DeleteSubscription": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "ModifyAckDeadline": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "Acknowledge": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "Pull": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_internal_unavailable", - "retry_params_name": "default" - }, - "StreamingPull": { - "timeout_millis": 900000, - "retry_codes_name": "deadline_exceeded_resource_exhausted_aborted_internal_unavailable", - "retry_params_name": "693222d32e887d96c8faeadca469f7763ccda85a" - }, - "ModifyPushConfig": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "GetSnapshot": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "ListSnapshots": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - }, - "CreateSnapshot": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "UpdateSnapshot": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "DeleteSnapshot": { - "timeout_millis": 60000, - "retry_codes_name": "unavailable", - "retry_params_name": "default" - }, - "Seek": { - "timeout_millis": 60000, - "retry_codes_name": "unknown_aborted_unavailable", - "retry_params_name": "default" - } - } - } - } -} diff --git a/owl-bot-staging/v1/src/v1/subscriber_proto_list.json b/owl-bot-staging/v1/src/v1/subscriber_proto_list.json deleted file mode 100644 index 91011aec1..000000000 --- a/owl-bot-staging/v1/src/v1/subscriber_proto_list.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "../../protos/google/pubsub/v1/pubsub.proto", - "../../protos/google/pubsub/v1/schema.proto" -] diff --git a/owl-bot-staging/v1/test/gapic_publisher_v1.ts b/owl-bot-staging/v1/test/gapic_publisher_v1.ts deleted file mode 100644 index 8fe09a0a4..000000000 --- a/owl-bot-staging/v1/test/gapic_publisher_v1.ts +++ /dev/null @@ -1,2013 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as publisherModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, IamProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.PublisherClient', () => { - describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = publisherModule.v1.PublisherClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = publisherModule.v1.PublisherClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = publisherModule.v1.PublisherClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new publisherModule.v1.PublisherClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new publisherModule.v1.PublisherClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.publisherStub, undefined); - await client.initialize(); - assert(client.publisherStub); - }); - - it('has close method for the initialized client', done => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - assert(client.publisherStub); - client.close().then(() => { - done(); - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.publisherStub, undefined); - client.close().then(() => { - done(); - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new publisherModule.v1.PublisherClient({ - 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 publisherModule.v1.PublisherClient({ - 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('createTopic', () => { - it('invokes createTopic without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - client.innerApiCalls.createTopic = stubSimpleCall(expectedResponse); - const [response] = await client.createTopic(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTopic without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - client.innerApiCalls.createTopic = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createTopic( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ITopic|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTopic with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createTopic = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createTopic(request), expectedError); - const actualRequest = (client.innerApiCalls.createTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTopic with closed client', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Topic', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.createTopic(request), expectedError); - }); - }); - - describe('updateTopic', () => { - it('invokes updateTopic without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateTopicRequest() - ); - request.topic ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); - request.topic.name = defaultValue1; - const expectedHeaderRequestParams = `topic.name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - client.innerApiCalls.updateTopic = stubSimpleCall(expectedResponse); - const [response] = await client.updateTopic(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTopic without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateTopicRequest() - ); - request.topic ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); - request.topic.name = defaultValue1; - const expectedHeaderRequestParams = `topic.name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - client.innerApiCalls.updateTopic = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateTopic( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ITopic|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTopic with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateTopicRequest() - ); - request.topic ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); - request.topic.name = defaultValue1; - const expectedHeaderRequestParams = `topic.name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateTopic = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateTopic(request), expectedError); - const actualRequest = (client.innerApiCalls.updateTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTopic with closed client', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateTopicRequest() - ); - request.topic ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateTopicRequest', ['topic', 'name']); - request.topic.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.updateTopic(request), expectedError); - }); - }); - - describe('publish', () => { - it('invokes publish without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PublishRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.PublishResponse() - ); - client.innerApiCalls.publish = stubSimpleCall(expectedResponse); - const [response] = await client.publish(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.publish as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.publish as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes publish without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PublishRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.PublishResponse() - ); - client.innerApiCalls.publish = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.publish( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.IPublishResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.publish as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.publish as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes publish with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PublishRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.publish = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.publish(request), expectedError); - const actualRequest = (client.innerApiCalls.publish as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.publish as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes publish with closed client', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PublishRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PublishRequest', ['topic']); - request.topic = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.publish(request), expectedError); - }); - }); - - describe('getTopic', () => { - it('invokes getTopic without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - client.innerApiCalls.getTopic = stubSimpleCall(expectedResponse); - const [response] = await client.getTopic(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTopic without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Topic() - ); - client.innerApiCalls.getTopic = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getTopic( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ITopic|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTopic with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getTopic = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getTopic(request), expectedError); - const actualRequest = (client.innerApiCalls.getTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTopic with closed client', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.getTopic(request), expectedError); - }); - }); - - describe('deleteTopic', () => { - it('invokes deleteTopic without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTopic = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTopic(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTopic without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTopic = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTopic( - 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.deleteTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTopic with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTopic = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTopic(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTopic as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTopic as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTopic with closed client', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteTopicRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteTopicRequest', ['topic']); - request.topic = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.deleteTopic(request), expectedError); - }); - }); - - describe('detachSubscription', () => { - it('invokes detachSubscription without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DetachSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.DetachSubscriptionResponse() - ); - client.innerApiCalls.detachSubscription = stubSimpleCall(expectedResponse); - const [response] = await client.detachSubscription(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.detachSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detachSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detachSubscription without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DetachSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.DetachSubscriptionResponse() - ); - client.innerApiCalls.detachSubscription = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.detachSubscription( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.IDetachSubscriptionResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.detachSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detachSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detachSubscription with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DetachSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.detachSubscription = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.detachSubscription(request), expectedError); - const actualRequest = (client.innerApiCalls.detachSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detachSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detachSubscription with closed client', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DetachSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DetachSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.detachSubscription(request), expectedError); - }); - }); - - describe('listTopics', () => { - it('invokes listTopics without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - ]; - client.innerApiCalls.listTopics = stubSimpleCall(expectedResponse); - const [response] = await client.listTopics(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTopics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopics without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - ]; - client.innerApiCalls.listTopics = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTopics( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ITopic[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTopics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopics with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTopics = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTopics(request), expectedError); - const actualRequest = (client.innerApiCalls.listTopics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicsStream without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - ]; - client.descriptors.page.listTopics.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTopicsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Topic[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Topic) => { - 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.listTopics.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTopics, request)); - assert( - (client.descriptors.page.listTopics.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTopicsStream with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listTopics.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTopicsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Topic[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Topic) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTopics.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTopics, request)); - assert( - (client.descriptors.page.listTopics.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTopics without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - generateSampleMessage(new protos.google.pubsub.v1.Topic()), - ]; - client.descriptors.page.listTopics.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.pubsub.v1.ITopic[] = []; - const iterable = client.listTopicsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTopics.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTopics.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTopics with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listTopics.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTopicsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.pubsub.v1.ITopic[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTopics.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTopics.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listTopicSubscriptions', () => { - it('invokes listTopicSubscriptions without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSubscriptions = stubSimpleCall(expectedResponse); - const [response] = await client.listTopicSubscriptions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTopicSubscriptions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopicSubscriptions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicSubscriptions without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSubscriptions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTopicSubscriptions( - request, - (err?: Error|null, result?: string[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTopicSubscriptions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopicSubscriptions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicSubscriptions with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTopicSubscriptions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTopicSubscriptions(request), expectedError); - const actualRequest = (client.innerApiCalls.listTopicSubscriptions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopicSubscriptions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicSubscriptionsStream without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSubscriptions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTopicSubscriptionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - 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.listTopicSubscriptions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTopicSubscriptions, request)); - assert( - (client.descriptors.page.listTopicSubscriptions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTopicSubscriptionsStream with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listTopicSubscriptions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTopicSubscriptionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTopicSubscriptions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTopicSubscriptions, request)); - assert( - (client.descriptors.page.listTopicSubscriptions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTopicSubscriptions without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSubscriptions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: string[] = []; - const iterable = client.listTopicSubscriptionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTopicSubscriptions with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSubscriptionsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listTopicSubscriptions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTopicSubscriptionsAsync(request); - await assert.rejects(async () => { - const responses: string[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTopicSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listTopicSnapshots', () => { - it('invokes listTopicSnapshots without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSnapshots = stubSimpleCall(expectedResponse); - const [response] = await client.listTopicSnapshots(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTopicSnapshots as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopicSnapshots as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicSnapshots without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSnapshots = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTopicSnapshots( - request, - (err?: Error|null, result?: string[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTopicSnapshots as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopicSnapshots as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicSnapshots with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTopicSnapshots = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTopicSnapshots(request), expectedError); - const actualRequest = (client.innerApiCalls.listTopicSnapshots as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTopicSnapshots as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTopicSnapshotsStream without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSnapshots.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTopicSnapshotsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - 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.listTopicSnapshots.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTopicSnapshots, request)); - assert( - (client.descriptors.page.listTopicSnapshots.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTopicSnapshotsStream with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listTopicSnapshots.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTopicSnapshotsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTopicSnapshots.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTopicSnapshots, request)); - assert( - (client.descriptors.page.listTopicSnapshots.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTopicSnapshots without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSnapshots.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: string[] = []; - const iterable = client.listTopicSnapshotsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTopicSnapshots with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListTopicSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListTopicSnapshotsRequest', ['topic']); - request.topic = defaultValue1; - const expectedHeaderRequestParams = `topic=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listTopicSnapshots.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTopicSnapshotsAsync(request); - await assert.rejects(async () => { - const responses: string[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.getIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes getIamPolicy without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes getIamPolicy with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.setIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes setIamPolicy without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes setIamPolicy with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); - const response = await client.testIamPermissions(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes testIamPermissions without error using callback', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0)); - }); - it('invokes testIamPermissions with error', async () => { - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('Path templates', () => { - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - 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('projectTopic', () => { - const fakePath = "/rendered/path/projectTopic"; - const expectedParameters = { - project: "projectValue", - topic: "topicValue", - }; - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.projectTopicPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectTopicPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectTopicPath', () => { - const result = client.projectTopicPath("projectValue", "topicValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectTopicPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectTopicName', () => { - const result = client.matchProjectFromProjectTopicName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTopicFromProjectTopicName', () => { - const result = client.matchTopicFromProjectTopicName(fakePath); - assert.strictEqual(result, "topicValue"); - assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('schema', () => { - const fakePath = "/rendered/path/schema"; - const expectedParameters = { - project: "projectValue", - schema: "schemaValue", - }; - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.schemaPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.schemaPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('schemaPath', () => { - const result = client.schemaPath("projectValue", "schemaValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.schemaPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSchemaName', () => { - const result = client.matchProjectFromSchemaName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSchemaFromSchemaName', () => { - const result = client.matchSchemaFromSchemaName(fakePath); - assert.strictEqual(result, "schemaValue"); - assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('snapshot', () => { - const fakePath = "/rendered/path/snapshot"; - const expectedParameters = { - project: "projectValue", - snapshot: "snapshotValue", - }; - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.snapshotPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.snapshotPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('snapshotPath', () => { - const result = client.snapshotPath("projectValue", "snapshotValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.snapshotPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSnapshotName', () => { - const result = client.matchProjectFromSnapshotName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSnapshotFromSnapshotName', () => { - const result = client.matchSnapshotFromSnapshotName(fakePath); - assert.strictEqual(result, "snapshotValue"); - assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('subscription', () => { - const fakePath = "/rendered/path/subscription"; - const expectedParameters = { - project: "projectValue", - subscription: "subscriptionValue", - }; - const client = new publisherModule.v1.PublisherClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.subscriptionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.subscriptionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('subscriptionPath', () => { - const result = client.subscriptionPath("projectValue", "subscriptionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.subscriptionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSubscriptionName', () => { - const result = client.matchProjectFromSubscriptionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSubscriptionFromSubscriptionName', () => { - const result = client.matchSubscriptionFromSubscriptionName(fakePath); - assert.strictEqual(result, "subscriptionValue"); - assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/owl-bot-staging/v1/test/gapic_schema_service_v1.ts b/owl-bot-staging/v1/test/gapic_schema_service_v1.ts deleted file mode 100644 index 517c88cb1..000000000 --- a/owl-bot-staging/v1/test/gapic_schema_service_v1.ts +++ /dev/null @@ -1,2012 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as schemaserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, IamProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.SchemaServiceClient', () => { - describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = schemaserviceModule.v1.SchemaServiceClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = schemaserviceModule.v1.SchemaServiceClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = schemaserviceModule.v1.SchemaServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new schemaserviceModule.v1.SchemaServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.schemaServiceStub, undefined); - await client.initialize(); - assert(client.schemaServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - assert(client.schemaServiceStub); - client.close().then(() => { - done(); - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.schemaServiceStub, undefined); - client.close().then(() => { - done(); - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new schemaserviceModule.v1.SchemaServiceClient({ - 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 schemaserviceModule.v1.SchemaServiceClient({ - 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('createSchema', () => { - it('invokes createSchema without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.createSchema = stubSimpleCall(expectedResponse); - const [response] = await client.createSchema(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSchema without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.createSchema = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSchema( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSchema with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createSchema = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSchema(request), expectedError); - const actualRequest = (client.innerApiCalls.createSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSchema with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.createSchema(request), expectedError); - }); - }); - - describe('getSchema', () => { - it('invokes getSchema without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.getSchema = stubSimpleCall(expectedResponse); - const [response] = await client.getSchema(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSchema without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.getSchema = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSchema( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSchema with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSchema = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSchema(request), expectedError); - const actualRequest = (client.innerApiCalls.getSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSchema with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.getSchema(request), expectedError); - }); - }); - - describe('commitSchema', () => { - it('invokes commitSchema without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CommitSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.commitSchema = stubSimpleCall(expectedResponse); - const [response] = await client.commitSchema(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.commitSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.commitSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commitSchema without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CommitSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.commitSchema = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.commitSchema( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.commitSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.commitSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commitSchema with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CommitSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.commitSchema = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.commitSchema(request), expectedError); - const actualRequest = (client.innerApiCalls.commitSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.commitSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes commitSchema with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CommitSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CommitSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.commitSchema(request), expectedError); - }); - }); - - describe('rollbackSchema', () => { - it('invokes rollbackSchema without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.RollbackSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.rollbackSchema = stubSimpleCall(expectedResponse); - const [response] = await client.rollbackSchema(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rollbackSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rollbackSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollbackSchema without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.RollbackSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.rollbackSchema = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rollbackSchema( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rollbackSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rollbackSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollbackSchema with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.RollbackSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.rollbackSchema = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.rollbackSchema(request), expectedError); - const actualRequest = (client.innerApiCalls.rollbackSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rollbackSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rollbackSchema with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.RollbackSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.RollbackSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.rollbackSchema(request), expectedError); - }); - }); - - describe('deleteSchemaRevision', () => { - it('invokes deleteSchemaRevision without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.deleteSchemaRevision = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSchemaRevision(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSchemaRevision as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSchemaRevision as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSchemaRevision without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Schema() - ); - client.innerApiCalls.deleteSchemaRevision = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSchemaRevision( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSchemaRevision as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSchemaRevision as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSchemaRevision with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSchemaRevision = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSchemaRevision(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSchemaRevision as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSchemaRevision as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSchemaRevision with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRevisionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRevisionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.deleteSchemaRevision(request), expectedError); - }); - }); - - describe('deleteSchema', () => { - it('invokes deleteSchema without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSchema = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSchema(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSchema without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSchema = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSchema( - 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.deleteSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSchema with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSchema = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSchema(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSchema with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSchemaRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.deleteSchema(request), expectedError); - }); - }); - - describe('validateSchema', () => { - it('invokes validateSchema without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.ValidateSchemaResponse() - ); - client.innerApiCalls.validateSchema = stubSimpleCall(expectedResponse); - const [response] = await client.validateSchema(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.validateSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.validateSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes validateSchema without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.ValidateSchemaResponse() - ); - client.innerApiCalls.validateSchema = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.validateSchema( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.IValidateSchemaResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.validateSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.validateSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes validateSchema with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.validateSchema = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.validateSchema(request), expectedError); - const actualRequest = (client.innerApiCalls.validateSchema as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.validateSchema as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes validateSchema with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateSchemaRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateSchemaRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.validateSchema(request), expectedError); - }); - }); - - describe('validateMessage', () => { - it('invokes validateMessage without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateMessageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.ValidateMessageResponse() - ); - client.innerApiCalls.validateMessage = stubSimpleCall(expectedResponse); - const [response] = await client.validateMessage(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.validateMessage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.validateMessage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes validateMessage without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateMessageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.ValidateMessageResponse() - ); - client.innerApiCalls.validateMessage = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.validateMessage( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.IValidateMessageResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.validateMessage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.validateMessage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes validateMessage with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateMessageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.validateMessage = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.validateMessage(request), expectedError); - const actualRequest = (client.innerApiCalls.validateMessage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.validateMessage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes validateMessage with closed client', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ValidateMessageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ValidateMessageRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.validateMessage(request), expectedError); - }); - }); - - describe('listSchemas', () => { - it('invokes listSchemas without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.innerApiCalls.listSchemas = stubSimpleCall(expectedResponse); - const [response] = await client.listSchemas(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSchemas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSchemas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSchemas without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.innerApiCalls.listSchemas = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSchemas( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSchemas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSchemas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSchemas with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSchemas = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSchemas(request), expectedError); - const actualRequest = (client.innerApiCalls.listSchemas as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSchemas as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSchemasStream without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.descriptors.page.listSchemas.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSchemasStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Schema[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Schema) => { - 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.listSchemas.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSchemas, request)); - assert( - (client.descriptors.page.listSchemas.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSchemasStream with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSchemas.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSchemasStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Schema[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Schema) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSchemas.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSchemas, request)); - assert( - (client.descriptors.page.listSchemas.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSchemas without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.descriptors.page.listSchemas.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.pubsub.v1.ISchema[] = []; - const iterable = client.listSchemasAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSchemas.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSchemas.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSchemas with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemasRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemasRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSchemas.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSchemasAsync(request); - await assert.rejects(async () => { - const responses: protos.google.pubsub.v1.ISchema[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSchemas.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSchemas.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listSchemaRevisions', () => { - it('invokes listSchemaRevisions without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.innerApiCalls.listSchemaRevisions = stubSimpleCall(expectedResponse); - const [response] = await client.listSchemaRevisions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSchemaRevisions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSchemaRevisions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSchemaRevisions without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.innerApiCalls.listSchemaRevisions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSchemaRevisions( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISchema[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSchemaRevisions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSchemaRevisions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSchemaRevisions with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSchemaRevisions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSchemaRevisions(request), expectedError); - const actualRequest = (client.innerApiCalls.listSchemaRevisions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSchemaRevisions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSchemaRevisionsStream without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.descriptors.page.listSchemaRevisions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSchemaRevisionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Schema[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Schema) => { - 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.listSchemaRevisions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSchemaRevisions, request)); - assert( - (client.descriptors.page.listSchemaRevisions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSchemaRevisionsStream with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSchemaRevisions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSchemaRevisionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Schema[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Schema) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSchemaRevisions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSchemaRevisions, request)); - assert( - (client.descriptors.page.listSchemaRevisions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSchemaRevisions without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - generateSampleMessage(new protos.google.pubsub.v1.Schema()), - ]; - client.descriptors.page.listSchemaRevisions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.pubsub.v1.ISchema[] = []; - const iterable = client.listSchemaRevisionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSchemaRevisions with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSchemaRevisionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSchemaRevisionsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSchemaRevisions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSchemaRevisionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.pubsub.v1.ISchema[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSchemaRevisions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.getIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes getIamPolicy without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes getIamPolicy with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.setIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes setIamPolicy without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes setIamPolicy with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); - const response = await client.testIamPermissions(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes testIamPermissions without error using callback', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0)); - }); - it('invokes testIamPermissions with error', async () => { - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('Path templates', () => { - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - 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('projectTopic', () => { - const fakePath = "/rendered/path/projectTopic"; - const expectedParameters = { - project: "projectValue", - topic: "topicValue", - }; - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.projectTopicPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectTopicPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectTopicPath', () => { - const result = client.projectTopicPath("projectValue", "topicValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectTopicPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectTopicName', () => { - const result = client.matchProjectFromProjectTopicName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTopicFromProjectTopicName', () => { - const result = client.matchTopicFromProjectTopicName(fakePath); - assert.strictEqual(result, "topicValue"); - assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('schema', () => { - const fakePath = "/rendered/path/schema"; - const expectedParameters = { - project: "projectValue", - schema: "schemaValue", - }; - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.schemaPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.schemaPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('schemaPath', () => { - const result = client.schemaPath("projectValue", "schemaValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.schemaPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSchemaName', () => { - const result = client.matchProjectFromSchemaName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSchemaFromSchemaName', () => { - const result = client.matchSchemaFromSchemaName(fakePath); - assert.strictEqual(result, "schemaValue"); - assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('snapshot', () => { - const fakePath = "/rendered/path/snapshot"; - const expectedParameters = { - project: "projectValue", - snapshot: "snapshotValue", - }; - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.snapshotPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.snapshotPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('snapshotPath', () => { - const result = client.snapshotPath("projectValue", "snapshotValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.snapshotPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSnapshotName', () => { - const result = client.matchProjectFromSnapshotName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSnapshotFromSnapshotName', () => { - const result = client.matchSnapshotFromSnapshotName(fakePath); - assert.strictEqual(result, "snapshotValue"); - assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('subscription', () => { - const fakePath = "/rendered/path/subscription"; - const expectedParameters = { - project: "projectValue", - subscription: "subscriptionValue", - }; - const client = new schemaserviceModule.v1.SchemaServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.subscriptionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.subscriptionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('subscriptionPath', () => { - const result = client.subscriptionPath("projectValue", "subscriptionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.subscriptionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSubscriptionName', () => { - const result = client.matchProjectFromSubscriptionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSubscriptionFromSubscriptionName', () => { - const result = client.matchSubscriptionFromSubscriptionName(fakePath); - assert.strictEqual(result, "subscriptionValue"); - assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/owl-bot-staging/v1/test/gapic_subscriber_v1.ts b/owl-bot-staging/v1/test/gapic_subscriber_v1.ts deleted file mode 100644 index d08c709e2..000000000 --- a/owl-bot-staging/v1/test/gapic_subscriber_v1.ts +++ /dev/null @@ -1,2633 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as subscriberModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, IamProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.SubscriberClient', () => { - describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = subscriberModule.v1.SubscriberClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = subscriberModule.v1.SubscriberClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = subscriberModule.v1.SubscriberClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new subscriberModule.v1.SubscriberClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new subscriberModule.v1.SubscriberClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.subscriberStub, undefined); - await client.initialize(); - assert(client.subscriberStub); - }); - - it('has close method for the initialized client', done => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - assert(client.subscriberStub); - client.close().then(() => { - done(); - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.subscriberStub, undefined); - client.close().then(() => { - done(); - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new subscriberModule.v1.SubscriberClient({ - 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 subscriberModule.v1.SubscriberClient({ - 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('createSubscription', () => { - it('invokes createSubscription without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - client.innerApiCalls.createSubscription = stubSimpleCall(expectedResponse); - const [response] = await client.createSubscription(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSubscription without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - client.innerApiCalls.createSubscription = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSubscription( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSubscription with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createSubscription = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSubscription(request), expectedError); - const actualRequest = (client.innerApiCalls.createSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSubscription with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.Subscription', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.createSubscription(request), expectedError); - }); - }); - - describe('getSubscription', () => { - it('invokes getSubscription without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - client.innerApiCalls.getSubscription = stubSimpleCall(expectedResponse); - const [response] = await client.getSubscription(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSubscription without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - client.innerApiCalls.getSubscription = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSubscription( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSubscription with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSubscription = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSubscription(request), expectedError); - const actualRequest = (client.innerApiCalls.getSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSubscription with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.getSubscription(request), expectedError); - }); - }); - - describe('updateSubscription', () => { - it('invokes updateSubscription without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSubscriptionRequest() - ); - request.subscription ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); - request.subscription.name = defaultValue1; - const expectedHeaderRequestParams = `subscription.name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - client.innerApiCalls.updateSubscription = stubSimpleCall(expectedResponse); - const [response] = await client.updateSubscription(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSubscription without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSubscriptionRequest() - ); - request.subscription ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); - request.subscription.name = defaultValue1; - const expectedHeaderRequestParams = `subscription.name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Subscription() - ); - client.innerApiCalls.updateSubscription = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateSubscription( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSubscription with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSubscriptionRequest() - ); - request.subscription ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); - request.subscription.name = defaultValue1; - const expectedHeaderRequestParams = `subscription.name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateSubscription = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateSubscription(request), expectedError); - const actualRequest = (client.innerApiCalls.updateSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSubscription with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSubscriptionRequest() - ); - request.subscription ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSubscriptionRequest', ['subscription', 'name']); - request.subscription.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.updateSubscription(request), expectedError); - }); - }); - - describe('deleteSubscription', () => { - it('invokes deleteSubscription without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSubscription = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSubscription(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSubscription without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSubscription = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSubscription( - 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.deleteSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSubscription with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSubscription = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSubscription(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSubscription as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSubscription as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSubscription with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSubscriptionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSubscriptionRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.deleteSubscription(request), expectedError); - }); - }); - - describe('modifyAckDeadline', () => { - it('invokes modifyAckDeadline without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyAckDeadlineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.modifyAckDeadline = stubSimpleCall(expectedResponse); - const [response] = await client.modifyAckDeadline(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.modifyAckDeadline as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.modifyAckDeadline as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes modifyAckDeadline without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyAckDeadlineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.modifyAckDeadline = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.modifyAckDeadline( - 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.modifyAckDeadline as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.modifyAckDeadline as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes modifyAckDeadline with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyAckDeadlineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.modifyAckDeadline = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.modifyAckDeadline(request), expectedError); - const actualRequest = (client.innerApiCalls.modifyAckDeadline as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.modifyAckDeadline as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes modifyAckDeadline with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyAckDeadlineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyAckDeadlineRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.modifyAckDeadline(request), expectedError); - }); - }); - - describe('acknowledge', () => { - it('invokes acknowledge without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.AcknowledgeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.acknowledge = stubSimpleCall(expectedResponse); - const [response] = await client.acknowledge(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acknowledge as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acknowledge as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acknowledge without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.AcknowledgeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.acknowledge = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.acknowledge( - 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.acknowledge as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acknowledge as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acknowledge with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.AcknowledgeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.acknowledge = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.acknowledge(request), expectedError); - const actualRequest = (client.innerApiCalls.acknowledge as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acknowledge as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acknowledge with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.AcknowledgeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.AcknowledgeRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.acknowledge(request), expectedError); - }); - }); - - describe('pull', () => { - it('invokes pull without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PullRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.PullResponse() - ); - client.innerApiCalls.pull = stubSimpleCall(expectedResponse); - const [response] = await client.pull(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pull as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pull as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pull without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PullRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.PullResponse() - ); - client.innerApiCalls.pull = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pull( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.IPullResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pull as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pull as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pull with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PullRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.pull = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pull(request), expectedError); - const actualRequest = (client.innerApiCalls.pull as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pull as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pull with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.PullRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.PullRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.pull(request), expectedError); - }); - }); - - describe('modifyPushConfig', () => { - it('invokes modifyPushConfig without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyPushConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.modifyPushConfig = stubSimpleCall(expectedResponse); - const [response] = await client.modifyPushConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.modifyPushConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.modifyPushConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes modifyPushConfig without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyPushConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.modifyPushConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.modifyPushConfig( - 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.modifyPushConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.modifyPushConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes modifyPushConfig with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyPushConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.modifyPushConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.modifyPushConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.modifyPushConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.modifyPushConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes modifyPushConfig with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ModifyPushConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ModifyPushConfigRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.modifyPushConfig(request), expectedError); - }); - }); - - describe('getSnapshot', () => { - it('invokes getSnapshot without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Snapshot() - ); - client.innerApiCalls.getSnapshot = stubSimpleCall(expectedResponse); - const [response] = await client.getSnapshot(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSnapshot without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Snapshot() - ); - client.innerApiCalls.getSnapshot = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSnapshot( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSnapshot with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSnapshot = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSnapshot(request), expectedError); - const actualRequest = (client.innerApiCalls.getSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSnapshot with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.GetSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.GetSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.getSnapshot(request), expectedError); - }); - }); - - describe('createSnapshot', () => { - it('invokes createSnapshot without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Snapshot() - ); - client.innerApiCalls.createSnapshot = stubSimpleCall(expectedResponse); - const [response] = await client.createSnapshot(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSnapshot without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Snapshot() - ); - client.innerApiCalls.createSnapshot = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSnapshot( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSnapshot with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.createSnapshot = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSnapshot(request), expectedError); - const actualRequest = (client.innerApiCalls.createSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSnapshot with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.CreateSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.CreateSnapshotRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.createSnapshot(request), expectedError); - }); - }); - - describe('updateSnapshot', () => { - it('invokes updateSnapshot without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSnapshotRequest() - ); - request.snapshot ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); - request.snapshot.name = defaultValue1; - const expectedHeaderRequestParams = `snapshot.name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Snapshot() - ); - client.innerApiCalls.updateSnapshot = stubSimpleCall(expectedResponse); - const [response] = await client.updateSnapshot(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSnapshot without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSnapshotRequest() - ); - request.snapshot ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); - request.snapshot.name = defaultValue1; - const expectedHeaderRequestParams = `snapshot.name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.Snapshot() - ); - client.innerApiCalls.updateSnapshot = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateSnapshot( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSnapshot with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSnapshotRequest() - ); - request.snapshot ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); - request.snapshot.name = defaultValue1; - const expectedHeaderRequestParams = `snapshot.name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateSnapshot = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateSnapshot(request), expectedError); - const actualRequest = (client.innerApiCalls.updateSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSnapshot with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.UpdateSnapshotRequest() - ); - request.snapshot ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.UpdateSnapshotRequest', ['snapshot', 'name']); - request.snapshot.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.updateSnapshot(request), expectedError); - }); - }); - - describe('deleteSnapshot', () => { - it('invokes deleteSnapshot without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSnapshot = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSnapshot(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSnapshot without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSnapshot = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSnapshot( - 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.deleteSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSnapshot with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedHeaderRequestParams = `snapshot=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSnapshot = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSnapshot(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSnapshot as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSnapshot as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSnapshot with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.DeleteSnapshotRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.DeleteSnapshotRequest', ['snapshot']); - request.snapshot = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.deleteSnapshot(request), expectedError); - }); - }); - - describe('seek', () => { - it('invokes seek without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.SeekRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.SeekResponse() - ); - client.innerApiCalls.seek = stubSimpleCall(expectedResponse); - const [response] = await client.seek(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.seek as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.seek as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes seek without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.SeekRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.SeekResponse() - ); - client.innerApiCalls.seek = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.seek( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISeekResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.seek as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.seek as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes seek with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.SeekRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedHeaderRequestParams = `subscription=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.seek = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.seek(request), expectedError); - const actualRequest = (client.innerApiCalls.seek as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.seek as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes seek with closed client', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.SeekRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.SeekRequest', ['subscription']); - request.subscription = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.seek(request), expectedError); - }); - }); - - describe('streamingPull', () => { - it('invokes streamingPull without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.StreamingPullRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.pubsub.v1.StreamingPullResponse() - ); - client.innerApiCalls.streamingPull = stubBidiStreamingCall(expectedResponse); - const stream = client.streamingPull(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.pubsub.v1.StreamingPullResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.streamingPull as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes streamingPull with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.StreamingPullRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.streamingPull = stubBidiStreamingCall(undefined, expectedError); - const stream = client.streamingPull(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.pubsub.v1.StreamingPullResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.streamingPull as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('listSubscriptions', () => { - it('invokes listSubscriptions without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - ]; - client.innerApiCalls.listSubscriptions = stubSimpleCall(expectedResponse); - const [response] = await client.listSubscriptions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSubscriptions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSubscriptions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSubscriptions without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - ]; - client.innerApiCalls.listSubscriptions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSubscriptions( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISubscription[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSubscriptions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSubscriptions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSubscriptions with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSubscriptions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSubscriptions(request), expectedError); - const actualRequest = (client.innerApiCalls.listSubscriptions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSubscriptions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSubscriptionsStream without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - ]; - client.descriptors.page.listSubscriptions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSubscriptionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Subscription[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Subscription) => { - 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.listSubscriptions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSubscriptions, request)); - assert( - (client.descriptors.page.listSubscriptions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSubscriptionsStream with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSubscriptions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSubscriptionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Subscription[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Subscription) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSubscriptions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSubscriptions, request)); - assert( - (client.descriptors.page.listSubscriptions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSubscriptions without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - generateSampleMessage(new protos.google.pubsub.v1.Subscription()), - ]; - client.descriptors.page.listSubscriptions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.pubsub.v1.ISubscription[] = []; - const iterable = client.listSubscriptionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSubscriptions with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSubscriptionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSubscriptionsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSubscriptions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSubscriptionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.pubsub.v1.ISubscription[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSubscriptions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listSnapshots', () => { - it('invokes listSnapshots without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - ]; - client.innerApiCalls.listSnapshots = stubSimpleCall(expectedResponse); - const [response] = await client.listSnapshots(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSnapshots as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSnapshots as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSnapshots without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`;const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - ]; - client.innerApiCalls.listSnapshots = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSnapshots( - request, - (err?: Error|null, result?: protos.google.pubsub.v1.ISnapshot[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSnapshots as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSnapshots as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSnapshots with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSnapshots = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSnapshots(request), expectedError); - const actualRequest = (client.innerApiCalls.listSnapshots as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSnapshots as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSnapshotsStream without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - ]; - client.descriptors.page.listSnapshots.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSnapshotsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Snapshot[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Snapshot) => { - 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.listSnapshots.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSnapshots, request)); - assert( - (client.descriptors.page.listSnapshots.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSnapshotsStream with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSnapshots.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSnapshotsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.pubsub.v1.Snapshot[] = []; - stream.on('data', (response: protos.google.pubsub.v1.Snapshot) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSnapshots.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSnapshots, request)); - assert( - (client.descriptors.page.listSnapshots.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSnapshots without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), - ]; - client.descriptors.page.listSnapshots.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.pubsub.v1.ISnapshot[] = []; - const iterable = client.listSnapshotsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSnapshots with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.pubsub.v1.ListSnapshotsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.pubsub.v1.ListSnapshotsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSnapshots.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSnapshotsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.pubsub.v1.ISnapshot[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSnapshots.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.getIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes getIamPolicy without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes getIamPolicy with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.setIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes setIamPolicy without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes setIamPolicy with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); - const response = await client.testIamPermissions(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes testIamPermissions without error using callback', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0)); - }); - it('invokes testIamPermissions with error', async () => { - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('Path templates', () => { - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - 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('projectTopic', () => { - const fakePath = "/rendered/path/projectTopic"; - const expectedParameters = { - project: "projectValue", - topic: "topicValue", - }; - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.projectTopicPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectTopicPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectTopicPath', () => { - const result = client.projectTopicPath("projectValue", "topicValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectTopicPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectTopicName', () => { - const result = client.matchProjectFromProjectTopicName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTopicFromProjectTopicName', () => { - const result = client.matchTopicFromProjectTopicName(fakePath); - assert.strictEqual(result, "topicValue"); - assert((client.pathTemplates.projectTopicPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('schema', () => { - const fakePath = "/rendered/path/schema"; - const expectedParameters = { - project: "projectValue", - schema: "schemaValue", - }; - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.schemaPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.schemaPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('schemaPath', () => { - const result = client.schemaPath("projectValue", "schemaValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.schemaPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSchemaName', () => { - const result = client.matchProjectFromSchemaName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSchemaFromSchemaName', () => { - const result = client.matchSchemaFromSchemaName(fakePath); - assert.strictEqual(result, "schemaValue"); - assert((client.pathTemplates.schemaPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('snapshot', () => { - const fakePath = "/rendered/path/snapshot"; - const expectedParameters = { - project: "projectValue", - snapshot: "snapshotValue", - }; - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.snapshotPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.snapshotPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('snapshotPath', () => { - const result = client.snapshotPath("projectValue", "snapshotValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.snapshotPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSnapshotName', () => { - const result = client.matchProjectFromSnapshotName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSnapshotFromSnapshotName', () => { - const result = client.matchSnapshotFromSnapshotName(fakePath); - assert.strictEqual(result, "snapshotValue"); - assert((client.pathTemplates.snapshotPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('subscription', () => { - const fakePath = "/rendered/path/subscription"; - const expectedParameters = { - project: "projectValue", - subscription: "subscriptionValue", - }; - const client = new subscriberModule.v1.SubscriberClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.subscriptionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.subscriptionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('subscriptionPath', () => { - const result = client.subscriptionPath("projectValue", "subscriptionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.subscriptionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromSubscriptionName', () => { - const result = client.matchProjectFromSubscriptionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSubscriptionFromSubscriptionName', () => { - const result = client.matchSubscriptionFromSubscriptionName(fakePath); - assert.strictEqual(result, "subscriptionValue"); - assert((client.pathTemplates.subscriptionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/owl-bot-staging/v1/tsconfig.json b/owl-bot-staging/v1/tsconfig.json deleted file mode 100644 index c78f1c884..000000000 --- a/owl-bot-staging/v1/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "resolveJsonModule": true, - "lib": [ - "es2018", - "dom" - ] - }, - "include": [ - "src/*.ts", - "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts" - ] -} diff --git a/owl-bot-staging/v1/webpack.config.js b/owl-bot-staging/v1/webpack.config.js deleted file mode 100644 index 3575e0eba..000000000 --- a/owl-bot-staging/v1/webpack.config.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -const path = require('path'); - -module.exports = { - entry: './src/index.ts', - output: { - library: 'pubsub', - filename: './pubsub.js', - }, - node: { - child_process: 'empty', - fs: 'empty', - crypto: 'empty', - }, - resolve: { - alias: { - '../../../package.json': path.resolve(__dirname, 'package.json'), - }, - extensions: ['.js', '.json', '.ts'], - }, - module: { - rules: [ - { - test: /\.tsx?$/, - use: 'ts-loader', - exclude: /node_modules/ - }, - { - test: /node_modules[\\/]@grpc[\\/]grpc-js/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]grpc/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]retry-request/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]https?-proxy-agent/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]gtoken/, - use: 'null-loader' - }, - ], - }, - mode: 'production', -}; From feb606387198d1a257e0f387d8f6612e237f69ca Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 26 Sep 2023 22:56:38 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6ae22d7da..ceefb3891 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,15 @@ npm install @google-cloud/pubsub ```javascript // Imports the Google Cloud client library -const { PubSub } = require("@google-cloud/pubsub"); +const {PubSub} = require('@google-cloud/pubsub'); async function quickstart( -projectId = 'your-project-id', // Your Google Cloud Platform project ID -topicNameOrId = 'my-topic', // Name for the new topic to create -subscriptionName = 'my-sub' // Name for the new subscription to create + projectId = 'your-project-id', // Your Google Cloud Platform project ID + topicNameOrId = 'my-topic', // Name for the new topic to create + subscriptionName = 'my-sub' // Name for the new subscription to create ) { // Instantiates a client - const pubsub = new PubSub({ projectId }); + const pubsub = new PubSub({projectId}); // Creates a new topic const [topic] = await pubsub.createTopic(topicNameOrId); @@ -84,19 +84,19 @@ subscriptionName = 'my-sub' // Name for the new subscription to create const [subscription] = await topic.createSubscription(subscriptionName); // Receive callbacks for new messages on the subscription - subscription.on('message', (message) => { + subscription.on('message', message => { console.log('Received message:', message.data.toString()); process.exit(0); }); // Receive callbacks for errors on the subscription - subscription.on('error', (error) => { + subscription.on('error', error => { console.error('Received error:', error); process.exit(1); }); // Send a message to the topic - topic.publishMessage({ data: Buffer.from('Test message!') }); + topic.publishMessage({data: Buffer.from('Test message!')}); } ```