google-cloud-firestore 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,1081 +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/v1beta1/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/v1beta1/firestore_pb"
29
- require "google/cloud/firestore/v1beta1/credentials"
30
- require "google/cloud/firestore/version"
31
-
32
- module Google
33
- module Cloud
34
- module Firestore
35
- module V1beta1
36
- # The Cloud Firestore service.
37
- #
38
- # This service exposes several types of comparable timestamps:
39
- #
40
- # * `create_time` - The time at which a document was created. Changes only
41
- # when a document is deleted, then re-created. Increases in a strict
42
- # monotonic fashion.
43
- # * `update_time` - The time at which a document was last updated. Changes
44
- # every time a document is modified. Does not change when a write results
45
- # in no modifications. Increases in a strict monotonic fashion.
46
- # * `read_time` - The time at which a particular state was observed. Used
47
- # to denote a consistent snapshot of the database or the time at which a
48
- # Document was observed to not exist.
49
- # * `commit_time` - The time at which the writes in a transaction were
50
- # committed. Any read with an equal or greater `read_time` is guaranteed
51
- # to see the effects of the transaction.
52
- #
53
- # @!attribute [r] firestore_stub
54
- # @return [Google::Firestore::V1beta1::Firestore::Stub]
55
- class FirestoreClient
56
- # @private
57
- attr_reader :firestore_stub
58
-
59
- # The default address of the service.
60
- SERVICE_ADDRESS = "firestore.googleapis.com".freeze
61
-
62
- # The default port of the service.
63
- DEFAULT_SERVICE_PORT = 443
64
-
65
- # The default set of gRPC interceptors.
66
- GRPC_INTERCEPTORS = []
67
-
68
- DEFAULT_TIMEOUT = 30
69
-
70
- PAGE_DESCRIPTORS = {
71
- "list_documents" => Google::Gax::PageDescriptor.new(
72
- "page_token",
73
- "next_page_token",
74
- "documents"),
75
- "list_collection_ids" => Google::Gax::PageDescriptor.new(
76
- "page_token",
77
- "next_page_token",
78
- "collection_ids")
79
- }.freeze
80
-
81
- private_constant :PAGE_DESCRIPTORS
82
-
83
- # The scopes needed to make gRPC calls to all of the methods defined in
84
- # this service.
85
- ALL_SCOPES = [
86
- "https://www.googleapis.com/auth/cloud-platform",
87
- "https://www.googleapis.com/auth/datastore"
88
- ].freeze
89
-
90
-
91
- ANY_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
92
- "projects/{project}/databases/{database}/documents/{document}/{any_path=**}"
93
- )
94
-
95
- private_constant :ANY_PATH_PATH_TEMPLATE
96
-
97
- DATABASE_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
98
- "projects/{project}/databases/{database}"
99
- )
100
-
101
- private_constant :DATABASE_ROOT_PATH_TEMPLATE
102
-
103
- DOCUMENT_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
104
- "projects/{project}/databases/{database}/documents/{document_path=**}"
105
- )
106
-
107
- private_constant :DOCUMENT_PATH_PATH_TEMPLATE
108
-
109
- DOCUMENT_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
110
- "projects/{project}/databases/{database}/documents"
111
- )
112
-
113
- private_constant :DOCUMENT_ROOT_PATH_TEMPLATE
114
-
115
- # Returns a fully-qualified any_path resource name string.
116
- # @param project [String]
117
- # @param database [String]
118
- # @param document [String]
119
- # @param any_path [String]
120
- # @return [String]
121
- def self.any_path_path project, database, document, any_path
122
- ANY_PATH_PATH_TEMPLATE.render(
123
- :"project" => project,
124
- :"database" => database,
125
- :"document" => document,
126
- :"any_path" => any_path
127
- )
128
- end
129
-
130
- # Returns a fully-qualified database_root resource name string.
131
- # @param project [String]
132
- # @param database [String]
133
- # @return [String]
134
- def self.database_root_path project, database
135
- DATABASE_ROOT_PATH_TEMPLATE.render(
136
- :"project" => project,
137
- :"database" => database
138
- )
139
- end
140
-
141
- # Returns a fully-qualified document_path resource name string.
142
- # @param project [String]
143
- # @param database [String]
144
- # @param document_path [String]
145
- # @return [String]
146
- def self.document_path_path project, database, document_path
147
- DOCUMENT_PATH_PATH_TEMPLATE.render(
148
- :"project" => project,
149
- :"database" => database,
150
- :"document_path" => document_path
151
- )
152
- end
153
-
154
- # Returns a fully-qualified document_root resource name string.
155
- # @param project [String]
156
- # @param database [String]
157
- # @return [String]
158
- def self.document_root_path project, database
159
- DOCUMENT_ROOT_PATH_TEMPLATE.render(
160
- :"project" => project,
161
- :"database" => database
162
- )
163
- end
164
-
165
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
166
- # Provides the means for authenticating requests made by the client. This parameter can
167
- # be many types.
168
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
169
- # authenticating requests made by this client.
170
- # A `String` will be treated as the path to the keyfile to be used for the construction of
171
- # credentials for this client.
172
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
173
- # credentials for this client.
174
- # A `GRPC::Core::Channel` will be used to make calls through.
175
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
176
- # should already be composed with a `GRPC::Core::CallCredentials` object.
177
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
178
- # metadata for requests, generally, to give OAuth credentials.
179
- # @param scopes [Array<String>]
180
- # The OAuth scopes for this service. This parameter is ignored if
181
- # an updater_proc is supplied.
182
- # @param client_config [Hash]
183
- # A Hash for call options for each method. See
184
- # Google::Gax#construct_settings for the structure of
185
- # this data. Falls back to the default config if not specified
186
- # or the specified config is missing data points.
187
- # @param timeout [Numeric]
188
- # The default timeout, in seconds, for calls made through this client.
189
- # @param metadata [Hash]
190
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
191
- # @param service_address [String]
192
- # Override for the service hostname, or `nil` to leave as the default.
193
- # @param service_port [Integer]
194
- # Override for the service port, or `nil` to leave as the default.
195
- # @param exception_transformer [Proc]
196
- # An optional proc that intercepts any exceptions raised during an API call to inject
197
- # custom error handling.
198
- def initialize \
199
- credentials: nil,
200
- scopes: ALL_SCOPES,
201
- client_config: {},
202
- timeout: DEFAULT_TIMEOUT,
203
- metadata: nil,
204
- service_address: nil,
205
- service_port: nil,
206
- exception_transformer: nil,
207
- lib_name: nil,
208
- lib_version: ""
209
- # These require statements are intentionally placed here to initialize
210
- # the gRPC module only when it's required.
211
- # See https://github.com/googleapis/toolkit/issues/446
212
- require "google/gax/grpc"
213
- require "google/firestore/v1beta1/firestore_services_pb"
214
-
215
- credentials ||= Google::Cloud::Firestore::V1beta1::Credentials.default
216
-
217
- if credentials.is_a?(String) || credentials.is_a?(Hash)
218
- updater_proc = Google::Cloud::Firestore::V1beta1::Credentials.new(credentials).updater_proc
219
- end
220
- if credentials.is_a?(GRPC::Core::Channel)
221
- channel = credentials
222
- end
223
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
224
- chan_creds = credentials
225
- end
226
- if credentials.is_a?(Proc)
227
- updater_proc = credentials
228
- end
229
- if credentials.is_a?(Google::Auth::Credentials)
230
- updater_proc = credentials.updater_proc
231
- end
232
-
233
- package_version = Google::Cloud::Firestore::VERSION
234
-
235
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
236
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
237
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
238
- google_api_client << " grpc/#{GRPC::VERSION}"
239
- google_api_client.freeze
240
-
241
- headers = { :"x-goog-api-client" => google_api_client }
242
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
243
- headers[:"x-goog-user-project"] = credentials.quota_project_id
244
- end
245
- headers.merge!(metadata) unless metadata.nil?
246
- client_config_file = Pathname.new(__dir__).join(
247
- "firestore_client_config.json"
248
- )
249
- defaults = client_config_file.open do |f|
250
- Google::Gax.construct_settings(
251
- "google.firestore.v1beta1.Firestore",
252
- JSON.parse(f.read),
253
- client_config,
254
- Google::Gax::Grpc::STATUS_CODE_NAMES,
255
- timeout,
256
- page_descriptors: PAGE_DESCRIPTORS,
257
- errors: Google::Gax::Grpc::API_ERRORS,
258
- metadata: headers
259
- )
260
- end
261
-
262
- # Allow overriding the service path/port in subclasses.
263
- service_path = service_address || self.class::SERVICE_ADDRESS
264
- port = service_port || self.class::DEFAULT_SERVICE_PORT
265
- interceptors = self.class::GRPC_INTERCEPTORS
266
- @firestore_stub = Google::Gax::Grpc.create_stub(
267
- service_path,
268
- port,
269
- chan_creds: chan_creds,
270
- channel: channel,
271
- updater_proc: updater_proc,
272
- scopes: scopes,
273
- interceptors: interceptors,
274
- &Google::Firestore::V1beta1::Firestore::Stub.method(:new)
275
- )
276
-
277
- @get_document = Google::Gax.create_api_call(
278
- @firestore_stub.method(:get_document),
279
- defaults["get_document"],
280
- exception_transformer: exception_transformer,
281
- params_extractor: proc do |request|
282
- {'name' => request.name}
283
- end
284
- )
285
- @list_documents = Google::Gax.create_api_call(
286
- @firestore_stub.method(:list_documents),
287
- defaults["list_documents"],
288
- exception_transformer: exception_transformer
289
- )
290
- @create_document = Google::Gax.create_api_call(
291
- @firestore_stub.method(:create_document),
292
- defaults["create_document"],
293
- exception_transformer: exception_transformer
294
- )
295
- @update_document = Google::Gax.create_api_call(
296
- @firestore_stub.method(:update_document),
297
- defaults["update_document"],
298
- exception_transformer: exception_transformer,
299
- params_extractor: proc do |request|
300
- {'document.name' => request.document.name}
301
- end
302
- )
303
- @delete_document = Google::Gax.create_api_call(
304
- @firestore_stub.method(:delete_document),
305
- defaults["delete_document"],
306
- exception_transformer: exception_transformer,
307
- params_extractor: proc do |request|
308
- {'name' => request.name}
309
- end
310
- )
311
- @batch_get_documents = Google::Gax.create_api_call(
312
- @firestore_stub.method(:batch_get_documents),
313
- defaults["batch_get_documents"],
314
- exception_transformer: exception_transformer,
315
- params_extractor: proc do |request|
316
- {'database' => request.database}
317
- end
318
- )
319
- @begin_transaction = Google::Gax.create_api_call(
320
- @firestore_stub.method(:begin_transaction),
321
- defaults["begin_transaction"],
322
- exception_transformer: exception_transformer,
323
- params_extractor: proc do |request|
324
- {'database' => request.database}
325
- end
326
- )
327
- @commit = Google::Gax.create_api_call(
328
- @firestore_stub.method(:commit),
329
- defaults["commit"],
330
- exception_transformer: exception_transformer,
331
- params_extractor: proc do |request|
332
- {'database' => request.database}
333
- end
334
- )
335
- @rollback = Google::Gax.create_api_call(
336
- @firestore_stub.method(:rollback),
337
- defaults["rollback"],
338
- exception_transformer: exception_transformer,
339
- params_extractor: proc do |request|
340
- {'database' => request.database}
341
- end
342
- )
343
- @run_query = Google::Gax.create_api_call(
344
- @firestore_stub.method(:run_query),
345
- defaults["run_query"],
346
- exception_transformer: exception_transformer,
347
- params_extractor: proc do |request|
348
- {'parent' => request.parent}
349
- end
350
- )
351
- @write = Google::Gax.create_api_call(
352
- @firestore_stub.method(:write),
353
- defaults["write"],
354
- exception_transformer: exception_transformer
355
- )
356
- @listen = Google::Gax.create_api_call(
357
- @firestore_stub.method(:listen),
358
- defaults["listen"],
359
- exception_transformer: exception_transformer
360
- )
361
- @list_collection_ids = Google::Gax.create_api_call(
362
- @firestore_stub.method(:list_collection_ids),
363
- defaults["list_collection_ids"],
364
- exception_transformer: exception_transformer,
365
- params_extractor: proc do |request|
366
- {'parent' => request.parent}
367
- end
368
- )
369
- end
370
-
371
- # Service calls
372
-
373
- # Gets a single document.
374
- #
375
- # @param name [String]
376
- # Required. The resource name of the Document to get. In the format:
377
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
378
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
379
- # The fields to return. If not set, returns all fields.
380
- #
381
- # If the document has a field that is not present in this mask, that field
382
- # will not be returned in the response.
383
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
384
- # can also be provided.
385
- # @param transaction [String]
386
- # Reads the document in a transaction.
387
- # @param read_time [Google::Protobuf::Timestamp | Hash]
388
- # Reads the version of the document at the given time.
389
- # This may not be older than 60 seconds.
390
- # A hash of the same form as `Google::Protobuf::Timestamp`
391
- # can also be provided.
392
- # @param options [Google::Gax::CallOptions]
393
- # Overrides the default settings for this call, e.g, timeout,
394
- # retries, etc.
395
- # @yield [result, operation] Access the result along with the RPC operation
396
- # @yieldparam result [Google::Firestore::V1beta1::Document]
397
- # @yieldparam operation [GRPC::ActiveCall::Operation]
398
- # @return [Google::Firestore::V1beta1::Document]
399
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
400
- # @example
401
- # require "google/cloud/firestore/v1beta1"
402
- #
403
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
404
- # formatted_name = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
405
- # response = firestore_client.get_document(formatted_name)
406
-
407
- def get_document \
408
- name,
409
- mask: nil,
410
- transaction: nil,
411
- read_time: nil,
412
- options: nil,
413
- &block
414
- req = {
415
- name: name,
416
- mask: mask,
417
- transaction: transaction,
418
- read_time: read_time
419
- }.delete_if { |_, v| v.nil? }
420
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::GetDocumentRequest)
421
- @get_document.call(req, options, &block)
422
- end
423
-
424
- # Lists documents.
425
- #
426
- # @param parent [String]
427
- # Required. The parent resource name. In the format:
428
- # `projects/{project_id}/databases/{database_id}/documents` or
429
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
430
- # For example:
431
- # `projects/my-project/databases/my-database/documents` or
432
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
433
- # @param collection_id [String]
434
- # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`
435
- # or `messages`.
436
- # @param page_size [Integer]
437
- # The maximum number of resources contained in the underlying API
438
- # response. If page streaming is performed per-resource, this
439
- # parameter does not affect the return value. If page streaming is
440
- # performed per-page, this determines the maximum number of
441
- # resources in a page.
442
- # @param order_by [String]
443
- # The order to sort results by. For example: `priority desc, name`.
444
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
445
- # The fields to return. If not set, returns all fields.
446
- #
447
- # If a document has a field that is not present in this mask, that field
448
- # will not be returned in the response.
449
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
450
- # can also be provided.
451
- # @param transaction [String]
452
- # Reads documents in a transaction.
453
- # @param read_time [Google::Protobuf::Timestamp | Hash]
454
- # Reads documents as they were at the given time.
455
- # This may not be older than 60 seconds.
456
- # A hash of the same form as `Google::Protobuf::Timestamp`
457
- # can also be provided.
458
- # @param show_missing [true, false]
459
- # If the list should show missing documents. A missing document is a
460
- # document that does not exist but has sub-documents. These documents will
461
- # be returned with a key but will not have fields, {Google::Firestore::V1beta1::Document#create_time Document#create_time},
462
- # or {Google::Firestore::V1beta1::Document#update_time Document#update_time} set.
463
- #
464
- # Requests with `show_missing` may not specify `where` or
465
- # `order_by`.
466
- # @param options [Google::Gax::CallOptions]
467
- # Overrides the default settings for this call, e.g, timeout,
468
- # retries, etc.
469
- # @yield [result, operation] Access the result along with the RPC operation
470
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
471
- # @yieldparam operation [GRPC::ActiveCall::Operation]
472
- # @return [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
473
- # An enumerable of Google::Firestore::V1beta1::Document instances.
474
- # See Google::Gax::PagedEnumerable documentation for other
475
- # operations such as per-page iteration or access to the response
476
- # object.
477
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
478
- # @example
479
- # require "google/cloud/firestore/v1beta1"
480
- #
481
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
482
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
483
- #
484
- # # TODO: Initialize `collection_id`:
485
- # collection_id = ''
486
- #
487
- # # Iterate over all results.
488
- # firestore_client.list_documents(formatted_parent, collection_id).each do |element|
489
- # # Process element.
490
- # end
491
- #
492
- # # Or iterate over results one page at a time.
493
- # firestore_client.list_documents(formatted_parent, collection_id).each_page do |page|
494
- # # Process each page at a time.
495
- # page.each do |element|
496
- # # Process element.
497
- # end
498
- # end
499
-
500
- def list_documents \
501
- parent,
502
- collection_id,
503
- page_size: nil,
504
- order_by: nil,
505
- mask: nil,
506
- transaction: nil,
507
- read_time: nil,
508
- show_missing: nil,
509
- options: nil,
510
- &block
511
- req = {
512
- parent: parent,
513
- collection_id: collection_id,
514
- page_size: page_size,
515
- order_by: order_by,
516
- mask: mask,
517
- transaction: transaction,
518
- read_time: read_time,
519
- show_missing: show_missing
520
- }.delete_if { |_, v| v.nil? }
521
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListDocumentsRequest)
522
- @list_documents.call(req, options, &block)
523
- end
524
-
525
- # Creates a new document.
526
- #
527
- # @param parent [String]
528
- # Required. The parent resource. For example:
529
- # `projects/{project_id}/databases/{database_id}/documents` or
530
- # `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
531
- # @param collection_id [String]
532
- # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`.
533
- # @param document_id [String]
534
- # The client-assigned document ID to use for this document.
535
- #
536
- # Optional. If not specified, an ID will be assigned by the service.
537
- # @param document [Google::Firestore::V1beta1::Document | Hash]
538
- # Required. The document to create. `name` must not be set.
539
- # A hash of the same form as `Google::Firestore::V1beta1::Document`
540
- # can also be provided.
541
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
542
- # The fields to return. If not set, returns all fields.
543
- #
544
- # If the document has a field that is not present in this mask, that field
545
- # will not be returned in the response.
546
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
547
- # can also be provided.
548
- # @param options [Google::Gax::CallOptions]
549
- # Overrides the default settings for this call, e.g, timeout,
550
- # retries, etc.
551
- # @yield [result, operation] Access the result along with the RPC operation
552
- # @yieldparam result [Google::Firestore::V1beta1::Document]
553
- # @yieldparam operation [GRPC::ActiveCall::Operation]
554
- # @return [Google::Firestore::V1beta1::Document]
555
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
556
- # @example
557
- # require "google/cloud/firestore/v1beta1"
558
- #
559
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
560
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
561
- #
562
- # # TODO: Initialize `collection_id`:
563
- # collection_id = ''
564
- #
565
- # # TODO: Initialize `document_id`:
566
- # document_id = ''
567
- #
568
- # # TODO: Initialize `document`:
569
- # document = {}
570
- # response = firestore_client.create_document(formatted_parent, collection_id, document_id, document)
571
-
572
- def create_document \
573
- parent,
574
- collection_id,
575
- document_id,
576
- document,
577
- mask: nil,
578
- options: nil,
579
- &block
580
- req = {
581
- parent: parent,
582
- collection_id: collection_id,
583
- document_id: document_id,
584
- document: document,
585
- mask: mask
586
- }.delete_if { |_, v| v.nil? }
587
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CreateDocumentRequest)
588
- @create_document.call(req, options, &block)
589
- end
590
-
591
- # Updates or inserts a document.
592
- #
593
- # @param document [Google::Firestore::V1beta1::Document | Hash]
594
- # Required. The updated document.
595
- # Creates the document if it does not already exist.
596
- # A hash of the same form as `Google::Firestore::V1beta1::Document`
597
- # can also be provided.
598
- # @param update_mask [Google::Firestore::V1beta1::DocumentMask | Hash]
599
- # The fields to update.
600
- # None of the field paths in the mask may contain a reserved name.
601
- #
602
- # If the document exists on the server and has fields not referenced in the
603
- # mask, they are left unchanged.
604
- # Fields referenced in the mask, but not present in the input document, are
605
- # deleted from the document on the server.
606
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
607
- # can also be provided.
608
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
609
- # The fields to return. If not set, returns all fields.
610
- #
611
- # If the document has a field that is not present in this mask, that field
612
- # will not be returned in the response.
613
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
614
- # can also be provided.
615
- # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
616
- # An optional precondition on the document.
617
- # The request will fail if this is set and not met by the target document.
618
- # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
619
- # can also be provided.
620
- # @param options [Google::Gax::CallOptions]
621
- # Overrides the default settings for this call, e.g, timeout,
622
- # retries, etc.
623
- # @yield [result, operation] Access the result along with the RPC operation
624
- # @yieldparam result [Google::Firestore::V1beta1::Document]
625
- # @yieldparam operation [GRPC::ActiveCall::Operation]
626
- # @return [Google::Firestore::V1beta1::Document]
627
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
628
- # @example
629
- # require "google/cloud/firestore/v1beta1"
630
- #
631
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
632
- #
633
- # # TODO: Initialize `document`:
634
- # document = {}
635
- #
636
- # # TODO: Initialize `update_mask`:
637
- # update_mask = {}
638
- # response = firestore_client.update_document(document, update_mask)
639
-
640
- def update_document \
641
- document,
642
- update_mask,
643
- mask: nil,
644
- current_document: nil,
645
- options: nil,
646
- &block
647
- req = {
648
- document: document,
649
- update_mask: update_mask,
650
- mask: mask,
651
- current_document: current_document
652
- }.delete_if { |_, v| v.nil? }
653
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::UpdateDocumentRequest)
654
- @update_document.call(req, options, &block)
655
- end
656
-
657
- # Deletes a document.
658
- #
659
- # @param name [String]
660
- # Required. The resource name of the Document to delete. In the format:
661
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
662
- # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
663
- # An optional precondition on the document.
664
- # The request will fail if this is set and not met by the target document.
665
- # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
666
- # can also be provided.
667
- # @param options [Google::Gax::CallOptions]
668
- # Overrides the default settings for this call, e.g, timeout,
669
- # retries, etc.
670
- # @yield [result, operation] Access the result along with the RPC operation
671
- # @yieldparam result []
672
- # @yieldparam operation [GRPC::ActiveCall::Operation]
673
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
674
- # @example
675
- # require "google/cloud/firestore/v1beta1"
676
- #
677
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
678
- # formatted_name = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
679
- # firestore_client.delete_document(formatted_name)
680
-
681
- def delete_document \
682
- name,
683
- current_document: nil,
684
- options: nil,
685
- &block
686
- req = {
687
- name: name,
688
- current_document: current_document
689
- }.delete_if { |_, v| v.nil? }
690
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::DeleteDocumentRequest)
691
- @delete_document.call(req, options, &block)
692
- nil
693
- end
694
-
695
- # Gets multiple documents.
696
- #
697
- # Documents returned by this method are not guaranteed to be returned in the
698
- # same order that they were requested.
699
- #
700
- # @param database [String]
701
- # Required. The database name. In the format:
702
- # `projects/{project_id}/databases/{database_id}`.
703
- # @param documents [Array<String>]
704
- # The names of the documents to retrieve. In the format:
705
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
706
- # The request will fail if any of the document is not a child resource of the
707
- # given `database`. Duplicate names will be elided.
708
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
709
- # The fields to return. If not set, returns all fields.
710
- #
711
- # If a document has a field that is not present in this mask, that field will
712
- # not be returned in the response.
713
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
714
- # can also be provided.
715
- # @param transaction [String]
716
- # Reads documents in a transaction.
717
- # @param new_transaction [Google::Firestore::V1beta1::TransactionOptions | Hash]
718
- # Starts a new transaction and reads the documents.
719
- # Defaults to a read-only transaction.
720
- # The new transaction ID will be returned as the first response in the
721
- # stream.
722
- # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
723
- # can also be provided.
724
- # @param read_time [Google::Protobuf::Timestamp | Hash]
725
- # Reads documents as they were at the given time.
726
- # This may not be older than 60 seconds.
727
- # A hash of the same form as `Google::Protobuf::Timestamp`
728
- # can also be provided.
729
- # @param options [Google::Gax::CallOptions]
730
- # Overrides the default settings for this call, e.g, timeout,
731
- # retries, etc.
732
- # @return [Enumerable<Google::Firestore::V1beta1::BatchGetDocumentsResponse>]
733
- # An enumerable of Google::Firestore::V1beta1::BatchGetDocumentsResponse instances.
734
- #
735
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
736
- # @example
737
- # require "google/cloud/firestore/v1beta1"
738
- #
739
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
740
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
741
- #
742
- # # TODO: Initialize `documents`:
743
- # documents = []
744
- # firestore_client.batch_get_documents(formatted_database, documents).each do |element|
745
- # # Process element.
746
- # end
747
-
748
- def batch_get_documents \
749
- database,
750
- documents,
751
- mask: nil,
752
- transaction: nil,
753
- new_transaction: nil,
754
- read_time: nil,
755
- options: nil
756
- req = {
757
- database: database,
758
- documents: documents,
759
- mask: mask,
760
- transaction: transaction,
761
- new_transaction: new_transaction,
762
- read_time: read_time
763
- }.delete_if { |_, v| v.nil? }
764
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BatchGetDocumentsRequest)
765
- @batch_get_documents.call(req, options)
766
- end
767
-
768
- # Starts a new transaction.
769
- #
770
- # @param database [String]
771
- # Required. The database name. In the format:
772
- # `projects/{project_id}/databases/{database_id}`.
773
- # @param options_ [Google::Firestore::V1beta1::TransactionOptions | Hash]
774
- # The options for the transaction.
775
- # Defaults to a read-write transaction.
776
- # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
777
- # can also be provided.
778
- # @param options [Google::Gax::CallOptions]
779
- # Overrides the default settings for this call, e.g, timeout,
780
- # retries, etc.
781
- # @yield [result, operation] Access the result along with the RPC operation
782
- # @yieldparam result [Google::Firestore::V1beta1::BeginTransactionResponse]
783
- # @yieldparam operation [GRPC::ActiveCall::Operation]
784
- # @return [Google::Firestore::V1beta1::BeginTransactionResponse]
785
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
786
- # @example
787
- # require "google/cloud/firestore/v1beta1"
788
- #
789
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
790
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
791
- # response = firestore_client.begin_transaction(formatted_database)
792
-
793
- def begin_transaction \
794
- database,
795
- options_: nil,
796
- options: nil,
797
- &block
798
- req = {
799
- database: database,
800
- options: options_
801
- }.delete_if { |_, v| v.nil? }
802
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BeginTransactionRequest)
803
- @begin_transaction.call(req, options, &block)
804
- end
805
-
806
- # Commits a transaction, while optionally updating documents.
807
- #
808
- # @param database [String]
809
- # Required. The database name. In the format:
810
- # `projects/{project_id}/databases/{database_id}`.
811
- # @param writes [Array<Google::Firestore::V1beta1::Write | Hash>]
812
- # The writes to apply.
813
- #
814
- # Always executed atomically and in order.
815
- # A hash of the same form as `Google::Firestore::V1beta1::Write`
816
- # can also be provided.
817
- # @param transaction [String]
818
- # If set, applies all writes in this transaction, and commits it.
819
- # @param options [Google::Gax::CallOptions]
820
- # Overrides the default settings for this call, e.g, timeout,
821
- # retries, etc.
822
- # @yield [result, operation] Access the result along with the RPC operation
823
- # @yieldparam result [Google::Firestore::V1beta1::CommitResponse]
824
- # @yieldparam operation [GRPC::ActiveCall::Operation]
825
- # @return [Google::Firestore::V1beta1::CommitResponse]
826
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
827
- # @example
828
- # require "google/cloud/firestore/v1beta1"
829
- #
830
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
831
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
832
- #
833
- # # TODO: Initialize `writes`:
834
- # writes = []
835
- # response = firestore_client.commit(formatted_database, writes)
836
-
837
- def commit \
838
- database,
839
- writes,
840
- transaction: nil,
841
- options: nil,
842
- &block
843
- req = {
844
- database: database,
845
- writes: writes,
846
- transaction: transaction
847
- }.delete_if { |_, v| v.nil? }
848
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CommitRequest)
849
- @commit.call(req, options, &block)
850
- end
851
-
852
- # Rolls back a transaction.
853
- #
854
- # @param database [String]
855
- # Required. The database name. In the format:
856
- # `projects/{project_id}/databases/{database_id}`.
857
- # @param transaction [String]
858
- # Required. The transaction to roll back.
859
- # @param options [Google::Gax::CallOptions]
860
- # Overrides the default settings for this call, e.g, timeout,
861
- # retries, etc.
862
- # @yield [result, operation] Access the result along with the RPC operation
863
- # @yieldparam result []
864
- # @yieldparam operation [GRPC::ActiveCall::Operation]
865
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
866
- # @example
867
- # require "google/cloud/firestore/v1beta1"
868
- #
869
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
870
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
871
- #
872
- # # TODO: Initialize `transaction`:
873
- # transaction = ''
874
- # firestore_client.rollback(formatted_database, transaction)
875
-
876
- def rollback \
877
- database,
878
- transaction,
879
- options: nil,
880
- &block
881
- req = {
882
- database: database,
883
- transaction: transaction
884
- }.delete_if { |_, v| v.nil? }
885
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RollbackRequest)
886
- @rollback.call(req, options, &block)
887
- nil
888
- end
889
-
890
- # Runs a query.
891
- #
892
- # @param parent [String]
893
- # Required. The parent resource name. In the format:
894
- # `projects/{project_id}/databases/{database_id}/documents` or
895
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
896
- # For example:
897
- # `projects/my-project/databases/my-database/documents` or
898
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
899
- # @param structured_query [Google::Firestore::V1beta1::StructuredQuery | Hash]
900
- # A structured query.
901
- # A hash of the same form as `Google::Firestore::V1beta1::StructuredQuery`
902
- # can also be provided.
903
- # @param transaction [String]
904
- # Reads documents in a transaction.
905
- # @param new_transaction [Google::Firestore::V1beta1::TransactionOptions | Hash]
906
- # Starts a new transaction and reads the documents.
907
- # Defaults to a read-only transaction.
908
- # The new transaction ID will be returned as the first response in the
909
- # stream.
910
- # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
911
- # can also be provided.
912
- # @param read_time [Google::Protobuf::Timestamp | Hash]
913
- # Reads documents as they were at the given time.
914
- # This may not be older than 60 seconds.
915
- # A hash of the same form as `Google::Protobuf::Timestamp`
916
- # can also be provided.
917
- # @param options [Google::Gax::CallOptions]
918
- # Overrides the default settings for this call, e.g, timeout,
919
- # retries, etc.
920
- # @return [Enumerable<Google::Firestore::V1beta1::RunQueryResponse>]
921
- # An enumerable of Google::Firestore::V1beta1::RunQueryResponse instances.
922
- #
923
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
924
- # @example
925
- # require "google/cloud/firestore/v1beta1"
926
- #
927
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
928
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
929
- # firestore_client.run_query(formatted_parent).each do |element|
930
- # # Process element.
931
- # end
932
-
933
- def run_query \
934
- parent,
935
- structured_query: nil,
936
- transaction: nil,
937
- new_transaction: nil,
938
- read_time: nil,
939
- options: nil
940
- req = {
941
- parent: parent,
942
- structured_query: structured_query,
943
- transaction: transaction,
944
- new_transaction: new_transaction,
945
- read_time: read_time
946
- }.delete_if { |_, v| v.nil? }
947
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RunQueryRequest)
948
- @run_query.call(req, options)
949
- end
950
-
951
- # Streams batches of document updates and deletes, in order.
952
- #
953
- # @param reqs [Enumerable<Google::Firestore::V1beta1::WriteRequest>]
954
- # The input requests.
955
- # @param options [Google::Gax::CallOptions]
956
- # Overrides the default settings for this call, e.g, timeout,
957
- # retries, etc.
958
- # @return [Enumerable<Google::Firestore::V1beta1::WriteResponse>]
959
- # An enumerable of Google::Firestore::V1beta1::WriteResponse instances.
960
- #
961
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
962
- #
963
- # @note
964
- # EXPERIMENTAL:
965
- # Streaming requests are still undergoing review.
966
- # This method interface might change in the future.
967
- #
968
- # @example
969
- # require "google/cloud/firestore/v1beta1"
970
- #
971
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
972
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
973
- # request = { database: formatted_database }
974
- # requests = [request]
975
- # firestore_client.write(requests).each do |element|
976
- # # Process element.
977
- # end
978
-
979
- def write reqs, options: nil
980
- request_protos = reqs.lazy.map do |req|
981
- Google::Gax::to_proto(req, Google::Firestore::V1beta1::WriteRequest)
982
- end
983
- @write.call(request_protos, options)
984
- end
985
-
986
- # Listens to changes.
987
- #
988
- # @param reqs [Enumerable<Google::Firestore::V1beta1::ListenRequest>]
989
- # The input requests.
990
- # @param options [Google::Gax::CallOptions]
991
- # Overrides the default settings for this call, e.g, timeout,
992
- # retries, etc.
993
- # @return [Enumerable<Google::Firestore::V1beta1::ListenResponse>]
994
- # An enumerable of Google::Firestore::V1beta1::ListenResponse instances.
995
- #
996
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
997
- #
998
- # @note
999
- # EXPERIMENTAL:
1000
- # Streaming requests are still undergoing review.
1001
- # This method interface might change in the future.
1002
- #
1003
- # @example
1004
- # require "google/cloud/firestore/v1beta1"
1005
- #
1006
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
1007
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
1008
- # request = { database: formatted_database }
1009
- # requests = [request]
1010
- # firestore_client.listen(requests).each do |element|
1011
- # # Process element.
1012
- # end
1013
-
1014
- def listen reqs, options: nil
1015
- request_protos = reqs.lazy.map do |req|
1016
- Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListenRequest)
1017
- end
1018
- @listen.call(request_protos, options)
1019
- end
1020
-
1021
- # Lists all the collection IDs underneath a document.
1022
- #
1023
- # @param parent [String]
1024
- # Required. The parent document. In the format:
1025
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
1026
- # For example:
1027
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
1028
- # @param page_size [Integer]
1029
- # The maximum number of resources contained in the underlying API
1030
- # response. If page streaming is performed per-resource, this
1031
- # parameter does not affect the return value. If page streaming is
1032
- # performed per-page, this determines the maximum number of
1033
- # resources in a page.
1034
- # @param options [Google::Gax::CallOptions]
1035
- # Overrides the default settings for this call, e.g, timeout,
1036
- # retries, etc.
1037
- # @yield [result, operation] Access the result along with the RPC operation
1038
- # @yieldparam result [Google::Gax::PagedEnumerable<String>]
1039
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1040
- # @return [Google::Gax::PagedEnumerable<String>]
1041
- # An enumerable of String instances.
1042
- # See Google::Gax::PagedEnumerable documentation for other
1043
- # operations such as per-page iteration or access to the response
1044
- # object.
1045
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1046
- # @example
1047
- # require "google/cloud/firestore/v1beta1"
1048
- #
1049
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
1050
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
1051
- #
1052
- # # Iterate over all results.
1053
- # firestore_client.list_collection_ids(formatted_parent).each do |element|
1054
- # # Process element.
1055
- # end
1056
- #
1057
- # # Or iterate over results one page at a time.
1058
- # firestore_client.list_collection_ids(formatted_parent).each_page do |page|
1059
- # # Process each page at a time.
1060
- # page.each do |element|
1061
- # # Process element.
1062
- # end
1063
- # end
1064
-
1065
- def list_collection_ids \
1066
- parent,
1067
- page_size: nil,
1068
- options: nil,
1069
- &block
1070
- req = {
1071
- parent: parent,
1072
- page_size: page_size
1073
- }.delete_if { |_, v| v.nil? }
1074
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListCollectionIdsRequest)
1075
- @list_collection_ids.call(req, options, &block)
1076
- end
1077
- end
1078
- end
1079
- end
1080
- end
1081
- end