google-cloud-firestore 0.24.2 → 0.25.0

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