google-cloud-firestore 1.4.4 → 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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +23 -0
  4. data/lib/google-cloud-firestore.rb +14 -21
  5. data/lib/google/cloud/firestore.rb +12 -23
  6. data/lib/google/cloud/firestore/client.rb +12 -14
  7. data/lib/google/cloud/firestore/collection_reference.rb +1 -0
  8. data/lib/google/cloud/firestore/collection_reference_list.rb +137 -0
  9. data/lib/google/cloud/firestore/convert.rb +39 -39
  10. data/lib/google/cloud/firestore/credentials.rb +2 -2
  11. data/lib/google/cloud/firestore/document_reference.rb +8 -8
  12. data/lib/google/cloud/firestore/document_reference/list.rb +2 -2
  13. data/lib/google/cloud/firestore/document_snapshot.rb +4 -4
  14. data/lib/google/cloud/firestore/query.rb +4 -4
  15. data/lib/google/cloud/firestore/service.rb +63 -104
  16. data/lib/google/cloud/firestore/transaction.rb +2 -2
  17. data/lib/google/cloud/firestore/version.rb +1 -1
  18. data/lib/google/cloud/firestore/watch/listener.rb +9 -9
  19. data/lib/google/cloud/firestore/watch/order.rb +1 -1
  20. metadata +9 -107
  21. data/lib/google/cloud/firestore/admin.rb +0 -144
  22. data/lib/google/cloud/firestore/admin/v1.rb +0 -151
  23. data/lib/google/cloud/firestore/admin/v1/credentials.rb +0 -44
  24. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/field.rb +0 -86
  25. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/firestore_admin.rb +0 -161
  26. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/index.rb +0 -142
  27. data/lib/google/cloud/firestore/admin/v1/doc/google/longrunning/operations.rb +0 -51
  28. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/any.rb +0 -131
  29. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/empty.rb +0 -29
  30. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/field_mask.rb +0 -222
  31. data/lib/google/cloud/firestore/admin/v1/doc/google/rpc/status.rb +0 -39
  32. data/lib/google/cloud/firestore/admin/v1/firestore_admin_client.rb +0 -902
  33. data/lib/google/cloud/firestore/admin/v1/firestore_admin_client_config.json +0 -76
  34. data/lib/google/cloud/firestore/v1.rb +0 -152
  35. data/lib/google/cloud/firestore/v1/credentials.rb +0 -42
  36. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/common.rb +0 -64
  37. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/document.rb +0 -136
  38. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/firestore.rb +0 -566
  39. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/query.rb +0 -227
  40. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/write.rb +0 -241
  41. data/lib/google/cloud/firestore/v1/doc/google/protobuf/any.rb +0 -131
  42. data/lib/google/cloud/firestore/v1/doc/google/protobuf/empty.rb +0 -29
  43. data/lib/google/cloud/firestore/v1/doc/google/protobuf/timestamp.rb +0 -113
  44. data/lib/google/cloud/firestore/v1/doc/google/protobuf/wrappers.rb +0 -26
  45. data/lib/google/cloud/firestore/v1/doc/google/rpc/status.rb +0 -39
  46. data/lib/google/cloud/firestore/v1/firestore_client.rb +0 -1011
  47. data/lib/google/cloud/firestore/v1/firestore_client_config.json +0 -105
  48. data/lib/google/cloud/firestore/v1beta1.rb +0 -162
  49. data/lib/google/cloud/firestore/v1beta1/credentials.rb +0 -42
  50. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/common.rb +0 -64
  51. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/document.rb +0 -136
  52. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/firestore.rb +0 -564
  53. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/query.rb +0 -227
  54. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/write.rb +0 -237
  55. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/any.rb +0 -131
  56. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/empty.rb +0 -29
  57. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/timestamp.rb +0 -113
  58. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/wrappers.rb +0 -26
  59. data/lib/google/cloud/firestore/v1beta1/doc/google/rpc/status.rb +0 -39
  60. data/lib/google/cloud/firestore/v1beta1/firestore_client.rb +0 -1021
  61. data/lib/google/cloud/firestore/v1beta1/firestore_client_config.json +0 -100
  62. data/lib/google/firestore/admin/v1/field_pb.rb +0 -32
  63. data/lib/google/firestore/admin/v1/firestore_admin_pb.rb +0 -84
  64. data/lib/google/firestore/admin/v1/firestore_admin_services_pb.rb +0 -94
  65. data/lib/google/firestore/admin/v1/index_pb.rb +0 -58
  66. data/lib/google/firestore/admin/v1/location_pb.rb +0 -22
  67. data/lib/google/firestore/admin/v1/operation_pb.rb +0 -90
  68. data/lib/google/firestore/v1/common_pb.rb +0 -45
  69. data/lib/google/firestore/v1/document_pb.rb +0 -50
  70. data/lib/google/firestore/v1/firestore_pb.rb +0 -222
  71. data/lib/google/firestore/v1/firestore_services_pb.rb +0 -80
  72. data/lib/google/firestore/v1/query_pb.rb +0 -107
  73. data/lib/google/firestore/v1/write_pb.rb +0 -80
  74. data/lib/google/firestore/v1beta1/common_pb.rb +0 -45
  75. data/lib/google/firestore/v1beta1/document_pb.rb +0 -50
  76. data/lib/google/firestore/v1beta1/firestore_pb.rb +0 -222
  77. data/lib/google/firestore/v1beta1/firestore_services_pb.rb +0 -89
  78. data/lib/google/firestore/v1beta1/query_pb.rb +0 -107
  79. data/lib/google/firestore/v1beta1/write_pb.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 767d0de57b4cb69eb636c2dd85e95da99bab28356514daeae0cb29e87aac8989
4
- data.tar.gz: 9a2c8ebd59ef8694fcfe1cd78c027acca7442ae638c90b125dbde4f7adc4a8e0
3
+ metadata.gz: e83411cc86b2d8999f2ea7771cc243f032b9119c03885427aa57b007c3695406
4
+ data.tar.gz: 2ba1894414f95466c521ac6159dcfeedfb713727049171226a0eaecb2b041a71
5
5
  SHA512:
6
- metadata.gz: 93d63f0d8d61ff6c32c2b94b0d38e8b1a1deadfdbe3bd104558ffc6fa55f265701dc262fd4f1200ea9d1802d26f5e5f79cd9859452d6128d3b3e49e36eae044c
7
- data.tar.gz: d43a9f1f2e7b0aeb0dbfd56f10a41790036f29199d1dec6862f4e97e14fd057baf72ed66a1d414073e5a590cecfbdbb0182524f486e63e4951ffa8aa11d8dfd0
6
+ metadata.gz: ee5186f01ad3ec6adf7508a043793306c622f77b5a4552f91a787d52860e57e8e65c99561d8995cd7dd3a424801ac7e56b36174e6a9139179bed3ac708391966
7
+ data.tar.gz: 0c2037885a4d5b12151f346f181de0f632e6c2c399e095899cd9567ad484ac954463c757740c0306639473edf69115a1e8fc37e1914727cbef11d90241aaef9c
@@ -76,7 +76,7 @@ The environment variables that google-cloud-firestore checks for project ID are:
76
76
  1. `FIRESTORE_PROJECT`
77
77
  2. `GOOGLE_CLOUD_PROJECT`
78
78
 
79
- The environment variables that google-cloud-firestore checks for credentials are configured on {Google::Cloud::Firestore::V1::Credentials}:
79
+ The environment variables that google-cloud-firestore checks for credentials are configured on {Google::Cloud::Firestore::Credentials}:
80
80
 
81
81
  1. `FIRESTORE_CREDENTIALS` - Path to JSON file, or JSON contents
82
82
  2. `FIRESTORE_KEYFILE` - Path to JSON file, or JSON contents
@@ -1,5 +1,28 @@
1
1
  # Release History
2
2
 
3
+ ### 2.0.0 / 2020-08-06
4
+
5
+ This is a major update that removes the "low-level" client interface code, and
6
+ instead adds the new `google-cloud-firestore-v1` gem as a dependency.
7
+ The new dependency is a rewritten low-level client, produced by a next-
8
+ generation client code generator, with improved performance and stability.
9
+
10
+ This change should have no effect on the high-level interface that most users
11
+ will use. The one exception is that the (mostly undocumented) `client_config`
12
+ argument, for adjusting low-level parameters such as RPC retry settings on
13
+ client objects, has been removed. If you need to adjust these parameters, use
14
+ the configuration interface in `google-cloud-firestore-v1`.
15
+
16
+ Substantial changes have been made in the low-level interfaces, however. If you
17
+ are using the low-level classes under the `Google::Cloud::Firestore::V1` module,
18
+ please review the docs for the new `google-cloud-firestore-v1` gem. In
19
+ particular:
20
+
21
+ * Some classes have been renamed, notably the client class itself.
22
+ * The client constructor takes a configuration block instead of configuration
23
+ keyword arguments.
24
+ * All RPC method arguments are now keyword arguments.
25
+
3
26
  ### 1.4.4 / 2020-05-28
4
27
 
5
28
  #### Documentation
@@ -42,8 +42,6 @@ module Google
42
42
  #
43
43
  # * `https://www.googleapis.com/auth/datastore`
44
44
  # @param [Integer] timeout Default timeout to use in requests. Optional.
45
- # @param [Hash] client_config A hash of values to override the default
46
- # behavior of the API client. Optional.
47
45
  #
48
46
  # @return [Google::Cloud::Firestore::Client]
49
47
  #
@@ -60,10 +58,8 @@ module Google
60
58
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
61
59
  # firestore = gcloud.firestore scope: platform_scope
62
60
  #
63
- def firestore scope: nil, timeout: nil, client_config: nil
64
- Google::Cloud.firestore @project, @keyfile,
65
- scope: scope, timeout: (timeout || @timeout),
66
- client_config: client_config
61
+ def firestore scope: nil, timeout: nil
62
+ Google::Cloud.firestore @project, @keyfile, scope: scope, timeout: (timeout || @timeout)
67
63
  end
68
64
 
69
65
  ##
@@ -87,8 +83,6 @@ module Google
87
83
  #
88
84
  # * `https://www.googleapis.com/auth/datastore`
89
85
  # @param [Integer] timeout Default timeout to use in requests. Optional.
90
- # @param [Hash] client_config A hash of values to override the default
91
- # behavior of the API client. Optional.
92
86
  #
93
87
  # @return [Google::Cloud::Firestore::Client]
94
88
  #
@@ -97,13 +91,12 @@ module Google
97
91
  #
98
92
  # firestore = Google::Cloud.firestore
99
93
  #
100
- def self.firestore project_id = nil, credentials = nil, scope: nil,
101
- timeout: nil, client_config: nil
94
+ def self.firestore project_id = nil, credentials = nil, scope: nil, timeout: nil
102
95
  require "google/cloud/firestore"
103
- Google::Cloud::Firestore.new project_id: project_id,
96
+ Google::Cloud::Firestore.new project_id: project_id,
104
97
  credentials: credentials,
105
- scope: scope, timeout: timeout,
106
- client_config: client_config
98
+ scope: scope,
99
+ timeout: timeout
107
100
  end
108
101
  end
109
102
  end
@@ -122,17 +115,17 @@ Google::Cloud.configure.add_config! :firestore do |config|
122
115
  default_emulator = Google::Cloud::Config.deferred do
123
116
  ENV["FIRESTORE_EMULATOR_HOST"]
124
117
  end
118
+ default_scopes = [
119
+ "https://www.googleapis.com/auth/cloud-platform",
120
+ "https://www.googleapis.com/auth/datastore"
121
+ ]
125
122
 
126
123
  config.add_field! :project_id, default_project, match: String, allow_nil: true
127
124
  config.add_alias! :project, :project_id
128
- config.add_field! :credentials, default_creds,
129
- match: [String, Hash, Google::Auth::Credentials],
130
- allow_nil: true
125
+ config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
131
126
  config.add_alias! :keyfile, :credentials
132
- config.add_field! :scope, nil, match: [String, Array]
127
+ config.add_field! :scope, default_scopes, match: [String, Array]
133
128
  config.add_field! :timeout, nil, match: Integer
134
- config.add_field! :client_config, nil, match: Hash
135
- config.add_field! :emulator_host, default_emulator,
136
- match: String, allow_nil: true
137
- config.add_field! :endpoint, nil, match: String
129
+ config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
130
+ config.add_field! :endpoint, "firestore.googleapis.com", match: String
138
131
  end
@@ -33,7 +33,6 @@ module Google
33
33
  #
34
34
  module Firestore
35
35
  # rubocop:disable Metrics/AbcSize
36
- # rubocop:disable Metrics/MethodLength
37
36
 
38
37
  ##
39
38
  # Creates a new object for connecting to the Firestore service.
@@ -56,8 +55,6 @@ module Google
56
55
  #
57
56
  # * `https://www.googleapis.com/auth/datastore`
58
57
  # @param [Integer] timeout Default timeout to use in requests. Optional.
59
- # @param [Hash] client_config A hash of values to override the default
60
- # behavior of the API client. Optional.
61
58
  # @param [String] endpoint Override of the endpoint host name. Optional.
62
59
  # If the param is nil, uses the default endpoint.
63
60
  # @param [String] emulator_host Firestore emulator host. Optional.
@@ -73,13 +70,17 @@ module Google
73
70
  #
74
71
  # firestore = Google::Cloud::Firestore.new
75
72
  #
76
- def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
77
- client_config: nil, endpoint: nil, emulator_host: nil,
78
- project: nil, keyfile: nil
73
+ def self.new project_id: nil,
74
+ credentials: nil,
75
+ scope: nil,
76
+ timeout: nil,
77
+ endpoint: nil,
78
+ emulator_host: nil,
79
+ project: nil,
80
+ keyfile: nil
79
81
  project_id ||= (project || default_project_id)
80
82
  scope ||= configure.scope
81
83
  timeout ||= configure.timeout
82
- client_config ||= configure.client_config
83
84
  endpoint ||= configure.endpoint
84
85
  emulator_host ||= configure.emulator_host
85
86
 
@@ -87,13 +88,8 @@ module Google
87
88
  project_id = project_id.to_s
88
89
  raise ArgumentError, "project_id is missing" if project_id.empty?
89
90
 
90
- return Firestore::Client.new(
91
- Firestore::Service.new(
92
- project_id, :this_channel_is_insecure,
93
- host: emulator_host, timeout: timeout,
94
- client_config: client_config
95
- )
96
- )
91
+ service = Firestore::Service.new project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout
92
+ return Firestore::Client.new service
97
93
  end
98
94
 
99
95
  credentials ||= (keyfile || default_credentials(scope: scope))
@@ -107,16 +103,11 @@ module Google
107
103
  project_id = project_id.to_s
108
104
  raise ArgumentError, "project_id is missing" if project_id.empty?
109
105
 
110
- Firestore::Client.new(
111
- Firestore::Service.new(
112
- project_id, credentials,
113
- host: endpoint, timeout: timeout, client_config: client_config
114
- )
115
- )
106
+ service = Firestore::Service.new project_id, credentials, host: endpoint, timeout: timeout
107
+ Firestore::Client.new service
116
108
  end
117
109
 
118
110
  # rubocop:enable Metrics/AbcSize
119
- # rubocop:enable Metrics/MethodLength
120
111
 
121
112
  ##
122
113
  # Configure the Google Cloud Firestore library.
@@ -132,8 +123,6 @@ module Google
132
123
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
133
124
  # the set of resources and operations that the connection can access.
134
125
  # * `timeout` - (Integer) Default timeout to use in requests.
135
- # * `client_config` - (Hash) A hash of values to override the default
136
- # behavior of the API client.
137
126
  # * `endpoint` - (String) Override of the endpoint host name, or `nil`
138
127
  # to use the default endpoint.
139
128
  # * `emulator_host` - (String) Host name of the emulator. Defaults to
@@ -82,12 +82,13 @@ module Google
82
82
  # @!group Access
83
83
 
84
84
  ##
85
- # Retrieves a list of collections.
85
+ # Retrieves an enumerator for the root collections.
86
86
  #
87
87
  # @yield [collections] The block for accessing the collections.
88
- # @yieldparam [CollectionReference] collection A collection.
88
+ # @yieldparam [CollectionReference] collection A collection reference object.
89
89
  #
90
- # @return [Enumerator<CollectionReference>] collection list.
90
+ # @return [Enumerator<CollectionReference>] An enumerator of collection references. If a block is provided,
91
+ # this is the same enumerator that is accessed through the block.
91
92
  #
92
93
  # @example
93
94
  # require "google/cloud/firestore"
@@ -101,11 +102,10 @@ module Google
101
102
  #
102
103
  def cols
103
104
  ensure_service!
104
-
105
- return enum_for :cols unless block_given?
106
-
107
- collection_ids = service.list_collections "#{path}/documents"
108
- collection_ids.each { |collection_id| yield col collection_id }
105
+ grpc = service.list_collections "#{path}/documents"
106
+ cols_enum = CollectionReferenceList.from_grpc(grpc, self, "#{path}/documents").all
107
+ cols_enum.each { |c| yield c } if block_given?
108
+ cols_enum
109
109
  end
110
110
  alias collections cols
111
111
  alias list_collections cols
@@ -134,8 +134,7 @@ module Google
134
134
  raise ArgumentError, "collection_path must refer to a collection."
135
135
  end
136
136
 
137
- CollectionReference.from_path \
138
- "#{path}/documents/#{collection_path}", self
137
+ CollectionReference.from_path "#{path}/documents/#{collection_path}", self
139
138
  end
140
139
  alias collection col
141
140
 
@@ -167,9 +166,9 @@ module Google
167
166
  raise ArgumentError, "Invalid collection_id: '#{collection_id}', " \
168
167
  "must not contain '/'."
169
168
  end
170
- query = Google::Firestore::V1::StructuredQuery.new(
169
+ query = Google::Cloud::Firestore::V1::StructuredQuery.new(
171
170
  from: [
172
- Google::Firestore::V1::StructuredQuery::CollectionSelector.new(
171
+ Google::Cloud::Firestore::V1::StructuredQuery::CollectionSelector.new(
173
172
  collection_id: collection_id, all_descendants: true
174
173
  )
175
174
  ]
@@ -670,8 +669,7 @@ module Google
670
669
  # @private
671
670
  def list_documents parent, collection_id, token: nil, max: nil
672
671
  ensure_service!
673
- grpc = service.list_documents \
674
- parent, collection_id, token: token, max: max
672
+ grpc = service.list_documents parent, collection_id, token: token, max: max
675
673
  DocumentReference::List.from_grpc grpc, self, parent, collection_id
676
674
  end
677
675
 
@@ -18,6 +18,7 @@ require "google/cloud/firestore/document_reference"
18
18
  require "google/cloud/firestore/document_snapshot"
19
19
  require "google/cloud/firestore/query"
20
20
  require "google/cloud/firestore/generate"
21
+ require "google/cloud/firestore/collection_reference_list"
21
22
 
22
23
  module Google
23
24
  module Cloud
@@ -0,0 +1,137 @@
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
+ require "delegate"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Firestore
21
+ ##
22
+ # @private
23
+ #
24
+ # An Array delegate for pagination. Private class exposing only an Enumerator to clients.
25
+ #
26
+ class CollectionReferenceList < DelegateClass(::Array)
27
+ ##
28
+ # If not empty, indicates that there are more records that match the request and this value should be passed
29
+ # to continue.
30
+ attr_accessor :token
31
+
32
+ ##
33
+ # @private Create a new CollectionReference::List with an array of CollectionReference instances.
34
+ def initialize arr = []
35
+ super arr
36
+ end
37
+
38
+ ##
39
+ # Whether there is a next page of collection references.
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def next?
44
+ !token.nil?
45
+ end
46
+
47
+ ##
48
+ # Retrieve the next page of collection references.
49
+ #
50
+ # @return [CollectionReference::List] The list of collection references.
51
+ #
52
+ def next
53
+ return nil unless next?
54
+ ensure_service!
55
+ grpc = @client.service.list_collections @parent, token: token, max: @max
56
+ self.class.from_grpc grpc, @client, @parent, max: @max
57
+ end
58
+
59
+ ##
60
+ # Retrieves remaining results by repeatedly invoking {#next} until {#next?} returns `false`. Calls the given
61
+ # block once for each result, which is passed as the argument to the block.
62
+ #
63
+ # An Enumerator is returned if no block is given.
64
+ #
65
+ # This method will make repeated API calls until all remaining results are retrieved. (Unlike `#each`, for
66
+ # example, which merely iterates over the results returned by a single API call.) Use with caution.
67
+ #
68
+ # @param [Integer] request_limit The upper limit of API requests to make to load all collection references.
69
+ # Default is no limit.
70
+ # @yield [collection_reference] The block for accessing each collection_reference.
71
+ # @yieldparam [CollectionReference] collection_reference The collection reference object.
72
+ #
73
+ # @return [Enumerator]
74
+ #
75
+ # @example Iterating each collection reference by passing a block:
76
+ # require "google/cloud/firestore"
77
+ #
78
+ # firestore = Google::Cloud::Firestore.new
79
+ #
80
+ # firestore.cols do |collection_reference|
81
+ # puts collection_reference.collection_id
82
+ # end
83
+ #
84
+ # @example Using the enumerator by not passing a block:
85
+ # require "google/cloud/firestore"
86
+ #
87
+ # firestore = Google::Cloud::Firestore.new
88
+ #
89
+ # all_collection_ids = firestore.cols.map do |collection_reference|
90
+ # collection_reference.collection_id
91
+ # end
92
+ #
93
+ def all request_limit: nil
94
+ request_limit = request_limit.to_i if request_limit
95
+ unless block_given?
96
+ return enum_for :all, request_limit: request_limit
97
+ end
98
+ results = self
99
+ loop do
100
+ results.each { |r| yield r }
101
+ if request_limit
102
+ request_limit -= 1
103
+ break if request_limit < 0
104
+ end
105
+ break unless results.next?
106
+ results = results.next
107
+ end
108
+ end
109
+
110
+ ##
111
+ # @private New CollectionReference::List from a `Google::Cloud::Firestore::V1::ListCollectionIdsResponse`
112
+ # object.
113
+ def self.from_grpc grpc, client, parent, max: nil
114
+ raise ArgumentError, "parent is required" unless parent
115
+ cols = CollectionReferenceList.new(Array(grpc.collection_ids).map do |collection_id|
116
+ CollectionReference.from_path "#{parent}/#{collection_id}", client
117
+ end)
118
+ token = grpc.next_page_token
119
+ token = nil if token == ""
120
+ cols.instance_variable_set :@token, token
121
+ cols.instance_variable_set :@client, client
122
+ cols.instance_variable_set :@parent, parent
123
+ cols.instance_variable_set :@max, max
124
+ cols
125
+ end
126
+
127
+ protected
128
+
129
+ ##
130
+ # Raise an error unless an active service is available.
131
+ def ensure_service!
132
+ raise "Must have active connection" unless @client.service
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -85,40 +85,40 @@ module Google
85
85
 
86
86
  def raw_to_value obj
87
87
  if NilClass === obj
88
- Google::Firestore::V1::Value.new null_value: :NULL_VALUE
88
+ Google::Cloud::Firestore::V1::Value.new null_value: :NULL_VALUE
89
89
  elsif TrueClass === obj || FalseClass === obj
90
- Google::Firestore::V1::Value.new boolean_value: obj
90
+ Google::Cloud::Firestore::V1::Value.new boolean_value: obj
91
91
  elsif Integer === obj
92
- Google::Firestore::V1::Value.new integer_value: obj
92
+ Google::Cloud::Firestore::V1::Value.new integer_value: obj
93
93
  elsif Numeric === obj # Any number not an integer is a double
94
- Google::Firestore::V1::Value.new double_value: obj.to_f
94
+ Google::Cloud::Firestore::V1::Value.new double_value: obj.to_f
95
95
  elsif Time === obj || DateTime === obj || Date === obj
96
- Google::Firestore::V1::Value.new \
96
+ Google::Cloud::Firestore::V1::Value.new \
97
97
  timestamp_value: time_to_timestamp(obj.to_time)
98
98
  elsif String === obj || Symbol === obj
99
- Google::Firestore::V1::Value.new string_value: obj.to_s
99
+ Google::Cloud::Firestore::V1::Value.new string_value: obj.to_s
100
100
  elsif Google::Cloud::Firestore::DocumentReference === obj
101
- Google::Firestore::V1::Value.new reference_value: obj.path
101
+ Google::Cloud::Firestore::V1::Value.new reference_value: obj.path
102
102
  elsif Array === obj
103
103
  values = obj.map { |o| raw_to_value(o) }
104
- Google::Firestore::V1::Value.new(array_value:
105
- Google::Firestore::V1::ArrayValue.new(values: values))
104
+ Google::Cloud::Firestore::V1::Value.new(array_value:
105
+ Google::Cloud::Firestore::V1::ArrayValue.new(values: values))
106
106
  elsif Hash === obj
107
107
  # keys have been changed to strings before the hash gets here
108
108
  geo_pairs = hash_is_geo_point? obj
109
109
  if geo_pairs
110
- Google::Firestore::V1::Value.new(
110
+ Google::Cloud::Firestore::V1::Value.new(
111
111
  geo_point_value: hash_to_geo_point(obj, geo_pairs)
112
112
  )
113
113
  else
114
114
  fields = hash_to_fields obj
115
- Google::Firestore::V1::Value.new(map_value:
116
- Google::Firestore::V1::MapValue.new(fields: fields))
115
+ Google::Cloud::Firestore::V1::Value.new(map_value:
116
+ Google::Cloud::Firestore::V1::MapValue.new(fields: fields))
117
117
  end
118
118
  elsif obj.respond_to?(:read) && obj.respond_to?(:rewind)
119
119
  obj.rewind
120
120
  content = obj.read.force_encoding "ASCII-8BIT"
121
- Google::Firestore::V1::Value.new bytes_value: content
121
+ Google::Cloud::Firestore::V1::Value.new bytes_value: content
122
122
  else
123
123
  raise ArgumentError,
124
124
  "A value of type #{obj.class} is not supported."
@@ -129,7 +129,7 @@ module Google
129
129
  return false unless hash.keys.count == 2
130
130
 
131
131
  pairs = hash.map { |k, v| [String(k), v] }.sort
132
- if pairs.map(&:first) == ["latitude".freeze, "longitude".freeze]
132
+ if pairs.map(&:first) == ["latitude", "longitude"]
133
133
  pairs
134
134
  end
135
135
  end
@@ -156,11 +156,11 @@ module Google
156
156
  data, field_paths_and_values = remove_field_value_from data
157
157
 
158
158
  if data.any? || field_paths_and_values.empty?
159
- write = Google::Firestore::V1::Write.new(
160
- update: Google::Firestore::V1::Document.new(
159
+ write = Google::Cloud::Firestore::V1::Write.new(
160
+ update: Google::Cloud::Firestore::V1::Document.new(
161
161
  name: doc_path,
162
162
  fields: hash_to_fields(data)),
163
- current_document: Google::Firestore::V1::Precondition.new(
163
+ current_document: Google::Cloud::Firestore::V1::Precondition.new(
164
164
  exists: false)
165
165
  )
166
166
  writes << write
@@ -171,7 +171,7 @@ module Google
171
171
 
172
172
  if data.empty?
173
173
  transform_write.current_document = \
174
- Google::Firestore::V1::Precondition.new(exists: false)
174
+ Google::Cloud::Firestore::V1::Precondition.new(exists: false)
175
175
  end
176
176
 
177
177
  writes << transform_write
@@ -207,8 +207,8 @@ module Google
207
207
 
208
208
  data, field_paths_and_values = remove_field_value_from data
209
209
 
210
- writes << Google::Firestore::V1::Write.new(
211
- update: Google::Firestore::V1::Document.new(
210
+ writes << Google::Cloud::Firestore::V1::Write.new(
211
+ update: Google::Cloud::Firestore::V1::Document.new(
212
212
  name: doc_path,
213
213
  fields: hash_to_fields(data))
214
214
  )
@@ -278,11 +278,11 @@ module Google
278
278
  end
279
279
 
280
280
  if data.any? || field_paths.any? || (allow_empty && field_paths_and_values.empty?)
281
- writes << Google::Firestore::V1::Write.new(
282
- update: Google::Firestore::V1::Document.new(
281
+ writes << Google::Cloud::Firestore::V1::Write.new(
282
+ update: Google::Cloud::Firestore::V1::Document.new(
283
283
  name: doc_path,
284
284
  fields: hash_to_fields(data)),
285
- update_mask: Google::Firestore::V1::DocumentMask.new(
285
+ update_mask: Google::Cloud::Firestore::V1::DocumentMask.new(
286
286
  field_paths: field_paths.map(&:formatted_string).sort)
287
287
  )
288
288
  end
@@ -339,18 +339,18 @@ module Google
339
339
  end
340
340
 
341
341
  if data.any? || delete_paths.any?
342
- write = Google::Firestore::V1::Write.new(
343
- update: Google::Firestore::V1::Document.new(
342
+ write = Google::Cloud::Firestore::V1::Write.new(
343
+ update: Google::Cloud::Firestore::V1::Document.new(
344
344
  name: doc_path,
345
345
  fields: hash_to_fields(data)),
346
- update_mask: Google::Firestore::V1::DocumentMask.new(
346
+ update_mask: Google::Cloud::Firestore::V1::DocumentMask.new(
347
347
  field_paths: (field_paths).map(&:formatted_string).sort),
348
- current_document: Google::Firestore::V1::Precondition.new(
348
+ current_document: Google::Cloud::Firestore::V1::Precondition.new(
349
349
  exists: true)
350
350
  )
351
351
  if update_time
352
352
  write.current_document = \
353
- Google::Firestore::V1::Precondition.new(
353
+ Google::Cloud::Firestore::V1::Precondition.new(
354
354
  update_time: time_to_timestamp(update_time))
355
355
  end
356
356
  writes << write
@@ -360,7 +360,7 @@ module Google
360
360
  transform_write = transform_write doc_path, field_paths_and_values
361
361
  if data.empty?
362
362
  transform_write.current_document = \
363
- Google::Firestore::V1::Precondition.new(exists: true)
363
+ Google::Cloud::Firestore::V1::Precondition.new(exists: true)
364
364
  end
365
365
  writes << transform_write
366
366
  end
@@ -373,13 +373,13 @@ module Google
373
373
  raise ArgumentError, "cannot specify both exists and update_time"
374
374
  end
375
375
 
376
- write = Google::Firestore::V1::Write.new(
376
+ write = Google::Cloud::Firestore::V1::Write.new(
377
377
  delete: doc_path
378
378
  )
379
379
 
380
380
  unless exists.nil? && update_time.nil?
381
381
  write.current_document = \
382
- Google::Firestore::V1::Precondition.new({
382
+ Google::Cloud::Firestore::V1::Precondition.new({
383
383
  exists: exists, update_time: time_to_timestamp(update_time)
384
384
  }.delete_if { |_, v| v.nil? })
385
385
  end
@@ -584,8 +584,8 @@ module Google
584
584
  to_field_transform field_path, field_value
585
585
  end
586
586
 
587
- Google::Firestore::V1::Write.new(
588
- transform: Google::Firestore::V1::DocumentTransform.new(
587
+ Google::Cloud::Firestore::V1::Write.new(
588
+ transform: Google::Cloud::Firestore::V1::DocumentTransform.new(
589
589
  document: doc_path,
590
590
  field_transforms: field_transforms
591
591
  )
@@ -594,32 +594,32 @@ module Google
594
594
 
595
595
  def to_field_transform field_path, field_value
596
596
  if field_value.type == :server_time
597
- Google::Firestore::V1::DocumentTransform::FieldTransform.new(
597
+ Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
598
598
  field_path: field_path.formatted_string,
599
599
  set_to_server_value: :REQUEST_TIME
600
600
  )
601
601
  elsif field_value.type == :array_union
602
- Google::Firestore::V1::DocumentTransform::FieldTransform.new(
602
+ Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
603
603
  field_path: field_path.formatted_string,
604
604
  append_missing_elements: raw_to_value(Array(field_value.value)).array_value
605
605
  )
606
606
  elsif field_value.type == :array_delete
607
- Google::Firestore::V1::DocumentTransform::FieldTransform.new(
607
+ Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
608
608
  field_path: field_path.formatted_string,
609
609
  remove_all_from_array: raw_to_value(Array(field_value.value)).array_value
610
610
  )
611
611
  elsif field_value.type == :increment
612
- Google::Firestore::V1::DocumentTransform::FieldTransform.new(
612
+ Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
613
613
  field_path: field_path.formatted_string,
614
614
  increment: raw_to_value(field_value.value)
615
615
  )
616
616
  elsif field_value.type == :maximum
617
- Google::Firestore::V1::DocumentTransform::FieldTransform.new(
617
+ Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
618
618
  field_path: field_path.formatted_string,
619
619
  maximum: raw_to_value(field_value.value)
620
620
  )
621
621
  elsif field_value.type == :minimum
622
- Google::Firestore::V1::DocumentTransform::FieldTransform.new(
622
+ Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
623
623
  field_path: field_path.formatted_string,
624
624
  minimum: raw_to_value(field_value.value)
625
625
  )