google-cloud-firestore 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +47 -0
  4. data/TROUBLESHOOTING.md +2 -8
  5. data/lib/google-cloud-firestore.rb +14 -21
  6. data/lib/google/cloud/firestore.rb +12 -23
  7. data/lib/google/cloud/firestore/client.rb +12 -14
  8. data/lib/google/cloud/firestore/collection_reference.rb +1 -0
  9. data/lib/google/cloud/firestore/collection_reference_list.rb +137 -0
  10. data/lib/google/cloud/firestore/convert.rb +39 -39
  11. data/lib/google/cloud/firestore/credentials.rb +2 -2
  12. data/lib/google/cloud/firestore/document_reference.rb +8 -8
  13. data/lib/google/cloud/firestore/document_reference/list.rb +2 -2
  14. data/lib/google/cloud/firestore/document_snapshot.rb +4 -4
  15. data/lib/google/cloud/firestore/query.rb +4 -4
  16. data/lib/google/cloud/firestore/service.rb +71 -106
  17. data/lib/google/cloud/firestore/transaction.rb +2 -2
  18. data/lib/google/cloud/firestore/version.rb +1 -1
  19. data/lib/google/cloud/firestore/watch/listener.rb +9 -9
  20. data/lib/google/cloud/firestore/watch/order.rb +1 -1
  21. metadata +11 -109
  22. data/lib/google/cloud/firestore/admin.rb +0 -144
  23. data/lib/google/cloud/firestore/admin/v1.rb +0 -151
  24. data/lib/google/cloud/firestore/admin/v1/credentials.rb +0 -44
  25. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/field.rb +0 -86
  26. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/firestore_admin.rb +0 -161
  27. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/index.rb +0 -142
  28. data/lib/google/cloud/firestore/admin/v1/doc/google/longrunning/operations.rb +0 -51
  29. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/any.rb +0 -131
  30. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/empty.rb +0 -29
  31. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/field_mask.rb +0 -222
  32. data/lib/google/cloud/firestore/admin/v1/doc/google/rpc/status.rb +0 -39
  33. data/lib/google/cloud/firestore/admin/v1/firestore_admin_client.rb +0 -764
  34. data/lib/google/cloud/firestore/admin/v1/firestore_admin_client_config.json +0 -72
  35. data/lib/google/cloud/firestore/v1.rb +0 -152
  36. data/lib/google/cloud/firestore/v1/credentials.rb +0 -42
  37. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/common.rb +0 -64
  38. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/document.rb +0 -136
  39. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/firestore.rb +0 -566
  40. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/query.rb +0 -227
  41. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/write.rb +0 -241
  42. data/lib/google/cloud/firestore/v1/doc/google/protobuf/any.rb +0 -131
  43. data/lib/google/cloud/firestore/v1/doc/google/protobuf/empty.rb +0 -29
  44. data/lib/google/cloud/firestore/v1/doc/google/protobuf/timestamp.rb +0 -113
  45. data/lib/google/cloud/firestore/v1/doc/google/protobuf/wrappers.rb +0 -26
  46. data/lib/google/cloud/firestore/v1/doc/google/rpc/status.rb +0 -39
  47. data/lib/google/cloud/firestore/v1/firestore_client.rb +0 -1073
  48. data/lib/google/cloud/firestore/v1/firestore_client_config.json +0 -101
  49. data/lib/google/cloud/firestore/v1beta1.rb +0 -160
  50. data/lib/google/cloud/firestore/v1beta1/credentials.rb +0 -42
  51. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/common.rb +0 -64
  52. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/document.rb +0 -136
  53. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/firestore.rb +0 -564
  54. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/query.rb +0 -227
  55. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/write.rb +0 -237
  56. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/any.rb +0 -131
  57. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/empty.rb +0 -29
  58. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/timestamp.rb +0 -113
  59. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/wrappers.rb +0 -26
  60. data/lib/google/cloud/firestore/v1beta1/doc/google/rpc/status.rb +0 -39
  61. data/lib/google/cloud/firestore/v1beta1/firestore_client.rb +0 -1081
  62. data/lib/google/cloud/firestore/v1beta1/firestore_client_config.json +0 -100
  63. data/lib/google/firestore/admin/v1/field_pb.rb +0 -32
  64. data/lib/google/firestore/admin/v1/firestore_admin_pb.rb +0 -84
  65. data/lib/google/firestore/admin/v1/firestore_admin_services_pb.rb +0 -94
  66. data/lib/google/firestore/admin/v1/index_pb.rb +0 -58
  67. data/lib/google/firestore/admin/v1/location_pb.rb +0 -22
  68. data/lib/google/firestore/admin/v1/operation_pb.rb +0 -90
  69. data/lib/google/firestore/v1/common_pb.rb +0 -45
  70. data/lib/google/firestore/v1/document_pb.rb +0 -50
  71. data/lib/google/firestore/v1/firestore_pb.rb +0 -222
  72. data/lib/google/firestore/v1/firestore_services_pb.rb +0 -80
  73. data/lib/google/firestore/v1/query_pb.rb +0 -107
  74. data/lib/google/firestore/v1/write_pb.rb +0 -80
  75. data/lib/google/firestore/v1beta1/common_pb.rb +0 -45
  76. data/lib/google/firestore/v1beta1/document_pb.rb +0 -50
  77. data/lib/google/firestore/v1beta1/firestore_pb.rb +0 -222
  78. data/lib/google/firestore/v1beta1/firestore_services_pb.rb +0 -89
  79. data/lib/google/firestore/v1beta1/query_pb.rb +0 -107
  80. data/lib/google/firestore/v1beta1/write_pb.rb +0 -79
@@ -1,131 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Protobuf
18
- # `Any` contains an arbitrary serialized protocol buffer message along with a
19
- # URL that describes the type of the serialized message.
20
- #
21
- # Protobuf library provides support to pack/unpack Any values in the form
22
- # of utility functions or additional generated methods of the Any type.
23
- #
24
- # Example 1: Pack and unpack a message in C++.
25
- #
26
- # Foo foo = ...;
27
- # Any any;
28
- # any.PackFrom(foo);
29
- # ...
30
- # if (any.UnpackTo(&foo)) {
31
- # ...
32
- # }
33
- #
34
- # Example 2: Pack and unpack a message in Java.
35
- #
36
- # Foo foo = ...;
37
- # Any any = Any.pack(foo);
38
- # ...
39
- # if (any.is(Foo.class)) {
40
- # foo = any.unpack(Foo.class);
41
- # }
42
- #
43
- # Example 3: Pack and unpack a message in Python.
44
- #
45
- # foo = Foo(...)
46
- # any = Any()
47
- # any.Pack(foo)
48
- # ...
49
- # if any.Is(Foo.DESCRIPTOR):
50
- # any.Unpack(foo)
51
- # ...
52
- #
53
- # Example 4: Pack and unpack a message in Go
54
- #
55
- # foo := &pb.Foo{...}
56
- # any, err := ptypes.MarshalAny(foo)
57
- # ...
58
- # foo := &pb.Foo{}
59
- # if err := ptypes.UnmarshalAny(any, foo); err != nil {
60
- # ...
61
- # }
62
- #
63
- # The pack methods provided by protobuf library will by default use
64
- # 'type.googleapis.com/full.type.name' as the type URL and the unpack
65
- # methods only use the fully qualified type name after the last '/'
66
- # in the type URL, for example "foo.bar.com/x/y.z" will yield type
67
- # name "y.z".
68
- #
69
- #
70
- # = JSON
71
- #
72
- # The JSON representation of an `Any` value uses the regular
73
- # representation of the deserialized, embedded message, with an
74
- # additional field `@type` which contains the type URL. Example:
75
- #
76
- # package google.profile;
77
- # message Person {
78
- # string first_name = 1;
79
- # string last_name = 2;
80
- # }
81
- #
82
- # {
83
- # "@type": "type.googleapis.com/google.profile.Person",
84
- # "firstName": <string>,
85
- # "lastName": <string>
86
- # }
87
- #
88
- # If the embedded message type is well-known and has a custom JSON
89
- # representation, that representation will be embedded adding a field
90
- # `value` which holds the custom JSON in addition to the `@type`
91
- # field. Example (for message {Google::Protobuf::Duration}):
92
- #
93
- # {
94
- # "@type": "type.googleapis.com/google.protobuf.Duration",
95
- # "value": "1.212s"
96
- # }
97
- # @!attribute [rw] type_url
98
- # @return [String]
99
- # A URL/resource name that uniquely identifies the type of the serialized
100
- # protocol buffer message. This string must contain at least
101
- # one "/" character. The last segment of the URL's path must represent
102
- # the fully qualified name of the type (as in
103
- # `path/google.protobuf.Duration`). The name should be in a canonical form
104
- # (e.g., leading "." is not accepted).
105
- #
106
- # In practice, teams usually precompile into the binary all types that they
107
- # expect it to use in the context of Any. However, for URLs which use the
108
- # scheme `http`, `https`, or no scheme, one can optionally set up a type
109
- # server that maps type URLs to message definitions as follows:
110
- #
111
- # * If no scheme is provided, `https` is assumed.
112
- # * An HTTP GET on the URL must yield a {Google::Protobuf::Type}
113
- # value in binary format, or produce an error.
114
- # * Applications are allowed to cache lookup results based on the
115
- # URL, or have them precompiled into a binary to avoid any
116
- # lookup. Therefore, binary compatibility needs to be preserved
117
- # on changes to types. (Use versioned type names to manage
118
- # breaking changes.)
119
- #
120
- # Note: this functionality is not currently available in the official
121
- # protobuf release, and it is not used for type URLs beginning with
122
- # type.googleapis.com.
123
- #
124
- # Schemes other than `http`, `https` (or the empty scheme) might be
125
- # used with implementation specific semantics.
126
- # @!attribute [rw] value
127
- # @return [String]
128
- # Must be a valid serialized protocol buffer of the above specified type.
129
- class Any; end
130
- end
131
- end
@@ -1,29 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Protobuf
18
- # A generic empty message that you can re-use to avoid defining duplicated
19
- # empty messages in your APIs. A typical example is to use it as the request
20
- # or the response type of an API method. For instance:
21
- #
22
- # service Foo {
23
- # rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
24
- # }
25
- #
26
- # The JSON representation for `Empty` is empty JSON object `{}`.
27
- class Empty; end
28
- end
29
- end
@@ -1,113 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Protobuf
18
- # A Timestamp represents a point in time independent of any time zone or local
19
- # calendar, encoded as a count of seconds and fractions of seconds at
20
- # nanosecond resolution. The count is relative to an epoch at UTC midnight on
21
- # January 1, 1970, in the proleptic Gregorian calendar which extends the
22
- # Gregorian calendar backwards to year one.
23
- #
24
- # All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
25
- # second table is needed for interpretation, using a [24-hour linear
26
- # smear](https://developers.google.com/time/smear).
27
- #
28
- # The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
29
- # restricting to that range, we ensure that we can convert to and from [RFC
30
- # 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
31
- #
32
- # = Examples
33
- #
34
- # Example 1: Compute Timestamp from POSIX `time()`.
35
- #
36
- # Timestamp timestamp;
37
- # timestamp.set_seconds(time(NULL));
38
- # timestamp.set_nanos(0);
39
- #
40
- # Example 2: Compute Timestamp from POSIX `gettimeofday()`.
41
- #
42
- # struct timeval tv;
43
- # gettimeofday(&tv, NULL);
44
- #
45
- # Timestamp timestamp;
46
- # timestamp.set_seconds(tv.tv_sec);
47
- # timestamp.set_nanos(tv.tv_usec * 1000);
48
- #
49
- # Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
50
- #
51
- # FILETIME ft;
52
- # GetSystemTimeAsFileTime(&ft);
53
- # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
54
- #
55
- # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
56
- # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
57
- # Timestamp timestamp;
58
- # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
59
- # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
60
- #
61
- # Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
62
- #
63
- # long millis = System.currentTimeMillis();
64
- #
65
- # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
66
- # .setNanos((int) ((millis % 1000) * 1000000)).build();
67
- #
68
- #
69
- # Example 5: Compute Timestamp from current time in Python.
70
- #
71
- # timestamp = Timestamp()
72
- # timestamp.GetCurrentTime()
73
- #
74
- # = JSON Mapping
75
- #
76
- # In JSON format, the Timestamp type is encoded as a string in the
77
- # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
78
- # format is "\\{year}-\\{month}-\\{day}T\\{hour}:\\{min}:\\{sec}[.\\{frac_sec}]Z"
79
- # where \\{year} is always expressed using four digits while \\{month}, \\{day},
80
- # \\{hour}, \\{min}, and \\{sec} are zero-padded to two digits each. The fractional
81
- # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
82
- # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
83
- # is required. A proto3 JSON serializer should always use UTC (as indicated by
84
- # "Z") when printing the Timestamp type and a proto3 JSON parser should be
85
- # able to accept both UTC and other timezones (as indicated by an offset).
86
- #
87
- # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
88
- # 01:30 UTC on January 15, 2017.
89
- #
90
- # In JavaScript, one can convert a Date object to this format using the
91
- # standard
92
- # [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
93
- # method. In Python, a standard `datetime.datetime` object can be converted
94
- # to this format using
95
- # [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
96
- # the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
97
- # the Joda Time's [`ISODateTimeFormat.dateTime()`](
98
- # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
99
- # ) to obtain a formatter capable of generating timestamps in this format.
100
- # @!attribute [rw] seconds
101
- # @return [Integer]
102
- # Represents seconds of UTC time since Unix epoch
103
- # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
104
- # 9999-12-31T23:59:59Z inclusive.
105
- # @!attribute [rw] nanos
106
- # @return [Integer]
107
- # Non-negative fractions of a second at nanosecond resolution. Negative
108
- # second values with fractions must still have non-negative nanos values
109
- # that count forward in time. Must be from 0 to 999,999,999
110
- # inclusive.
111
- class Timestamp; end
112
- end
113
- end
@@ -1,26 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Protobuf
18
- # Wrapper message for `int32`.
19
- #
20
- # The JSON representation for `Int32Value` is JSON number.
21
- # @!attribute [rw] value
22
- # @return [Integer]
23
- # The int32 value.
24
- class Int32Value; end
25
- end
26
- end
@@ -1,39 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Rpc
18
- # The `Status` type defines a logical error model that is suitable for
19
- # different programming environments, including REST APIs and RPC APIs. It is
20
- # used by [gRPC](https://github.com/grpc). Each `Status` message contains
21
- # three pieces of data: error code, error message, and error details.
22
- #
23
- # You can find out more about this error model and how to work with it in the
24
- # [API Design Guide](https://cloud.google.com/apis/design/errors).
25
- # @!attribute [rw] code
26
- # @return [Integer]
27
- # The status code, which should be an enum value of {Google::Rpc::Code}.
28
- # @!attribute [rw] message
29
- # @return [String]
30
- # A developer-facing error message, which should be in English. Any
31
- # user-facing error message should be localized and sent in the
32
- # {Google::Rpc::Status#details} field, or localized by the client.
33
- # @!attribute [rw] details
34
- # @return [Array<Google::Protobuf::Any>]
35
- # A list of messages that carry the error details. There is a common set of
36
- # message types for APIs to use.
37
- class Status; end
38
- end
39
- end
@@ -1,1073 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/firestore/v1/firestore.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/firestore/v1/firestore_pb"
29
- require "google/cloud/firestore/v1/credentials"
30
- require "google/cloud/firestore/version"
31
-
32
- module Google
33
- module Cloud
34
- module Firestore
35
- module V1
36
- # The Cloud Firestore service.
37
- #
38
- # Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL
39
- # document database that simplifies storing, syncing, and querying data for
40
- # your mobile, web, and IoT apps at global scale. Its client libraries provide
41
- # live synchronization and offline support, while its security features and
42
- # integrations with Firebase and Google Cloud Platform (GCP) accelerate
43
- # building truly serverless apps.
44
- #
45
- # @!attribute [r] firestore_stub
46
- # @return [Google::Firestore::V1::Firestore::Stub]
47
- class FirestoreClient
48
- # @private
49
- attr_reader :firestore_stub
50
-
51
- # The default address of the service.
52
- SERVICE_ADDRESS = "firestore.googleapis.com".freeze
53
-
54
- # The default port of the service.
55
- DEFAULT_SERVICE_PORT = 443
56
-
57
- # The default set of gRPC interceptors.
58
- GRPC_INTERCEPTORS = []
59
-
60
- DEFAULT_TIMEOUT = 30
61
-
62
- PAGE_DESCRIPTORS = {
63
- "list_documents" => Google::Gax::PageDescriptor.new(
64
- "page_token",
65
- "next_page_token",
66
- "documents"),
67
- "list_collection_ids" => Google::Gax::PageDescriptor.new(
68
- "page_token",
69
- "next_page_token",
70
- "collection_ids")
71
- }.freeze
72
-
73
- private_constant :PAGE_DESCRIPTORS
74
-
75
- # The scopes needed to make gRPC calls to all of the methods defined in
76
- # this service.
77
- ALL_SCOPES = [
78
- "https://www.googleapis.com/auth/cloud-platform",
79
- "https://www.googleapis.com/auth/datastore"
80
- ].freeze
81
-
82
-
83
- ANY_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
84
- "projects/{project}/databases/{database}/documents/{document}/{any_path=**}"
85
- )
86
-
87
- private_constant :ANY_PATH_PATH_TEMPLATE
88
-
89
- DATABASE_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
90
- "projects/{project}/databases/{database}"
91
- )
92
-
93
- private_constant :DATABASE_ROOT_PATH_TEMPLATE
94
-
95
- DOCUMENT_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
96
- "projects/{project}/databases/{database}/documents/{document_path=**}"
97
- )
98
-
99
- private_constant :DOCUMENT_PATH_PATH_TEMPLATE
100
-
101
- DOCUMENT_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
102
- "projects/{project}/databases/{database}/documents"
103
- )
104
-
105
- private_constant :DOCUMENT_ROOT_PATH_TEMPLATE
106
-
107
- # Returns a fully-qualified any_path resource name string.
108
- # @param project [String]
109
- # @param database [String]
110
- # @param document [String]
111
- # @param any_path [String]
112
- # @return [String]
113
- def self.any_path_path project, database, document, any_path
114
- ANY_PATH_PATH_TEMPLATE.render(
115
- :"project" => project,
116
- :"database" => database,
117
- :"document" => document,
118
- :"any_path" => any_path
119
- )
120
- end
121
-
122
- # Returns a fully-qualified database_root resource name string.
123
- # @param project [String]
124
- # @param database [String]
125
- # @return [String]
126
- def self.database_root_path project, database
127
- DATABASE_ROOT_PATH_TEMPLATE.render(
128
- :"project" => project,
129
- :"database" => database
130
- )
131
- end
132
-
133
- # Returns a fully-qualified document_path resource name string.
134
- # @param project [String]
135
- # @param database [String]
136
- # @param document_path [String]
137
- # @return [String]
138
- def self.document_path_path project, database, document_path
139
- DOCUMENT_PATH_PATH_TEMPLATE.render(
140
- :"project" => project,
141
- :"database" => database,
142
- :"document_path" => document_path
143
- )
144
- end
145
-
146
- # Returns a fully-qualified document_root resource name string.
147
- # @param project [String]
148
- # @param database [String]
149
- # @return [String]
150
- def self.document_root_path project, database
151
- DOCUMENT_ROOT_PATH_TEMPLATE.render(
152
- :"project" => project,
153
- :"database" => database
154
- )
155
- end
156
-
157
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
158
- # Provides the means for authenticating requests made by the client. This parameter can
159
- # be many types.
160
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
161
- # authenticating requests made by this client.
162
- # A `String` will be treated as the path to the keyfile to be used for the construction of
163
- # credentials for this client.
164
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
165
- # credentials for this client.
166
- # A `GRPC::Core::Channel` will be used to make calls through.
167
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
168
- # should already be composed with a `GRPC::Core::CallCredentials` object.
169
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
170
- # metadata for requests, generally, to give OAuth credentials.
171
- # @param scopes [Array<String>]
172
- # The OAuth scopes for this service. This parameter is ignored if
173
- # an updater_proc is supplied.
174
- # @param client_config [Hash]
175
- # A Hash for call options for each method. See
176
- # Google::Gax#construct_settings for the structure of
177
- # this data. Falls back to the default config if not specified
178
- # or the specified config is missing data points.
179
- # @param timeout [Numeric]
180
- # The default timeout, in seconds, for calls made through this client.
181
- # @param metadata [Hash]
182
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
183
- # @param service_address [String]
184
- # Override for the service hostname, or `nil` to leave as the default.
185
- # @param service_port [Integer]
186
- # Override for the service port, or `nil` to leave as the default.
187
- # @param exception_transformer [Proc]
188
- # An optional proc that intercepts any exceptions raised during an API call to inject
189
- # custom error handling.
190
- def initialize \
191
- credentials: nil,
192
- scopes: ALL_SCOPES,
193
- client_config: {},
194
- timeout: DEFAULT_TIMEOUT,
195
- metadata: nil,
196
- service_address: nil,
197
- service_port: nil,
198
- exception_transformer: nil,
199
- lib_name: nil,
200
- lib_version: ""
201
- # These require statements are intentionally placed here to initialize
202
- # the gRPC module only when it's required.
203
- # See https://github.com/googleapis/toolkit/issues/446
204
- require "google/gax/grpc"
205
- require "google/firestore/v1/firestore_services_pb"
206
-
207
- credentials ||= Google::Cloud::Firestore::V1::Credentials.default
208
-
209
- if credentials.is_a?(String) || credentials.is_a?(Hash)
210
- updater_proc = Google::Cloud::Firestore::V1::Credentials.new(credentials).updater_proc
211
- end
212
- if credentials.is_a?(GRPC::Core::Channel)
213
- channel = credentials
214
- end
215
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
216
- chan_creds = credentials
217
- end
218
- if credentials.is_a?(Proc)
219
- updater_proc = credentials
220
- end
221
- if credentials.is_a?(Google::Auth::Credentials)
222
- updater_proc = credentials.updater_proc
223
- end
224
-
225
- package_version = Google::Cloud::Firestore::VERSION
226
-
227
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
228
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
229
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
230
- google_api_client << " grpc/#{GRPC::VERSION}"
231
- google_api_client.freeze
232
-
233
- headers = { :"x-goog-api-client" => google_api_client }
234
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
235
- headers[:"x-goog-user-project"] = credentials.quota_project_id
236
- end
237
- headers.merge!(metadata) unless metadata.nil?
238
- client_config_file = Pathname.new(__dir__).join(
239
- "firestore_client_config.json"
240
- )
241
- defaults = client_config_file.open do |f|
242
- Google::Gax.construct_settings(
243
- "google.firestore.v1.Firestore",
244
- JSON.parse(f.read),
245
- client_config,
246
- Google::Gax::Grpc::STATUS_CODE_NAMES,
247
- timeout,
248
- page_descriptors: PAGE_DESCRIPTORS,
249
- errors: Google::Gax::Grpc::API_ERRORS,
250
- metadata: headers
251
- )
252
- end
253
-
254
- # Allow overriding the service path/port in subclasses.
255
- service_path = service_address || self.class::SERVICE_ADDRESS
256
- port = service_port || self.class::DEFAULT_SERVICE_PORT
257
- interceptors = self.class::GRPC_INTERCEPTORS
258
- @firestore_stub = Google::Gax::Grpc.create_stub(
259
- service_path,
260
- port,
261
- chan_creds: chan_creds,
262
- channel: channel,
263
- updater_proc: updater_proc,
264
- scopes: scopes,
265
- interceptors: interceptors,
266
- &Google::Firestore::V1::Firestore::Stub.method(:new)
267
- )
268
-
269
- @get_document = Google::Gax.create_api_call(
270
- @firestore_stub.method(:get_document),
271
- defaults["get_document"],
272
- exception_transformer: exception_transformer,
273
- params_extractor: proc do |request|
274
- {'name' => request.name}
275
- end
276
- )
277
- @list_documents = Google::Gax.create_api_call(
278
- @firestore_stub.method(:list_documents),
279
- defaults["list_documents"],
280
- exception_transformer: exception_transformer
281
- )
282
- @create_document = Google::Gax.create_api_call(
283
- @firestore_stub.method(:create_document),
284
- defaults["create_document"],
285
- exception_transformer: exception_transformer
286
- )
287
- @update_document = Google::Gax.create_api_call(
288
- @firestore_stub.method(:update_document),
289
- defaults["update_document"],
290
- exception_transformer: exception_transformer,
291
- params_extractor: proc do |request|
292
- {'document.name' => request.document.name}
293
- end
294
- )
295
- @delete_document = Google::Gax.create_api_call(
296
- @firestore_stub.method(:delete_document),
297
- defaults["delete_document"],
298
- exception_transformer: exception_transformer,
299
- params_extractor: proc do |request|
300
- {'name' => request.name}
301
- end
302
- )
303
- @batch_get_documents = Google::Gax.create_api_call(
304
- @firestore_stub.method(:batch_get_documents),
305
- defaults["batch_get_documents"],
306
- exception_transformer: exception_transformer,
307
- params_extractor: proc do |request|
308
- {'database' => request.database}
309
- end
310
- )
311
- @begin_transaction = Google::Gax.create_api_call(
312
- @firestore_stub.method(:begin_transaction),
313
- defaults["begin_transaction"],
314
- exception_transformer: exception_transformer,
315
- params_extractor: proc do |request|
316
- {'database' => request.database}
317
- end
318
- )
319
- @commit = Google::Gax.create_api_call(
320
- @firestore_stub.method(:commit),
321
- defaults["commit"],
322
- exception_transformer: exception_transformer,
323
- params_extractor: proc do |request|
324
- {'database' => request.database}
325
- end
326
- )
327
- @rollback = Google::Gax.create_api_call(
328
- @firestore_stub.method(:rollback),
329
- defaults["rollback"],
330
- exception_transformer: exception_transformer,
331
- params_extractor: proc do |request|
332
- {'database' => request.database}
333
- end
334
- )
335
- @run_query = Google::Gax.create_api_call(
336
- @firestore_stub.method(:run_query),
337
- defaults["run_query"],
338
- exception_transformer: exception_transformer,
339
- params_extractor: proc do |request|
340
- {'parent' => request.parent}
341
- end
342
- )
343
- @write = Google::Gax.create_api_call(
344
- @firestore_stub.method(:write),
345
- defaults["write"],
346
- exception_transformer: exception_transformer
347
- )
348
- @listen = Google::Gax.create_api_call(
349
- @firestore_stub.method(:listen),
350
- defaults["listen"],
351
- exception_transformer: exception_transformer
352
- )
353
- @list_collection_ids = Google::Gax.create_api_call(
354
- @firestore_stub.method(:list_collection_ids),
355
- defaults["list_collection_ids"],
356
- exception_transformer: exception_transformer,
357
- params_extractor: proc do |request|
358
- {'parent' => request.parent}
359
- end
360
- )
361
- end
362
-
363
- # Service calls
364
-
365
- # Gets a single document.
366
- #
367
- # @param name [String]
368
- # Required. The resource name of the Document to get. In the format:
369
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
370
- # @param mask [Google::Firestore::V1::DocumentMask | Hash]
371
- # The fields to return. If not set, returns all fields.
372
- #
373
- # If the document has a field that is not present in this mask, that field
374
- # will not be returned in the response.
375
- # A hash of the same form as `Google::Firestore::V1::DocumentMask`
376
- # can also be provided.
377
- # @param transaction [String]
378
- # Reads the document in a transaction.
379
- # @param read_time [Google::Protobuf::Timestamp | Hash]
380
- # Reads the version of the document at the given time.
381
- # This may not be older than 60 seconds.
382
- # A hash of the same form as `Google::Protobuf::Timestamp`
383
- # can also be provided.
384
- # @param options [Google::Gax::CallOptions]
385
- # Overrides the default settings for this call, e.g, timeout,
386
- # retries, etc.
387
- # @yield [result, operation] Access the result along with the RPC operation
388
- # @yieldparam result [Google::Firestore::V1::Document]
389
- # @yieldparam operation [GRPC::ActiveCall::Operation]
390
- # @return [Google::Firestore::V1::Document]
391
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
392
- # @example
393
- # require "google/cloud/firestore/v1"
394
- #
395
- # firestore_client = Google::Cloud::Firestore::V1.new
396
- # formatted_name = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
397
- # response = firestore_client.get_document(formatted_name)
398
-
399
- def get_document \
400
- name,
401
- mask: nil,
402
- transaction: nil,
403
- read_time: nil,
404
- options: nil,
405
- &block
406
- req = {
407
- name: name,
408
- mask: mask,
409
- transaction: transaction,
410
- read_time: read_time
411
- }.delete_if { |_, v| v.nil? }
412
- req = Google::Gax::to_proto(req, Google::Firestore::V1::GetDocumentRequest)
413
- @get_document.call(req, options, &block)
414
- end
415
-
416
- # Lists documents.
417
- #
418
- # @param parent [String]
419
- # Required. The parent resource name. In the format:
420
- # `projects/{project_id}/databases/{database_id}/documents` or
421
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
422
- # For example:
423
- # `projects/my-project/databases/my-database/documents` or
424
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
425
- # @param collection_id [String]
426
- # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`
427
- # or `messages`.
428
- # @param page_size [Integer]
429
- # The maximum number of resources contained in the underlying API
430
- # response. If page streaming is performed per-resource, this
431
- # parameter does not affect the return value. If page streaming is
432
- # performed per-page, this determines the maximum number of
433
- # resources in a page.
434
- # @param order_by [String]
435
- # The order to sort results by. For example: `priority desc, name`.
436
- # @param mask [Google::Firestore::V1::DocumentMask | Hash]
437
- # The fields to return. If not set, returns all fields.
438
- #
439
- # If a document has a field that is not present in this mask, that field
440
- # will not be returned in the response.
441
- # A hash of the same form as `Google::Firestore::V1::DocumentMask`
442
- # can also be provided.
443
- # @param transaction [String]
444
- # Reads documents in a transaction.
445
- # @param read_time [Google::Protobuf::Timestamp | Hash]
446
- # Reads documents as they were at the given time.
447
- # This may not be older than 60 seconds.
448
- # A hash of the same form as `Google::Protobuf::Timestamp`
449
- # can also be provided.
450
- # @param show_missing [true, false]
451
- # If the list should show missing documents. A missing document is a
452
- # document that does not exist but has sub-documents. These documents will
453
- # be returned with a key but will not have fields, {Google::Firestore::V1::Document#create_time Document#create_time},
454
- # or {Google::Firestore::V1::Document#update_time Document#update_time} set.
455
- #
456
- # Requests with `show_missing` may not specify `where` or
457
- # `order_by`.
458
- # @param options [Google::Gax::CallOptions]
459
- # Overrides the default settings for this call, e.g, timeout,
460
- # retries, etc.
461
- # @yield [result, operation] Access the result along with the RPC operation
462
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Firestore::V1::Document>]
463
- # @yieldparam operation [GRPC::ActiveCall::Operation]
464
- # @return [Google::Gax::PagedEnumerable<Google::Firestore::V1::Document>]
465
- # An enumerable of Google::Firestore::V1::Document instances.
466
- # See Google::Gax::PagedEnumerable documentation for other
467
- # operations such as per-page iteration or access to the response
468
- # object.
469
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
470
- # @example
471
- # require "google/cloud/firestore/v1"
472
- #
473
- # firestore_client = Google::Cloud::Firestore::V1.new
474
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
475
- #
476
- # # TODO: Initialize `collection_id`:
477
- # collection_id = ''
478
- #
479
- # # Iterate over all results.
480
- # firestore_client.list_documents(formatted_parent, collection_id).each do |element|
481
- # # Process element.
482
- # end
483
- #
484
- # # Or iterate over results one page at a time.
485
- # firestore_client.list_documents(formatted_parent, collection_id).each_page do |page|
486
- # # Process each page at a time.
487
- # page.each do |element|
488
- # # Process element.
489
- # end
490
- # end
491
-
492
- def list_documents \
493
- parent,
494
- collection_id,
495
- page_size: nil,
496
- order_by: nil,
497
- mask: nil,
498
- transaction: nil,
499
- read_time: nil,
500
- show_missing: nil,
501
- options: nil,
502
- &block
503
- req = {
504
- parent: parent,
505
- collection_id: collection_id,
506
- page_size: page_size,
507
- order_by: order_by,
508
- mask: mask,
509
- transaction: transaction,
510
- read_time: read_time,
511
- show_missing: show_missing
512
- }.delete_if { |_, v| v.nil? }
513
- req = Google::Gax::to_proto(req, Google::Firestore::V1::ListDocumentsRequest)
514
- @list_documents.call(req, options, &block)
515
- end
516
-
517
- # Creates a new document.
518
- #
519
- # @param parent [String]
520
- # Required. The parent resource. For example:
521
- # `projects/{project_id}/databases/{database_id}/documents` or
522
- # `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
523
- # @param collection_id [String]
524
- # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`.
525
- # @param document_id [String]
526
- # The client-assigned document ID to use for this document.
527
- #
528
- # Optional. If not specified, an ID will be assigned by the service.
529
- # @param document [Google::Firestore::V1::Document | Hash]
530
- # Required. The document to create. `name` must not be set.
531
- # A hash of the same form as `Google::Firestore::V1::Document`
532
- # can also be provided.
533
- # @param mask [Google::Firestore::V1::DocumentMask | Hash]
534
- # The fields to return. If not set, returns all fields.
535
- #
536
- # If the document has a field that is not present in this mask, that field
537
- # will not be returned in the response.
538
- # A hash of the same form as `Google::Firestore::V1::DocumentMask`
539
- # can also be provided.
540
- # @param options [Google::Gax::CallOptions]
541
- # Overrides the default settings for this call, e.g, timeout,
542
- # retries, etc.
543
- # @yield [result, operation] Access the result along with the RPC operation
544
- # @yieldparam result [Google::Firestore::V1::Document]
545
- # @yieldparam operation [GRPC::ActiveCall::Operation]
546
- # @return [Google::Firestore::V1::Document]
547
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
548
- # @example
549
- # require "google/cloud/firestore/v1"
550
- #
551
- # firestore_client = Google::Cloud::Firestore::V1.new
552
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
553
- #
554
- # # TODO: Initialize `collection_id`:
555
- # collection_id = ''
556
- #
557
- # # TODO: Initialize `document_id`:
558
- # document_id = ''
559
- #
560
- # # TODO: Initialize `document`:
561
- # document = {}
562
- # response = firestore_client.create_document(formatted_parent, collection_id, document_id, document)
563
-
564
- def create_document \
565
- parent,
566
- collection_id,
567
- document_id,
568
- document,
569
- mask: nil,
570
- options: nil,
571
- &block
572
- req = {
573
- parent: parent,
574
- collection_id: collection_id,
575
- document_id: document_id,
576
- document: document,
577
- mask: mask
578
- }.delete_if { |_, v| v.nil? }
579
- req = Google::Gax::to_proto(req, Google::Firestore::V1::CreateDocumentRequest)
580
- @create_document.call(req, options, &block)
581
- end
582
-
583
- # Updates or inserts a document.
584
- #
585
- # @param document [Google::Firestore::V1::Document | Hash]
586
- # Required. The updated document.
587
- # Creates the document if it does not already exist.
588
- # A hash of the same form as `Google::Firestore::V1::Document`
589
- # can also be provided.
590
- # @param update_mask [Google::Firestore::V1::DocumentMask | Hash]
591
- # The fields to update.
592
- # None of the field paths in the mask may contain a reserved name.
593
- #
594
- # If the document exists on the server and has fields not referenced in the
595
- # mask, they are left unchanged.
596
- # Fields referenced in the mask, but not present in the input document, are
597
- # deleted from the document on the server.
598
- # A hash of the same form as `Google::Firestore::V1::DocumentMask`
599
- # can also be provided.
600
- # @param mask [Google::Firestore::V1::DocumentMask | Hash]
601
- # The fields to return. If not set, returns all fields.
602
- #
603
- # If the document has a field that is not present in this mask, that field
604
- # will not be returned in the response.
605
- # A hash of the same form as `Google::Firestore::V1::DocumentMask`
606
- # can also be provided.
607
- # @param current_document [Google::Firestore::V1::Precondition | Hash]
608
- # An optional precondition on the document.
609
- # The request will fail if this is set and not met by the target document.
610
- # A hash of the same form as `Google::Firestore::V1::Precondition`
611
- # can also be provided.
612
- # @param options [Google::Gax::CallOptions]
613
- # Overrides the default settings for this call, e.g, timeout,
614
- # retries, etc.
615
- # @yield [result, operation] Access the result along with the RPC operation
616
- # @yieldparam result [Google::Firestore::V1::Document]
617
- # @yieldparam operation [GRPC::ActiveCall::Operation]
618
- # @return [Google::Firestore::V1::Document]
619
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
620
- # @example
621
- # require "google/cloud/firestore/v1"
622
- #
623
- # firestore_client = Google::Cloud::Firestore::V1.new
624
- #
625
- # # TODO: Initialize `document`:
626
- # document = {}
627
- #
628
- # # TODO: Initialize `update_mask`:
629
- # update_mask = {}
630
- # response = firestore_client.update_document(document, update_mask)
631
-
632
- def update_document \
633
- document,
634
- update_mask,
635
- mask: nil,
636
- current_document: nil,
637
- options: nil,
638
- &block
639
- req = {
640
- document: document,
641
- update_mask: update_mask,
642
- mask: mask,
643
- current_document: current_document
644
- }.delete_if { |_, v| v.nil? }
645
- req = Google::Gax::to_proto(req, Google::Firestore::V1::UpdateDocumentRequest)
646
- @update_document.call(req, options, &block)
647
- end
648
-
649
- # Deletes a document.
650
- #
651
- # @param name [String]
652
- # Required. The resource name of the Document to delete. In the format:
653
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
654
- # @param current_document [Google::Firestore::V1::Precondition | Hash]
655
- # An optional precondition on the document.
656
- # The request will fail if this is set and not met by the target document.
657
- # A hash of the same form as `Google::Firestore::V1::Precondition`
658
- # can also be provided.
659
- # @param options [Google::Gax::CallOptions]
660
- # Overrides the default settings for this call, e.g, timeout,
661
- # retries, etc.
662
- # @yield [result, operation] Access the result along with the RPC operation
663
- # @yieldparam result []
664
- # @yieldparam operation [GRPC::ActiveCall::Operation]
665
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
666
- # @example
667
- # require "google/cloud/firestore/v1"
668
- #
669
- # firestore_client = Google::Cloud::Firestore::V1.new
670
- # formatted_name = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
671
- # firestore_client.delete_document(formatted_name)
672
-
673
- def delete_document \
674
- name,
675
- current_document: nil,
676
- options: nil,
677
- &block
678
- req = {
679
- name: name,
680
- current_document: current_document
681
- }.delete_if { |_, v| v.nil? }
682
- req = Google::Gax::to_proto(req, Google::Firestore::V1::DeleteDocumentRequest)
683
- @delete_document.call(req, options, &block)
684
- nil
685
- end
686
-
687
- # Gets multiple documents.
688
- #
689
- # Documents returned by this method are not guaranteed to be returned in the
690
- # same order that they were requested.
691
- #
692
- # @param database [String]
693
- # Required. The database name. In the format:
694
- # `projects/{project_id}/databases/{database_id}`.
695
- # @param documents [Array<String>]
696
- # The names of the documents to retrieve. In the format:
697
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
698
- # The request will fail if any of the document is not a child resource of the
699
- # given `database`. Duplicate names will be elided.
700
- # @param mask [Google::Firestore::V1::DocumentMask | Hash]
701
- # The fields to return. If not set, returns all fields.
702
- #
703
- # If a document has a field that is not present in this mask, that field will
704
- # not be returned in the response.
705
- # A hash of the same form as `Google::Firestore::V1::DocumentMask`
706
- # can also be provided.
707
- # @param transaction [String]
708
- # Reads documents in a transaction.
709
- # @param new_transaction [Google::Firestore::V1::TransactionOptions | Hash]
710
- # Starts a new transaction and reads the documents.
711
- # Defaults to a read-only transaction.
712
- # The new transaction ID will be returned as the first response in the
713
- # stream.
714
- # A hash of the same form as `Google::Firestore::V1::TransactionOptions`
715
- # can also be provided.
716
- # @param read_time [Google::Protobuf::Timestamp | Hash]
717
- # Reads documents as they were at the given time.
718
- # This may not be older than 60 seconds.
719
- # A hash of the same form as `Google::Protobuf::Timestamp`
720
- # can also be provided.
721
- # @param options [Google::Gax::CallOptions]
722
- # Overrides the default settings for this call, e.g, timeout,
723
- # retries, etc.
724
- # @return [Enumerable<Google::Firestore::V1::BatchGetDocumentsResponse>]
725
- # An enumerable of Google::Firestore::V1::BatchGetDocumentsResponse instances.
726
- #
727
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
728
- # @example
729
- # require "google/cloud/firestore/v1"
730
- #
731
- # firestore_client = Google::Cloud::Firestore::V1.new
732
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
733
- #
734
- # # TODO: Initialize `documents`:
735
- # documents = []
736
- # firestore_client.batch_get_documents(formatted_database, documents).each do |element|
737
- # # Process element.
738
- # end
739
-
740
- def batch_get_documents \
741
- database,
742
- documents,
743
- mask: nil,
744
- transaction: nil,
745
- new_transaction: nil,
746
- read_time: nil,
747
- options: nil
748
- req = {
749
- database: database,
750
- documents: documents,
751
- mask: mask,
752
- transaction: transaction,
753
- new_transaction: new_transaction,
754
- read_time: read_time
755
- }.delete_if { |_, v| v.nil? }
756
- req = Google::Gax::to_proto(req, Google::Firestore::V1::BatchGetDocumentsRequest)
757
- @batch_get_documents.call(req, options)
758
- end
759
-
760
- # Starts a new transaction.
761
- #
762
- # @param database [String]
763
- # Required. The database name. In the format:
764
- # `projects/{project_id}/databases/{database_id}`.
765
- # @param options_ [Google::Firestore::V1::TransactionOptions | Hash]
766
- # The options for the transaction.
767
- # Defaults to a read-write transaction.
768
- # A hash of the same form as `Google::Firestore::V1::TransactionOptions`
769
- # can also be provided.
770
- # @param options [Google::Gax::CallOptions]
771
- # Overrides the default settings for this call, e.g, timeout,
772
- # retries, etc.
773
- # @yield [result, operation] Access the result along with the RPC operation
774
- # @yieldparam result [Google::Firestore::V1::BeginTransactionResponse]
775
- # @yieldparam operation [GRPC::ActiveCall::Operation]
776
- # @return [Google::Firestore::V1::BeginTransactionResponse]
777
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
778
- # @example
779
- # require "google/cloud/firestore/v1"
780
- #
781
- # firestore_client = Google::Cloud::Firestore::V1.new
782
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
783
- # response = firestore_client.begin_transaction(formatted_database)
784
-
785
- def begin_transaction \
786
- database,
787
- options_: nil,
788
- options: nil,
789
- &block
790
- req = {
791
- database: database,
792
- options: options_
793
- }.delete_if { |_, v| v.nil? }
794
- req = Google::Gax::to_proto(req, Google::Firestore::V1::BeginTransactionRequest)
795
- @begin_transaction.call(req, options, &block)
796
- end
797
-
798
- # Commits a transaction, while optionally updating documents.
799
- #
800
- # @param database [String]
801
- # Required. The database name. In the format:
802
- # `projects/{project_id}/databases/{database_id}`.
803
- # @param writes [Array<Google::Firestore::V1::Write | Hash>]
804
- # The writes to apply.
805
- #
806
- # Always executed atomically and in order.
807
- # A hash of the same form as `Google::Firestore::V1::Write`
808
- # can also be provided.
809
- # @param transaction [String]
810
- # If set, applies all writes in this transaction, and commits it.
811
- # @param options [Google::Gax::CallOptions]
812
- # Overrides the default settings for this call, e.g, timeout,
813
- # retries, etc.
814
- # @yield [result, operation] Access the result along with the RPC operation
815
- # @yieldparam result [Google::Firestore::V1::CommitResponse]
816
- # @yieldparam operation [GRPC::ActiveCall::Operation]
817
- # @return [Google::Firestore::V1::CommitResponse]
818
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
819
- # @example
820
- # require "google/cloud/firestore/v1"
821
- #
822
- # firestore_client = Google::Cloud::Firestore::V1.new
823
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
824
- #
825
- # # TODO: Initialize `writes`:
826
- # writes = []
827
- # response = firestore_client.commit(formatted_database, writes)
828
-
829
- def commit \
830
- database,
831
- writes,
832
- transaction: nil,
833
- options: nil,
834
- &block
835
- req = {
836
- database: database,
837
- writes: writes,
838
- transaction: transaction
839
- }.delete_if { |_, v| v.nil? }
840
- req = Google::Gax::to_proto(req, Google::Firestore::V1::CommitRequest)
841
- @commit.call(req, options, &block)
842
- end
843
-
844
- # Rolls back a transaction.
845
- #
846
- # @param database [String]
847
- # Required. The database name. In the format:
848
- # `projects/{project_id}/databases/{database_id}`.
849
- # @param transaction [String]
850
- # Required. The transaction to roll back.
851
- # @param options [Google::Gax::CallOptions]
852
- # Overrides the default settings for this call, e.g, timeout,
853
- # retries, etc.
854
- # @yield [result, operation] Access the result along with the RPC operation
855
- # @yieldparam result []
856
- # @yieldparam operation [GRPC::ActiveCall::Operation]
857
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
858
- # @example
859
- # require "google/cloud/firestore/v1"
860
- #
861
- # firestore_client = Google::Cloud::Firestore::V1.new
862
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
863
- #
864
- # # TODO: Initialize `transaction`:
865
- # transaction = ''
866
- # firestore_client.rollback(formatted_database, transaction)
867
-
868
- def rollback \
869
- database,
870
- transaction,
871
- options: nil,
872
- &block
873
- req = {
874
- database: database,
875
- transaction: transaction
876
- }.delete_if { |_, v| v.nil? }
877
- req = Google::Gax::to_proto(req, Google::Firestore::V1::RollbackRequest)
878
- @rollback.call(req, options, &block)
879
- nil
880
- end
881
-
882
- # Runs a query.
883
- #
884
- # @param parent [String]
885
- # Required. The parent resource name. In the format:
886
- # `projects/{project_id}/databases/{database_id}/documents` or
887
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
888
- # For example:
889
- # `projects/my-project/databases/my-database/documents` or
890
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
891
- # @param structured_query [Google::Firestore::V1::StructuredQuery | Hash]
892
- # A structured query.
893
- # A hash of the same form as `Google::Firestore::V1::StructuredQuery`
894
- # can also be provided.
895
- # @param transaction [String]
896
- # Reads documents in a transaction.
897
- # @param new_transaction [Google::Firestore::V1::TransactionOptions | Hash]
898
- # Starts a new transaction and reads the documents.
899
- # Defaults to a read-only transaction.
900
- # The new transaction ID will be returned as the first response in the
901
- # stream.
902
- # A hash of the same form as `Google::Firestore::V1::TransactionOptions`
903
- # can also be provided.
904
- # @param read_time [Google::Protobuf::Timestamp | Hash]
905
- # Reads documents as they were at the given time.
906
- # This may not be older than 60 seconds.
907
- # A hash of the same form as `Google::Protobuf::Timestamp`
908
- # can also be provided.
909
- # @param options [Google::Gax::CallOptions]
910
- # Overrides the default settings for this call, e.g, timeout,
911
- # retries, etc.
912
- # @return [Enumerable<Google::Firestore::V1::RunQueryResponse>]
913
- # An enumerable of Google::Firestore::V1::RunQueryResponse instances.
914
- #
915
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
916
- # @example
917
- # require "google/cloud/firestore/v1"
918
- #
919
- # firestore_client = Google::Cloud::Firestore::V1.new
920
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
921
- # firestore_client.run_query(formatted_parent).each do |element|
922
- # # Process element.
923
- # end
924
-
925
- def run_query \
926
- parent,
927
- structured_query: nil,
928
- transaction: nil,
929
- new_transaction: nil,
930
- read_time: nil,
931
- options: nil
932
- req = {
933
- parent: parent,
934
- structured_query: structured_query,
935
- transaction: transaction,
936
- new_transaction: new_transaction,
937
- read_time: read_time
938
- }.delete_if { |_, v| v.nil? }
939
- req = Google::Gax::to_proto(req, Google::Firestore::V1::RunQueryRequest)
940
- @run_query.call(req, options)
941
- end
942
-
943
- # Streams batches of document updates and deletes, in order.
944
- #
945
- # @param reqs [Enumerable<Google::Firestore::V1::WriteRequest>]
946
- # The input requests.
947
- # @param options [Google::Gax::CallOptions]
948
- # Overrides the default settings for this call, e.g, timeout,
949
- # retries, etc.
950
- # @return [Enumerable<Google::Firestore::V1::WriteResponse>]
951
- # An enumerable of Google::Firestore::V1::WriteResponse instances.
952
- #
953
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
954
- #
955
- # @note
956
- # EXPERIMENTAL:
957
- # Streaming requests are still undergoing review.
958
- # This method interface might change in the future.
959
- #
960
- # @example
961
- # require "google/cloud/firestore/v1"
962
- #
963
- # firestore_client = Google::Cloud::Firestore::V1.new
964
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
965
- # request = { database: formatted_database }
966
- # requests = [request]
967
- # firestore_client.write(requests).each do |element|
968
- # # Process element.
969
- # end
970
-
971
- def write reqs, options: nil
972
- request_protos = reqs.lazy.map do |req|
973
- Google::Gax::to_proto(req, Google::Firestore::V1::WriteRequest)
974
- end
975
- @write.call(request_protos, options)
976
- end
977
-
978
- # Listens to changes.
979
- #
980
- # @param reqs [Enumerable<Google::Firestore::V1::ListenRequest>]
981
- # The input requests.
982
- # @param options [Google::Gax::CallOptions]
983
- # Overrides the default settings for this call, e.g, timeout,
984
- # retries, etc.
985
- # @return [Enumerable<Google::Firestore::V1::ListenResponse>]
986
- # An enumerable of Google::Firestore::V1::ListenResponse instances.
987
- #
988
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
989
- #
990
- # @note
991
- # EXPERIMENTAL:
992
- # Streaming requests are still undergoing review.
993
- # This method interface might change in the future.
994
- #
995
- # @example
996
- # require "google/cloud/firestore/v1"
997
- #
998
- # firestore_client = Google::Cloud::Firestore::V1.new
999
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
1000
- # request = { database: formatted_database }
1001
- # requests = [request]
1002
- # firestore_client.listen(requests).each do |element|
1003
- # # Process element.
1004
- # end
1005
-
1006
- def listen reqs, options: nil
1007
- request_protos = reqs.lazy.map do |req|
1008
- Google::Gax::to_proto(req, Google::Firestore::V1::ListenRequest)
1009
- end
1010
- @listen.call(request_protos, options)
1011
- end
1012
-
1013
- # Lists all the collection IDs underneath a document.
1014
- #
1015
- # @param parent [String]
1016
- # Required. The parent document. In the format:
1017
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
1018
- # For example:
1019
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
1020
- # @param page_size [Integer]
1021
- # The maximum number of resources contained in the underlying API
1022
- # response. If page streaming is performed per-resource, this
1023
- # parameter does not affect the return value. If page streaming is
1024
- # performed per-page, this determines the maximum number of
1025
- # resources in a page.
1026
- # @param options [Google::Gax::CallOptions]
1027
- # Overrides the default settings for this call, e.g, timeout,
1028
- # retries, etc.
1029
- # @yield [result, operation] Access the result along with the RPC operation
1030
- # @yieldparam result [Google::Gax::PagedEnumerable<String>]
1031
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1032
- # @return [Google::Gax::PagedEnumerable<String>]
1033
- # An enumerable of String instances.
1034
- # See Google::Gax::PagedEnumerable documentation for other
1035
- # operations such as per-page iteration or access to the response
1036
- # object.
1037
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1038
- # @example
1039
- # require "google/cloud/firestore/v1"
1040
- #
1041
- # firestore_client = Google::Cloud::Firestore::V1.new
1042
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
1043
- #
1044
- # # Iterate over all results.
1045
- # firestore_client.list_collection_ids(formatted_parent).each do |element|
1046
- # # Process element.
1047
- # end
1048
- #
1049
- # # Or iterate over results one page at a time.
1050
- # firestore_client.list_collection_ids(formatted_parent).each_page do |page|
1051
- # # Process each page at a time.
1052
- # page.each do |element|
1053
- # # Process element.
1054
- # end
1055
- # end
1056
-
1057
- def list_collection_ids \
1058
- parent,
1059
- page_size: nil,
1060
- options: nil,
1061
- &block
1062
- req = {
1063
- parent: parent,
1064
- page_size: page_size
1065
- }.delete_if { |_, v| v.nil? }
1066
- req = Google::Gax::to_proto(req, Google::Firestore::V1::ListCollectionIdsRequest)
1067
- @list_collection_ids.call(req, options, &block)
1068
- end
1069
- end
1070
- end
1071
- end
1072
- end
1073
- end