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