Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/services/firestore/transports/rest.py: 34%

629 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-09 06:27 +0000

1# -*- coding: utf-8 -*- 

2# Copyright 2023 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16 

17from google.auth.transport.requests import AuthorizedSession # type: ignore 

18import json # type: ignore 

19import grpc # type: ignore 

20from google.auth.transport.grpc import SslCredentials # type: ignore 

21from google.auth import credentials as ga_credentials # type: ignore 

22from google.api_core import exceptions as core_exceptions 

23from google.api_core import retry as retries 

24from google.api_core import rest_helpers 

25from google.api_core import rest_streaming 

26from google.api_core import path_template 

27from google.api_core import gapic_v1 

28 

29from google.protobuf import json_format 

30from google.cloud.location import locations_pb2 # type: ignore 

31from requests import __version__ as requests_version 

32import dataclasses 

33import re 

34from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union 

35import warnings 

36 

37try: 

38 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] 

39except AttributeError: # pragma: NO COVER 

40 OptionalRetry = Union[retries.Retry, object] # type: ignore 

41 

42 

43from google.cloud.firestore_v1.types import document 

44from google.cloud.firestore_v1.types import document as gf_document 

45from google.cloud.firestore_v1.types import firestore 

46from google.protobuf import empty_pb2 # type: ignore 

47from google.longrunning import operations_pb2 # type: ignore 

48 

49from .base import FirestoreTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

50 

51 

52DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

53 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

54 grpc_version=None, 

55 rest_version=requests_version, 

56) 

57 

58 

59class FirestoreRestInterceptor: 

60 """Interceptor for Firestore. 

61 

62 Interceptors are used to manipulate requests, request metadata, and responses 

63 in arbitrary ways. 

64 Example use cases include: 

65 * Logging 

66 * Verifying requests according to service or custom semantics 

67 * Stripping extraneous information from responses 

68 

69 These use cases and more can be enabled by injecting an 

70 instance of a custom subclass when constructing the FirestoreRestTransport. 

71 

72 .. code-block:: python 

73 class MyCustomFirestoreInterceptor(FirestoreRestInterceptor): 

74 def pre_batch_get_documents(self, request, metadata): 

75 logging.log(f"Received request: {request}") 

76 return request, metadata 

77 

78 def post_batch_get_documents(self, response): 

79 logging.log(f"Received response: {response}") 

80 return response 

81 

82 def pre_batch_write(self, request, metadata): 

83 logging.log(f"Received request: {request}") 

84 return request, metadata 

85 

86 def post_batch_write(self, response): 

87 logging.log(f"Received response: {response}") 

88 return response 

89 

90 def pre_begin_transaction(self, request, metadata): 

91 logging.log(f"Received request: {request}") 

92 return request, metadata 

93 

94 def post_begin_transaction(self, response): 

95 logging.log(f"Received response: {response}") 

96 return response 

97 

98 def pre_commit(self, request, metadata): 

99 logging.log(f"Received request: {request}") 

100 return request, metadata 

101 

102 def post_commit(self, response): 

103 logging.log(f"Received response: {response}") 

104 return response 

105 

106 def pre_create_document(self, request, metadata): 

107 logging.log(f"Received request: {request}") 

108 return request, metadata 

109 

110 def post_create_document(self, response): 

111 logging.log(f"Received response: {response}") 

112 return response 

113 

114 def pre_delete_document(self, request, metadata): 

115 logging.log(f"Received request: {request}") 

116 return request, metadata 

117 

118 def pre_get_document(self, request, metadata): 

119 logging.log(f"Received request: {request}") 

120 return request, metadata 

121 

122 def post_get_document(self, response): 

123 logging.log(f"Received response: {response}") 

124 return response 

125 

126 def pre_list_collection_ids(self, request, metadata): 

127 logging.log(f"Received request: {request}") 

128 return request, metadata 

129 

130 def post_list_collection_ids(self, response): 

131 logging.log(f"Received response: {response}") 

132 return response 

133 

134 def pre_list_documents(self, request, metadata): 

135 logging.log(f"Received request: {request}") 

136 return request, metadata 

137 

138 def post_list_documents(self, response): 

139 logging.log(f"Received response: {response}") 

140 return response 

141 

142 def pre_partition_query(self, request, metadata): 

143 logging.log(f"Received request: {request}") 

144 return request, metadata 

145 

146 def post_partition_query(self, response): 

147 logging.log(f"Received response: {response}") 

148 return response 

149 

150 def pre_rollback(self, request, metadata): 

151 logging.log(f"Received request: {request}") 

152 return request, metadata 

153 

154 def pre_run_aggregation_query(self, request, metadata): 

155 logging.log(f"Received request: {request}") 

156 return request, metadata 

157 

158 def post_run_aggregation_query(self, response): 

159 logging.log(f"Received response: {response}") 

160 return response 

161 

162 def pre_run_query(self, request, metadata): 

163 logging.log(f"Received request: {request}") 

164 return request, metadata 

165 

166 def post_run_query(self, response): 

167 logging.log(f"Received response: {response}") 

168 return response 

169 

170 def pre_update_document(self, request, metadata): 

171 logging.log(f"Received request: {request}") 

172 return request, metadata 

173 

174 def post_update_document(self, response): 

175 logging.log(f"Received response: {response}") 

176 return response 

177 

178 transport = FirestoreRestTransport(interceptor=MyCustomFirestoreInterceptor()) 

179 client = FirestoreClient(transport=transport) 

180 

181 

182 """ 

183 

184 def pre_batch_get_documents( 

185 self, 

186 request: firestore.BatchGetDocumentsRequest, 

187 metadata: Sequence[Tuple[str, str]], 

188 ) -> Tuple[firestore.BatchGetDocumentsRequest, Sequence[Tuple[str, str]]]: 

189 """Pre-rpc interceptor for batch_get_documents 

190 

191 Override in a subclass to manipulate the request or metadata 

192 before they are sent to the Firestore server. 

193 """ 

194 return request, metadata 

195 

196 def post_batch_get_documents( 

197 self, response: rest_streaming.ResponseIterator 

198 ) -> rest_streaming.ResponseIterator: 

199 """Post-rpc interceptor for batch_get_documents 

200 

201 Override in a subclass to manipulate the response 

202 after it is returned by the Firestore server but before 

203 it is returned to user code. 

204 """ 

205 return response 

206 

207 def pre_batch_write( 

208 self, request: firestore.BatchWriteRequest, metadata: Sequence[Tuple[str, str]] 

209 ) -> Tuple[firestore.BatchWriteRequest, Sequence[Tuple[str, str]]]: 

210 """Pre-rpc interceptor for batch_write 

211 

212 Override in a subclass to manipulate the request or metadata 

213 before they are sent to the Firestore server. 

214 """ 

215 return request, metadata 

216 

217 def post_batch_write( 

218 self, response: firestore.BatchWriteResponse 

219 ) -> firestore.BatchWriteResponse: 

220 """Post-rpc interceptor for batch_write 

221 

222 Override in a subclass to manipulate the response 

223 after it is returned by the Firestore server but before 

224 it is returned to user code. 

225 """ 

226 return response 

227 

228 def pre_begin_transaction( 

229 self, 

230 request: firestore.BeginTransactionRequest, 

231 metadata: Sequence[Tuple[str, str]], 

232 ) -> Tuple[firestore.BeginTransactionRequest, Sequence[Tuple[str, str]]]: 

233 """Pre-rpc interceptor for begin_transaction 

234 

235 Override in a subclass to manipulate the request or metadata 

236 before they are sent to the Firestore server. 

237 """ 

238 return request, metadata 

239 

240 def post_begin_transaction( 

241 self, response: firestore.BeginTransactionResponse 

242 ) -> firestore.BeginTransactionResponse: 

243 """Post-rpc interceptor for begin_transaction 

244 

245 Override in a subclass to manipulate the response 

246 after it is returned by the Firestore server but before 

247 it is returned to user code. 

248 """ 

249 return response 

250 

251 def pre_commit( 

252 self, request: firestore.CommitRequest, metadata: Sequence[Tuple[str, str]] 

253 ) -> Tuple[firestore.CommitRequest, Sequence[Tuple[str, str]]]: 

254 """Pre-rpc interceptor for commit 

255 

256 Override in a subclass to manipulate the request or metadata 

257 before they are sent to the Firestore server. 

258 """ 

259 return request, metadata 

260 

261 def post_commit( 

262 self, response: firestore.CommitResponse 

263 ) -> firestore.CommitResponse: 

264 """Post-rpc interceptor for commit 

265 

266 Override in a subclass to manipulate the response 

267 after it is returned by the Firestore server but before 

268 it is returned to user code. 

269 """ 

270 return response 

271 

272 def pre_create_document( 

273 self, 

274 request: firestore.CreateDocumentRequest, 

275 metadata: Sequence[Tuple[str, str]], 

276 ) -> Tuple[firestore.CreateDocumentRequest, Sequence[Tuple[str, str]]]: 

277 """Pre-rpc interceptor for create_document 

278 

279 Override in a subclass to manipulate the request or metadata 

280 before they are sent to the Firestore server. 

281 """ 

282 return request, metadata 

283 

284 def post_create_document(self, response: document.Document) -> document.Document: 

285 """Post-rpc interceptor for create_document 

286 

287 Override in a subclass to manipulate the response 

288 after it is returned by the Firestore server but before 

289 it is returned to user code. 

290 """ 

291 return response 

292 

293 def pre_delete_document( 

294 self, 

295 request: firestore.DeleteDocumentRequest, 

296 metadata: Sequence[Tuple[str, str]], 

297 ) -> Tuple[firestore.DeleteDocumentRequest, Sequence[Tuple[str, str]]]: 

298 """Pre-rpc interceptor for delete_document 

299 

300 Override in a subclass to manipulate the request or metadata 

301 before they are sent to the Firestore server. 

302 """ 

303 return request, metadata 

304 

305 def pre_get_document( 

306 self, request: firestore.GetDocumentRequest, metadata: Sequence[Tuple[str, str]] 

307 ) -> Tuple[firestore.GetDocumentRequest, Sequence[Tuple[str, str]]]: 

308 """Pre-rpc interceptor for get_document 

309 

310 Override in a subclass to manipulate the request or metadata 

311 before they are sent to the Firestore server. 

312 """ 

313 return request, metadata 

314 

315 def post_get_document(self, response: document.Document) -> document.Document: 

316 """Post-rpc interceptor for get_document 

317 

318 Override in a subclass to manipulate the response 

319 after it is returned by the Firestore server but before 

320 it is returned to user code. 

321 """ 

322 return response 

323 

324 def pre_list_collection_ids( 

325 self, 

326 request: firestore.ListCollectionIdsRequest, 

327 metadata: Sequence[Tuple[str, str]], 

328 ) -> Tuple[firestore.ListCollectionIdsRequest, Sequence[Tuple[str, str]]]: 

329 """Pre-rpc interceptor for list_collection_ids 

330 

331 Override in a subclass to manipulate the request or metadata 

332 before they are sent to the Firestore server. 

333 """ 

334 return request, metadata 

335 

336 def post_list_collection_ids( 

337 self, response: firestore.ListCollectionIdsResponse 

338 ) -> firestore.ListCollectionIdsResponse: 

339 """Post-rpc interceptor for list_collection_ids 

340 

341 Override in a subclass to manipulate the response 

342 after it is returned by the Firestore server but before 

343 it is returned to user code. 

344 """ 

345 return response 

346 

347 def pre_list_documents( 

348 self, 

349 request: firestore.ListDocumentsRequest, 

350 metadata: Sequence[Tuple[str, str]], 

351 ) -> Tuple[firestore.ListDocumentsRequest, Sequence[Tuple[str, str]]]: 

352 """Pre-rpc interceptor for list_documents 

353 

354 Override in a subclass to manipulate the request or metadata 

355 before they are sent to the Firestore server. 

356 """ 

357 return request, metadata 

358 

359 def post_list_documents( 

360 self, response: firestore.ListDocumentsResponse 

361 ) -> firestore.ListDocumentsResponse: 

362 """Post-rpc interceptor for list_documents 

363 

364 Override in a subclass to manipulate the response 

365 after it is returned by the Firestore server but before 

366 it is returned to user code. 

367 """ 

368 return response 

369 

370 def pre_partition_query( 

371 self, 

372 request: firestore.PartitionQueryRequest, 

373 metadata: Sequence[Tuple[str, str]], 

374 ) -> Tuple[firestore.PartitionQueryRequest, Sequence[Tuple[str, str]]]: 

375 """Pre-rpc interceptor for partition_query 

376 

377 Override in a subclass to manipulate the request or metadata 

378 before they are sent to the Firestore server. 

379 """ 

380 return request, metadata 

381 

382 def post_partition_query( 

383 self, response: firestore.PartitionQueryResponse 

384 ) -> firestore.PartitionQueryResponse: 

385 """Post-rpc interceptor for partition_query 

386 

387 Override in a subclass to manipulate the response 

388 after it is returned by the Firestore server but before 

389 it is returned to user code. 

390 """ 

391 return response 

392 

393 def pre_rollback( 

394 self, request: firestore.RollbackRequest, metadata: Sequence[Tuple[str, str]] 

395 ) -> Tuple[firestore.RollbackRequest, Sequence[Tuple[str, str]]]: 

396 """Pre-rpc interceptor for rollback 

397 

398 Override in a subclass to manipulate the request or metadata 

399 before they are sent to the Firestore server. 

400 """ 

401 return request, metadata 

402 

403 def pre_run_aggregation_query( 

404 self, 

405 request: firestore.RunAggregationQueryRequest, 

406 metadata: Sequence[Tuple[str, str]], 

407 ) -> Tuple[firestore.RunAggregationQueryRequest, Sequence[Tuple[str, str]]]: 

408 """Pre-rpc interceptor for run_aggregation_query 

409 

410 Override in a subclass to manipulate the request or metadata 

411 before they are sent to the Firestore server. 

412 """ 

413 return request, metadata 

414 

415 def post_run_aggregation_query( 

416 self, response: rest_streaming.ResponseIterator 

417 ) -> rest_streaming.ResponseIterator: 

418 """Post-rpc interceptor for run_aggregation_query 

419 

420 Override in a subclass to manipulate the response 

421 after it is returned by the Firestore server but before 

422 it is returned to user code. 

423 """ 

424 return response 

425 

426 def pre_run_query( 

427 self, request: firestore.RunQueryRequest, metadata: Sequence[Tuple[str, str]] 

428 ) -> Tuple[firestore.RunQueryRequest, Sequence[Tuple[str, str]]]: 

429 """Pre-rpc interceptor for run_query 

430 

431 Override in a subclass to manipulate the request or metadata 

432 before they are sent to the Firestore server. 

433 """ 

434 return request, metadata 

435 

436 def post_run_query( 

437 self, response: rest_streaming.ResponseIterator 

438 ) -> rest_streaming.ResponseIterator: 

439 """Post-rpc interceptor for run_query 

440 

441 Override in a subclass to manipulate the response 

442 after it is returned by the Firestore server but before 

443 it is returned to user code. 

444 """ 

445 return response 

446 

447 def pre_update_document( 

448 self, 

449 request: firestore.UpdateDocumentRequest, 

450 metadata: Sequence[Tuple[str, str]], 

451 ) -> Tuple[firestore.UpdateDocumentRequest, Sequence[Tuple[str, str]]]: 

452 """Pre-rpc interceptor for update_document 

453 

454 Override in a subclass to manipulate the request or metadata 

455 before they are sent to the Firestore server. 

456 """ 

457 return request, metadata 

458 

459 def post_update_document( 

460 self, response: gf_document.Document 

461 ) -> gf_document.Document: 

462 """Post-rpc interceptor for update_document 

463 

464 Override in a subclass to manipulate the response 

465 after it is returned by the Firestore server but before 

466 it is returned to user code. 

467 """ 

468 return response 

469 

470 def pre_cancel_operation( 

471 self, 

472 request: operations_pb2.CancelOperationRequest, 

473 metadata: Sequence[Tuple[str, str]], 

474 ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: 

475 """Pre-rpc interceptor for cancel_operation 

476 

477 Override in a subclass to manipulate the request or metadata 

478 before they are sent to the Firestore server. 

479 """ 

480 return request, metadata 

481 

482 def post_cancel_operation(self, response: None) -> None: 

483 """Post-rpc interceptor for cancel_operation 

484 

485 Override in a subclass to manipulate the response 

486 after it is returned by the Firestore server but before 

487 it is returned to user code. 

488 """ 

489 return response 

490 

491 def pre_delete_operation( 

492 self, 

493 request: operations_pb2.DeleteOperationRequest, 

494 metadata: Sequence[Tuple[str, str]], 

495 ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: 

496 """Pre-rpc interceptor for delete_operation 

497 

498 Override in a subclass to manipulate the request or metadata 

499 before they are sent to the Firestore server. 

500 """ 

501 return request, metadata 

502 

503 def post_delete_operation(self, response: None) -> None: 

504 """Post-rpc interceptor for delete_operation 

505 

506 Override in a subclass to manipulate the response 

507 after it is returned by the Firestore server but before 

508 it is returned to user code. 

509 """ 

510 return response 

511 

512 def pre_get_operation( 

513 self, 

514 request: operations_pb2.GetOperationRequest, 

515 metadata: Sequence[Tuple[str, str]], 

516 ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: 

517 """Pre-rpc interceptor for get_operation 

518 

519 Override in a subclass to manipulate the request or metadata 

520 before they are sent to the Firestore server. 

521 """ 

522 return request, metadata 

523 

524 def post_get_operation( 

525 self, response: operations_pb2.Operation 

526 ) -> operations_pb2.Operation: 

527 """Post-rpc interceptor for get_operation 

528 

529 Override in a subclass to manipulate the response 

530 after it is returned by the Firestore server but before 

531 it is returned to user code. 

532 """ 

533 return response 

534 

535 def pre_list_operations( 

536 self, 

537 request: operations_pb2.ListOperationsRequest, 

538 metadata: Sequence[Tuple[str, str]], 

539 ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: 

540 """Pre-rpc interceptor for list_operations 

541 

542 Override in a subclass to manipulate the request or metadata 

543 before they are sent to the Firestore server. 

544 """ 

545 return request, metadata 

546 

547 def post_list_operations( 

548 self, response: operations_pb2.ListOperationsResponse 

549 ) -> operations_pb2.ListOperationsResponse: 

550 """Post-rpc interceptor for list_operations 

551 

552 Override in a subclass to manipulate the response 

553 after it is returned by the Firestore server but before 

554 it is returned to user code. 

555 """ 

556 return response 

557 

558 

559@dataclasses.dataclass 

560class FirestoreRestStub: 

561 _session: AuthorizedSession 

562 _host: str 

563 _interceptor: FirestoreRestInterceptor 

564 

565 

566class FirestoreRestTransport(FirestoreTransport): 

567 """REST backend transport for Firestore. 

568 

569 The Cloud Firestore service. 

570 

571 Cloud Firestore is a fast, fully managed, serverless, 

572 cloud-native NoSQL document database that simplifies storing, 

573 syncing, and querying data for your mobile, web, and IoT apps at 

574 global scale. Its client libraries provide live synchronization 

575 and offline support, while its security features and 

576 integrations with Firebase and Google Cloud Platform accelerate 

577 building truly serverless apps. 

578 

579 This class defines the same methods as the primary client, so the 

580 primary client can load the underlying transport implementation 

581 and call it. 

582 

583 It sends JSON representations of protocol buffers over HTTP/1.1 

584 

585 """ 

586 

587 def __init__( 

588 self, 

589 *, 

590 host: str = "firestore.googleapis.com", 

591 credentials: Optional[ga_credentials.Credentials] = None, 

592 credentials_file: Optional[str] = None, 

593 scopes: Optional[Sequence[str]] = None, 

594 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

595 quota_project_id: Optional[str] = None, 

596 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

597 always_use_jwt_access: Optional[bool] = False, 

598 url_scheme: str = "https", 

599 interceptor: Optional[FirestoreRestInterceptor] = None, 

600 api_audience: Optional[str] = None, 

601 ) -> None: 

602 """Instantiate the transport. 

603 

604 Args: 

605 host (Optional[str]): 

606 The hostname to connect to. 

607 credentials (Optional[google.auth.credentials.Credentials]): The 

608 authorization credentials to attach to requests. These 

609 credentials identify the application to the service; if none 

610 are specified, the client will attempt to ascertain the 

611 credentials from the environment. 

612 

613 credentials_file (Optional[str]): A file with credentials that can 

614 be loaded with :func:`google.auth.load_credentials_from_file`. 

615 This argument is ignored if ``channel`` is provided. 

616 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

617 ignored if ``channel`` is provided. 

618 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client 

619 certificate to configure mutual TLS HTTP channel. It is ignored 

620 if ``channel`` is provided. 

621 quota_project_id (Optional[str]): An optional project to use for billing 

622 and quota. 

623 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

624 The client info used to send a user-agent string along with 

625 API requests. If ``None``, then default info will be used. 

626 Generally, you only need to set this if you are developing 

627 your own client library. 

628 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

629 be used for service account credentials. 

630 url_scheme: the protocol scheme for the API endpoint. Normally 

631 "https", but for testing or local servers, 

632 "http" can be specified. 

633 """ 

634 # Run the base constructor 

635 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. 

636 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the 

637 # credentials object 

638 maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host) 

639 if maybe_url_match is None: 

640 raise ValueError( 

641 f"Unexpected hostname structure: {host}" 

642 ) # pragma: NO COVER 

643 

644 url_match_items = maybe_url_match.groupdict() 

645 

646 host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host 

647 

648 super().__init__( 

649 host=host, 

650 credentials=credentials, 

651 client_info=client_info, 

652 always_use_jwt_access=always_use_jwt_access, 

653 api_audience=api_audience, 

654 ) 

655 self._session = AuthorizedSession( 

656 self._credentials, default_host=self.DEFAULT_HOST 

657 ) 

658 if client_cert_source_for_mtls: 

659 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

660 self._interceptor = interceptor or FirestoreRestInterceptor() 

661 self._prep_wrapped_messages(client_info) 

662 

663 class _BatchGetDocuments(FirestoreRestStub): 

664 def __hash__(self): 

665 return hash("BatchGetDocuments") 

666 

667 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

668 

669 @classmethod 

670 def _get_unset_required_fields(cls, message_dict): 

671 return { 

672 k: v 

673 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

674 if k not in message_dict 

675 } 

676 

677 def __call__( 

678 self, 

679 request: firestore.BatchGetDocumentsRequest, 

680 *, 

681 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

682 timeout: Optional[float] = None, 

683 metadata: Sequence[Tuple[str, str]] = (), 

684 ) -> rest_streaming.ResponseIterator: 

685 r"""Call the batch get documents method over HTTP. 

686 

687 Args: 

688 request (~.firestore.BatchGetDocumentsRequest): 

689 The request object. The request for 

690 [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. 

691 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

692 should be retried. 

693 timeout (float): The timeout for this request. 

694 metadata (Sequence[Tuple[str, str]]): Strings which should be 

695 sent along with the request as metadata. 

696 

697 Returns: 

698 ~.firestore.BatchGetDocumentsResponse: 

699 The streamed response for 

700 [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. 

701 

702 """ 

703 

704 http_options: List[Dict[str, str]] = [ 

705 { 

706 "method": "post", 

707 "uri": "/v1/{database=projects/*/databases/*}/documents:batchGet", 

708 "body": "*", 

709 }, 

710 ] 

711 request, metadata = self._interceptor.pre_batch_get_documents( 

712 request, metadata 

713 ) 

714 pb_request = firestore.BatchGetDocumentsRequest.pb(request) 

715 transcoded_request = path_template.transcode(http_options, pb_request) 

716 

717 # Jsonify the request body 

718 

719 body = json_format.MessageToJson( 

720 transcoded_request["body"], 

721 including_default_value_fields=False, 

722 use_integers_for_enums=True, 

723 ) 

724 uri = transcoded_request["uri"] 

725 method = transcoded_request["method"] 

726 

727 # Jsonify the query params 

728 query_params = json.loads( 

729 json_format.MessageToJson( 

730 transcoded_request["query_params"], 

731 including_default_value_fields=False, 

732 use_integers_for_enums=True, 

733 ) 

734 ) 

735 query_params.update(self._get_unset_required_fields(query_params)) 

736 

737 query_params["$alt"] = "json;enum-encoding=int" 

738 

739 # Send the request 

740 headers = dict(metadata) 

741 headers["Content-Type"] = "application/json" 

742 response = getattr(self._session, method)( 

743 "{host}{uri}".format(host=self._host, uri=uri), 

744 timeout=timeout, 

745 headers=headers, 

746 params=rest_helpers.flatten_query_params(query_params, strict=True), 

747 data=body, 

748 ) 

749 

750 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

751 # subclass. 

752 if response.status_code >= 400: 

753 raise core_exceptions.from_http_response(response) 

754 

755 # Return the response 

756 resp = rest_streaming.ResponseIterator( 

757 response, firestore.BatchGetDocumentsResponse 

758 ) 

759 resp = self._interceptor.post_batch_get_documents(resp) 

760 return resp 

761 

762 class _BatchWrite(FirestoreRestStub): 

763 def __hash__(self): 

764 return hash("BatchWrite") 

765 

766 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

767 

768 @classmethod 

769 def _get_unset_required_fields(cls, message_dict): 

770 return { 

771 k: v 

772 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

773 if k not in message_dict 

774 } 

775 

776 def __call__( 

777 self, 

778 request: firestore.BatchWriteRequest, 

779 *, 

780 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

781 timeout: Optional[float] = None, 

782 metadata: Sequence[Tuple[str, str]] = (), 

783 ) -> firestore.BatchWriteResponse: 

784 r"""Call the batch write method over HTTP. 

785 

786 Args: 

787 request (~.firestore.BatchWriteRequest): 

788 The request object. The request for 

789 [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite]. 

790 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

791 should be retried. 

792 timeout (float): The timeout for this request. 

793 metadata (Sequence[Tuple[str, str]]): Strings which should be 

794 sent along with the request as metadata. 

795 

796 Returns: 

797 ~.firestore.BatchWriteResponse: 

798 The response from 

799 [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite]. 

800 

801 """ 

802 

803 http_options: List[Dict[str, str]] = [ 

804 { 

805 "method": "post", 

806 "uri": "/v1/{database=projects/*/databases/*}/documents:batchWrite", 

807 "body": "*", 

808 }, 

809 ] 

810 request, metadata = self._interceptor.pre_batch_write(request, metadata) 

811 pb_request = firestore.BatchWriteRequest.pb(request) 

812 transcoded_request = path_template.transcode(http_options, pb_request) 

813 

814 # Jsonify the request body 

815 

816 body = json_format.MessageToJson( 

817 transcoded_request["body"], 

818 including_default_value_fields=False, 

819 use_integers_for_enums=True, 

820 ) 

821 uri = transcoded_request["uri"] 

822 method = transcoded_request["method"] 

823 

824 # Jsonify the query params 

825 query_params = json.loads( 

826 json_format.MessageToJson( 

827 transcoded_request["query_params"], 

828 including_default_value_fields=False, 

829 use_integers_for_enums=True, 

830 ) 

831 ) 

832 query_params.update(self._get_unset_required_fields(query_params)) 

833 

834 query_params["$alt"] = "json;enum-encoding=int" 

835 

836 # Send the request 

837 headers = dict(metadata) 

838 headers["Content-Type"] = "application/json" 

839 response = getattr(self._session, method)( 

840 "{host}{uri}".format(host=self._host, uri=uri), 

841 timeout=timeout, 

842 headers=headers, 

843 params=rest_helpers.flatten_query_params(query_params, strict=True), 

844 data=body, 

845 ) 

846 

847 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

848 # subclass. 

849 if response.status_code >= 400: 

850 raise core_exceptions.from_http_response(response) 

851 

852 # Return the response 

853 resp = firestore.BatchWriteResponse() 

854 pb_resp = firestore.BatchWriteResponse.pb(resp) 

855 

856 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

857 resp = self._interceptor.post_batch_write(resp) 

858 return resp 

859 

860 class _BeginTransaction(FirestoreRestStub): 

861 def __hash__(self): 

862 return hash("BeginTransaction") 

863 

864 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

865 

866 @classmethod 

867 def _get_unset_required_fields(cls, message_dict): 

868 return { 

869 k: v 

870 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

871 if k not in message_dict 

872 } 

873 

874 def __call__( 

875 self, 

876 request: firestore.BeginTransactionRequest, 

877 *, 

878 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

879 timeout: Optional[float] = None, 

880 metadata: Sequence[Tuple[str, str]] = (), 

881 ) -> firestore.BeginTransactionResponse: 

882 r"""Call the begin transaction method over HTTP. 

883 

884 Args: 

885 request (~.firestore.BeginTransactionRequest): 

886 The request object. The request for 

887 [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction]. 

888 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

889 should be retried. 

890 timeout (float): The timeout for this request. 

891 metadata (Sequence[Tuple[str, str]]): Strings which should be 

892 sent along with the request as metadata. 

893 

894 Returns: 

895 ~.firestore.BeginTransactionResponse: 

896 The response for 

897 [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction]. 

898 

899 """ 

900 

901 http_options: List[Dict[str, str]] = [ 

902 { 

903 "method": "post", 

904 "uri": "/v1/{database=projects/*/databases/*}/documents:beginTransaction", 

905 "body": "*", 

906 }, 

907 ] 

908 request, metadata = self._interceptor.pre_begin_transaction( 

909 request, metadata 

910 ) 

911 pb_request = firestore.BeginTransactionRequest.pb(request) 

912 transcoded_request = path_template.transcode(http_options, pb_request) 

913 

914 # Jsonify the request body 

915 

916 body = json_format.MessageToJson( 

917 transcoded_request["body"], 

918 including_default_value_fields=False, 

919 use_integers_for_enums=True, 

920 ) 

921 uri = transcoded_request["uri"] 

922 method = transcoded_request["method"] 

923 

924 # Jsonify the query params 

925 query_params = json.loads( 

926 json_format.MessageToJson( 

927 transcoded_request["query_params"], 

928 including_default_value_fields=False, 

929 use_integers_for_enums=True, 

930 ) 

931 ) 

932 query_params.update(self._get_unset_required_fields(query_params)) 

933 

934 query_params["$alt"] = "json;enum-encoding=int" 

935 

936 # Send the request 

937 headers = dict(metadata) 

938 headers["Content-Type"] = "application/json" 

939 response = getattr(self._session, method)( 

940 "{host}{uri}".format(host=self._host, uri=uri), 

941 timeout=timeout, 

942 headers=headers, 

943 params=rest_helpers.flatten_query_params(query_params, strict=True), 

944 data=body, 

945 ) 

946 

947 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

948 # subclass. 

949 if response.status_code >= 400: 

950 raise core_exceptions.from_http_response(response) 

951 

952 # Return the response 

953 resp = firestore.BeginTransactionResponse() 

954 pb_resp = firestore.BeginTransactionResponse.pb(resp) 

955 

956 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

957 resp = self._interceptor.post_begin_transaction(resp) 

958 return resp 

959 

960 class _Commit(FirestoreRestStub): 

961 def __hash__(self): 

962 return hash("Commit") 

963 

964 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

965 

966 @classmethod 

967 def _get_unset_required_fields(cls, message_dict): 

968 return { 

969 k: v 

970 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

971 if k not in message_dict 

972 } 

973 

974 def __call__( 

975 self, 

976 request: firestore.CommitRequest, 

977 *, 

978 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

979 timeout: Optional[float] = None, 

980 metadata: Sequence[Tuple[str, str]] = (), 

981 ) -> firestore.CommitResponse: 

982 r"""Call the commit method over HTTP. 

983 

984 Args: 

985 request (~.firestore.CommitRequest): 

986 The request object. The request for 

987 [Firestore.Commit][google.firestore.v1.Firestore.Commit]. 

988 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

989 should be retried. 

990 timeout (float): The timeout for this request. 

991 metadata (Sequence[Tuple[str, str]]): Strings which should be 

992 sent along with the request as metadata. 

993 

994 Returns: 

995 ~.firestore.CommitResponse: 

996 The response for 

997 [Firestore.Commit][google.firestore.v1.Firestore.Commit]. 

998 

999 """ 

1000 

1001 http_options: List[Dict[str, str]] = [ 

1002 { 

1003 "method": "post", 

1004 "uri": "/v1/{database=projects/*/databases/*}/documents:commit", 

1005 "body": "*", 

1006 }, 

1007 ] 

1008 request, metadata = self._interceptor.pre_commit(request, metadata) 

1009 pb_request = firestore.CommitRequest.pb(request) 

1010 transcoded_request = path_template.transcode(http_options, pb_request) 

1011 

1012 # Jsonify the request body 

1013 

1014 body = json_format.MessageToJson( 

1015 transcoded_request["body"], 

1016 including_default_value_fields=False, 

1017 use_integers_for_enums=True, 

1018 ) 

1019 uri = transcoded_request["uri"] 

1020 method = transcoded_request["method"] 

1021 

1022 # Jsonify the query params 

1023 query_params = json.loads( 

1024 json_format.MessageToJson( 

1025 transcoded_request["query_params"], 

1026 including_default_value_fields=False, 

1027 use_integers_for_enums=True, 

1028 ) 

1029 ) 

1030 query_params.update(self._get_unset_required_fields(query_params)) 

1031 

1032 query_params["$alt"] = "json;enum-encoding=int" 

1033 

1034 # Send the request 

1035 headers = dict(metadata) 

1036 headers["Content-Type"] = "application/json" 

1037 response = getattr(self._session, method)( 

1038 "{host}{uri}".format(host=self._host, uri=uri), 

1039 timeout=timeout, 

1040 headers=headers, 

1041 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1042 data=body, 

1043 ) 

1044 

1045 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1046 # subclass. 

1047 if response.status_code >= 400: 

1048 raise core_exceptions.from_http_response(response) 

1049 

1050 # Return the response 

1051 resp = firestore.CommitResponse() 

1052 pb_resp = firestore.CommitResponse.pb(resp) 

1053 

1054 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1055 resp = self._interceptor.post_commit(resp) 

1056 return resp 

1057 

1058 class _CreateDocument(FirestoreRestStub): 

1059 def __hash__(self): 

1060 return hash("CreateDocument") 

1061 

1062 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1063 

1064 @classmethod 

1065 def _get_unset_required_fields(cls, message_dict): 

1066 return { 

1067 k: v 

1068 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1069 if k not in message_dict 

1070 } 

1071 

1072 def __call__( 

1073 self, 

1074 request: firestore.CreateDocumentRequest, 

1075 *, 

1076 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1077 timeout: Optional[float] = None, 

1078 metadata: Sequence[Tuple[str, str]] = (), 

1079 ) -> document.Document: 

1080 r"""Call the create document method over HTTP. 

1081 

1082 Args: 

1083 request (~.firestore.CreateDocumentRequest): 

1084 The request object. The request for 

1085 [Firestore.CreateDocument][google.firestore.v1.Firestore.CreateDocument]. 

1086 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1087 should be retried. 

1088 timeout (float): The timeout for this request. 

1089 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1090 sent along with the request as metadata. 

1091 

1092 Returns: 

1093 ~.document.Document: 

1094 A Firestore document. 

1095 

1096 Must not exceed 1 MiB - 4 bytes. 

1097 

1098 """ 

1099 

1100 http_options: List[Dict[str, str]] = [ 

1101 { 

1102 "method": "post", 

1103 "uri": "/v1/{parent=projects/*/databases/*/documents/**}/{collection_id}", 

1104 "body": "document", 

1105 }, 

1106 ] 

1107 request, metadata = self._interceptor.pre_create_document(request, metadata) 

1108 pb_request = firestore.CreateDocumentRequest.pb(request) 

1109 transcoded_request = path_template.transcode(http_options, pb_request) 

1110 

1111 # Jsonify the request body 

1112 

1113 body = json_format.MessageToJson( 

1114 transcoded_request["body"], 

1115 including_default_value_fields=False, 

1116 use_integers_for_enums=True, 

1117 ) 

1118 uri = transcoded_request["uri"] 

1119 method = transcoded_request["method"] 

1120 

1121 # Jsonify the query params 

1122 query_params = json.loads( 

1123 json_format.MessageToJson( 

1124 transcoded_request["query_params"], 

1125 including_default_value_fields=False, 

1126 use_integers_for_enums=True, 

1127 ) 

1128 ) 

1129 query_params.update(self._get_unset_required_fields(query_params)) 

1130 

1131 query_params["$alt"] = "json;enum-encoding=int" 

1132 

1133 # Send the request 

1134 headers = dict(metadata) 

1135 headers["Content-Type"] = "application/json" 

1136 response = getattr(self._session, method)( 

1137 "{host}{uri}".format(host=self._host, uri=uri), 

1138 timeout=timeout, 

1139 headers=headers, 

1140 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1141 data=body, 

1142 ) 

1143 

1144 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1145 # subclass. 

1146 if response.status_code >= 400: 

1147 raise core_exceptions.from_http_response(response) 

1148 

1149 # Return the response 

1150 resp = document.Document() 

1151 pb_resp = document.Document.pb(resp) 

1152 

1153 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1154 resp = self._interceptor.post_create_document(resp) 

1155 return resp 

1156 

1157 class _DeleteDocument(FirestoreRestStub): 

1158 def __hash__(self): 

1159 return hash("DeleteDocument") 

1160 

1161 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1162 

1163 @classmethod 

1164 def _get_unset_required_fields(cls, message_dict): 

1165 return { 

1166 k: v 

1167 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1168 if k not in message_dict 

1169 } 

1170 

1171 def __call__( 

1172 self, 

1173 request: firestore.DeleteDocumentRequest, 

1174 *, 

1175 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1176 timeout: Optional[float] = None, 

1177 metadata: Sequence[Tuple[str, str]] = (), 

1178 ): 

1179 r"""Call the delete document method over HTTP. 

1180 

1181 Args: 

1182 request (~.firestore.DeleteDocumentRequest): 

1183 The request object. The request for 

1184 [Firestore.DeleteDocument][google.firestore.v1.Firestore.DeleteDocument]. 

1185 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1186 should be retried. 

1187 timeout (float): The timeout for this request. 

1188 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1189 sent along with the request as metadata. 

1190 """ 

1191 

1192 http_options: List[Dict[str, str]] = [ 

1193 { 

1194 "method": "delete", 

1195 "uri": "/v1/{name=projects/*/databases/*/documents/*/**}", 

1196 }, 

1197 ] 

1198 request, metadata = self._interceptor.pre_delete_document(request, metadata) 

1199 pb_request = firestore.DeleteDocumentRequest.pb(request) 

1200 transcoded_request = path_template.transcode(http_options, pb_request) 

1201 

1202 uri = transcoded_request["uri"] 

1203 method = transcoded_request["method"] 

1204 

1205 # Jsonify the query params 

1206 query_params = json.loads( 

1207 json_format.MessageToJson( 

1208 transcoded_request["query_params"], 

1209 including_default_value_fields=False, 

1210 use_integers_for_enums=True, 

1211 ) 

1212 ) 

1213 query_params.update(self._get_unset_required_fields(query_params)) 

1214 

1215 query_params["$alt"] = "json;enum-encoding=int" 

1216 

1217 # Send the request 

1218 headers = dict(metadata) 

1219 headers["Content-Type"] = "application/json" 

1220 response = getattr(self._session, method)( 

1221 "{host}{uri}".format(host=self._host, uri=uri), 

1222 timeout=timeout, 

1223 headers=headers, 

1224 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1225 ) 

1226 

1227 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1228 # subclass. 

1229 if response.status_code >= 400: 

1230 raise core_exceptions.from_http_response(response) 

1231 

1232 class _GetDocument(FirestoreRestStub): 

1233 def __hash__(self): 

1234 return hash("GetDocument") 

1235 

1236 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1237 

1238 @classmethod 

1239 def _get_unset_required_fields(cls, message_dict): 

1240 return { 

1241 k: v 

1242 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1243 if k not in message_dict 

1244 } 

1245 

1246 def __call__( 

1247 self, 

1248 request: firestore.GetDocumentRequest, 

1249 *, 

1250 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1251 timeout: Optional[float] = None, 

1252 metadata: Sequence[Tuple[str, str]] = (), 

1253 ) -> document.Document: 

1254 r"""Call the get document method over HTTP. 

1255 

1256 Args: 

1257 request (~.firestore.GetDocumentRequest): 

1258 The request object. The request for 

1259 [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument]. 

1260 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1261 should be retried. 

1262 timeout (float): The timeout for this request. 

1263 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1264 sent along with the request as metadata. 

1265 

1266 Returns: 

1267 ~.document.Document: 

1268 A Firestore document. 

1269 

1270 Must not exceed 1 MiB - 4 bytes. 

1271 

1272 """ 

1273 

1274 http_options: List[Dict[str, str]] = [ 

1275 { 

1276 "method": "get", 

1277 "uri": "/v1/{name=projects/*/databases/*/documents/*/**}", 

1278 }, 

1279 ] 

1280 request, metadata = self._interceptor.pre_get_document(request, metadata) 

1281 pb_request = firestore.GetDocumentRequest.pb(request) 

1282 transcoded_request = path_template.transcode(http_options, pb_request) 

1283 

1284 uri = transcoded_request["uri"] 

1285 method = transcoded_request["method"] 

1286 

1287 # Jsonify the query params 

1288 query_params = json.loads( 

1289 json_format.MessageToJson( 

1290 transcoded_request["query_params"], 

1291 including_default_value_fields=False, 

1292 use_integers_for_enums=True, 

1293 ) 

1294 ) 

1295 query_params.update(self._get_unset_required_fields(query_params)) 

1296 

1297 query_params["$alt"] = "json;enum-encoding=int" 

1298 

1299 # Send the request 

1300 headers = dict(metadata) 

1301 headers["Content-Type"] = "application/json" 

1302 response = getattr(self._session, method)( 

1303 "{host}{uri}".format(host=self._host, uri=uri), 

1304 timeout=timeout, 

1305 headers=headers, 

1306 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1307 ) 

1308 

1309 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1310 # subclass. 

1311 if response.status_code >= 400: 

1312 raise core_exceptions.from_http_response(response) 

1313 

1314 # Return the response 

1315 resp = document.Document() 

1316 pb_resp = document.Document.pb(resp) 

1317 

1318 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1319 resp = self._interceptor.post_get_document(resp) 

1320 return resp 

1321 

1322 class _ListCollectionIds(FirestoreRestStub): 

1323 def __hash__(self): 

1324 return hash("ListCollectionIds") 

1325 

1326 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1327 

1328 @classmethod 

1329 def _get_unset_required_fields(cls, message_dict): 

1330 return { 

1331 k: v 

1332 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1333 if k not in message_dict 

1334 } 

1335 

1336 def __call__( 

1337 self, 

1338 request: firestore.ListCollectionIdsRequest, 

1339 *, 

1340 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1341 timeout: Optional[float] = None, 

1342 metadata: Sequence[Tuple[str, str]] = (), 

1343 ) -> firestore.ListCollectionIdsResponse: 

1344 r"""Call the list collection ids method over HTTP. 

1345 

1346 Args: 

1347 request (~.firestore.ListCollectionIdsRequest): 

1348 The request object. The request for 

1349 [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds]. 

1350 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1351 should be retried. 

1352 timeout (float): The timeout for this request. 

1353 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1354 sent along with the request as metadata. 

1355 

1356 Returns: 

1357 ~.firestore.ListCollectionIdsResponse: 

1358 The response from 

1359 [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds]. 

1360 

1361 """ 

1362 

1363 http_options: List[Dict[str, str]] = [ 

1364 { 

1365 "method": "post", 

1366 "uri": "/v1/{parent=projects/*/databases/*/documents}:listCollectionIds", 

1367 "body": "*", 

1368 }, 

1369 { 

1370 "method": "post", 

1371 "uri": "/v1/{parent=projects/*/databases/*/documents/*/**}:listCollectionIds", 

1372 "body": "*", 

1373 }, 

1374 ] 

1375 request, metadata = self._interceptor.pre_list_collection_ids( 

1376 request, metadata 

1377 ) 

1378 pb_request = firestore.ListCollectionIdsRequest.pb(request) 

1379 transcoded_request = path_template.transcode(http_options, pb_request) 

1380 

1381 # Jsonify the request body 

1382 

1383 body = json_format.MessageToJson( 

1384 transcoded_request["body"], 

1385 including_default_value_fields=False, 

1386 use_integers_for_enums=True, 

1387 ) 

1388 uri = transcoded_request["uri"] 

1389 method = transcoded_request["method"] 

1390 

1391 # Jsonify the query params 

1392 query_params = json.loads( 

1393 json_format.MessageToJson( 

1394 transcoded_request["query_params"], 

1395 including_default_value_fields=False, 

1396 use_integers_for_enums=True, 

1397 ) 

1398 ) 

1399 query_params.update(self._get_unset_required_fields(query_params)) 

1400 

1401 query_params["$alt"] = "json;enum-encoding=int" 

1402 

1403 # Send the request 

1404 headers = dict(metadata) 

1405 headers["Content-Type"] = "application/json" 

1406 response = getattr(self._session, method)( 

1407 "{host}{uri}".format(host=self._host, uri=uri), 

1408 timeout=timeout, 

1409 headers=headers, 

1410 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1411 data=body, 

1412 ) 

1413 

1414 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1415 # subclass. 

1416 if response.status_code >= 400: 

1417 raise core_exceptions.from_http_response(response) 

1418 

1419 # Return the response 

1420 resp = firestore.ListCollectionIdsResponse() 

1421 pb_resp = firestore.ListCollectionIdsResponse.pb(resp) 

1422 

1423 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1424 resp = self._interceptor.post_list_collection_ids(resp) 

1425 return resp 

1426 

1427 class _ListDocuments(FirestoreRestStub): 

1428 def __hash__(self): 

1429 return hash("ListDocuments") 

1430 

1431 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1432 

1433 @classmethod 

1434 def _get_unset_required_fields(cls, message_dict): 

1435 return { 

1436 k: v 

1437 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1438 if k not in message_dict 

1439 } 

1440 

1441 def __call__( 

1442 self, 

1443 request: firestore.ListDocumentsRequest, 

1444 *, 

1445 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1446 timeout: Optional[float] = None, 

1447 metadata: Sequence[Tuple[str, str]] = (), 

1448 ) -> firestore.ListDocumentsResponse: 

1449 r"""Call the list documents method over HTTP. 

1450 

1451 Args: 

1452 request (~.firestore.ListDocumentsRequest): 

1453 The request object. The request for 

1454 [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments]. 

1455 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1456 should be retried. 

1457 timeout (float): The timeout for this request. 

1458 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1459 sent along with the request as metadata. 

1460 

1461 Returns: 

1462 ~.firestore.ListDocumentsResponse: 

1463 The response for 

1464 [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments]. 

1465 

1466 """ 

1467 

1468 http_options: List[Dict[str, str]] = [ 

1469 { 

1470 "method": "get", 

1471 "uri": "/v1/{parent=projects/*/databases/*/documents/*/**}/{collection_id}", 

1472 }, 

1473 { 

1474 "method": "get", 

1475 "uri": "/v1/{parent=projects/*/databases/*/documents}/{collection_id}", 

1476 }, 

1477 ] 

1478 request, metadata = self._interceptor.pre_list_documents(request, metadata) 

1479 pb_request = firestore.ListDocumentsRequest.pb(request) 

1480 transcoded_request = path_template.transcode(http_options, pb_request) 

1481 

1482 uri = transcoded_request["uri"] 

1483 method = transcoded_request["method"] 

1484 

1485 # Jsonify the query params 

1486 query_params = json.loads( 

1487 json_format.MessageToJson( 

1488 transcoded_request["query_params"], 

1489 including_default_value_fields=False, 

1490 use_integers_for_enums=True, 

1491 ) 

1492 ) 

1493 query_params.update(self._get_unset_required_fields(query_params)) 

1494 

1495 query_params["$alt"] = "json;enum-encoding=int" 

1496 

1497 # Send the request 

1498 headers = dict(metadata) 

1499 headers["Content-Type"] = "application/json" 

1500 response = getattr(self._session, method)( 

1501 "{host}{uri}".format(host=self._host, uri=uri), 

1502 timeout=timeout, 

1503 headers=headers, 

1504 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1505 ) 

1506 

1507 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1508 # subclass. 

1509 if response.status_code >= 400: 

1510 raise core_exceptions.from_http_response(response) 

1511 

1512 # Return the response 

1513 resp = firestore.ListDocumentsResponse() 

1514 pb_resp = firestore.ListDocumentsResponse.pb(resp) 

1515 

1516 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1517 resp = self._interceptor.post_list_documents(resp) 

1518 return resp 

1519 

1520 class _Listen(FirestoreRestStub): 

1521 def __hash__(self): 

1522 return hash("Listen") 

1523 

1524 def __call__( 

1525 self, 

1526 request: firestore.ListenRequest, 

1527 *, 

1528 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1529 timeout: Optional[float] = None, 

1530 metadata: Sequence[Tuple[str, str]] = (), 

1531 ) -> rest_streaming.ResponseIterator: 

1532 raise NotImplementedError( 

1533 "Method Listen is not available over REST transport" 

1534 ) 

1535 

1536 class _PartitionQuery(FirestoreRestStub): 

1537 def __hash__(self): 

1538 return hash("PartitionQuery") 

1539 

1540 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1541 

1542 @classmethod 

1543 def _get_unset_required_fields(cls, message_dict): 

1544 return { 

1545 k: v 

1546 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1547 if k not in message_dict 

1548 } 

1549 

1550 def __call__( 

1551 self, 

1552 request: firestore.PartitionQueryRequest, 

1553 *, 

1554 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1555 timeout: Optional[float] = None, 

1556 metadata: Sequence[Tuple[str, str]] = (), 

1557 ) -> firestore.PartitionQueryResponse: 

1558 r"""Call the partition query method over HTTP. 

1559 

1560 Args: 

1561 request (~.firestore.PartitionQueryRequest): 

1562 The request object. The request for 

1563 [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery]. 

1564 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1565 should be retried. 

1566 timeout (float): The timeout for this request. 

1567 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1568 sent along with the request as metadata. 

1569 

1570 Returns: 

1571 ~.firestore.PartitionQueryResponse: 

1572 The response for 

1573 [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery]. 

1574 

1575 """ 

1576 

1577 http_options: List[Dict[str, str]] = [ 

1578 { 

1579 "method": "post", 

1580 "uri": "/v1/{parent=projects/*/databases/*/documents}:partitionQuery", 

1581 "body": "*", 

1582 }, 

1583 { 

1584 "method": "post", 

1585 "uri": "/v1/{parent=projects/*/databases/*/documents/*/**}:partitionQuery", 

1586 "body": "*", 

1587 }, 

1588 ] 

1589 request, metadata = self._interceptor.pre_partition_query(request, metadata) 

1590 pb_request = firestore.PartitionQueryRequest.pb(request) 

1591 transcoded_request = path_template.transcode(http_options, pb_request) 

1592 

1593 # Jsonify the request body 

1594 

1595 body = json_format.MessageToJson( 

1596 transcoded_request["body"], 

1597 including_default_value_fields=False, 

1598 use_integers_for_enums=True, 

1599 ) 

1600 uri = transcoded_request["uri"] 

1601 method = transcoded_request["method"] 

1602 

1603 # Jsonify the query params 

1604 query_params = json.loads( 

1605 json_format.MessageToJson( 

1606 transcoded_request["query_params"], 

1607 including_default_value_fields=False, 

1608 use_integers_for_enums=True, 

1609 ) 

1610 ) 

1611 query_params.update(self._get_unset_required_fields(query_params)) 

1612 

1613 query_params["$alt"] = "json;enum-encoding=int" 

1614 

1615 # Send the request 

1616 headers = dict(metadata) 

1617 headers["Content-Type"] = "application/json" 

1618 response = getattr(self._session, method)( 

1619 "{host}{uri}".format(host=self._host, uri=uri), 

1620 timeout=timeout, 

1621 headers=headers, 

1622 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1623 data=body, 

1624 ) 

1625 

1626 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1627 # subclass. 

1628 if response.status_code >= 400: 

1629 raise core_exceptions.from_http_response(response) 

1630 

1631 # Return the response 

1632 resp = firestore.PartitionQueryResponse() 

1633 pb_resp = firestore.PartitionQueryResponse.pb(resp) 

1634 

1635 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1636 resp = self._interceptor.post_partition_query(resp) 

1637 return resp 

1638 

1639 class _Rollback(FirestoreRestStub): 

1640 def __hash__(self): 

1641 return hash("Rollback") 

1642 

1643 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1644 

1645 @classmethod 

1646 def _get_unset_required_fields(cls, message_dict): 

1647 return { 

1648 k: v 

1649 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1650 if k not in message_dict 

1651 } 

1652 

1653 def __call__( 

1654 self, 

1655 request: firestore.RollbackRequest, 

1656 *, 

1657 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1658 timeout: Optional[float] = None, 

1659 metadata: Sequence[Tuple[str, str]] = (), 

1660 ): 

1661 r"""Call the rollback method over HTTP. 

1662 

1663 Args: 

1664 request (~.firestore.RollbackRequest): 

1665 The request object. The request for 

1666 [Firestore.Rollback][google.firestore.v1.Firestore.Rollback]. 

1667 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1668 should be retried. 

1669 timeout (float): The timeout for this request. 

1670 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1671 sent along with the request as metadata. 

1672 """ 

1673 

1674 http_options: List[Dict[str, str]] = [ 

1675 { 

1676 "method": "post", 

1677 "uri": "/v1/{database=projects/*/databases/*}/documents:rollback", 

1678 "body": "*", 

1679 }, 

1680 ] 

1681 request, metadata = self._interceptor.pre_rollback(request, metadata) 

1682 pb_request = firestore.RollbackRequest.pb(request) 

1683 transcoded_request = path_template.transcode(http_options, pb_request) 

1684 

1685 # Jsonify the request body 

1686 

1687 body = json_format.MessageToJson( 

1688 transcoded_request["body"], 

1689 including_default_value_fields=False, 

1690 use_integers_for_enums=True, 

1691 ) 

1692 uri = transcoded_request["uri"] 

1693 method = transcoded_request["method"] 

1694 

1695 # Jsonify the query params 

1696 query_params = json.loads( 

1697 json_format.MessageToJson( 

1698 transcoded_request["query_params"], 

1699 including_default_value_fields=False, 

1700 use_integers_for_enums=True, 

1701 ) 

1702 ) 

1703 query_params.update(self._get_unset_required_fields(query_params)) 

1704 

1705 query_params["$alt"] = "json;enum-encoding=int" 

1706 

1707 # Send the request 

1708 headers = dict(metadata) 

1709 headers["Content-Type"] = "application/json" 

1710 response = getattr(self._session, method)( 

1711 "{host}{uri}".format(host=self._host, uri=uri), 

1712 timeout=timeout, 

1713 headers=headers, 

1714 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1715 data=body, 

1716 ) 

1717 

1718 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1719 # subclass. 

1720 if response.status_code >= 400: 

1721 raise core_exceptions.from_http_response(response) 

1722 

1723 class _RunAggregationQuery(FirestoreRestStub): 

1724 def __hash__(self): 

1725 return hash("RunAggregationQuery") 

1726 

1727 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1728 

1729 @classmethod 

1730 def _get_unset_required_fields(cls, message_dict): 

1731 return { 

1732 k: v 

1733 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1734 if k not in message_dict 

1735 } 

1736 

1737 def __call__( 

1738 self, 

1739 request: firestore.RunAggregationQueryRequest, 

1740 *, 

1741 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1742 timeout: Optional[float] = None, 

1743 metadata: Sequence[Tuple[str, str]] = (), 

1744 ) -> rest_streaming.ResponseIterator: 

1745 r"""Call the run aggregation query method over HTTP. 

1746 

1747 Args: 

1748 request (~.firestore.RunAggregationQueryRequest): 

1749 The request object. The request for 

1750 [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery]. 

1751 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1752 should be retried. 

1753 timeout (float): The timeout for this request. 

1754 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1755 sent along with the request as metadata. 

1756 

1757 Returns: 

1758 ~.firestore.RunAggregationQueryResponse: 

1759 The response for 

1760 [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery]. 

1761 

1762 """ 

1763 

1764 http_options: List[Dict[str, str]] = [ 

1765 { 

1766 "method": "post", 

1767 "uri": "/v1/{parent=projects/*/databases/*/documents}:runAggregationQuery", 

1768 "body": "*", 

1769 }, 

1770 { 

1771 "method": "post", 

1772 "uri": "/v1/{parent=projects/*/databases/*/documents/*/**}:runAggregationQuery", 

1773 "body": "*", 

1774 }, 

1775 ] 

1776 request, metadata = self._interceptor.pre_run_aggregation_query( 

1777 request, metadata 

1778 ) 

1779 pb_request = firestore.RunAggregationQueryRequest.pb(request) 

1780 transcoded_request = path_template.transcode(http_options, pb_request) 

1781 

1782 # Jsonify the request body 

1783 

1784 body = json_format.MessageToJson( 

1785 transcoded_request["body"], 

1786 including_default_value_fields=False, 

1787 use_integers_for_enums=True, 

1788 ) 

1789 uri = transcoded_request["uri"] 

1790 method = transcoded_request["method"] 

1791 

1792 # Jsonify the query params 

1793 query_params = json.loads( 

1794 json_format.MessageToJson( 

1795 transcoded_request["query_params"], 

1796 including_default_value_fields=False, 

1797 use_integers_for_enums=True, 

1798 ) 

1799 ) 

1800 query_params.update(self._get_unset_required_fields(query_params)) 

1801 

1802 query_params["$alt"] = "json;enum-encoding=int" 

1803 

1804 # Send the request 

1805 headers = dict(metadata) 

1806 headers["Content-Type"] = "application/json" 

1807 response = getattr(self._session, method)( 

1808 "{host}{uri}".format(host=self._host, uri=uri), 

1809 timeout=timeout, 

1810 headers=headers, 

1811 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1812 data=body, 

1813 ) 

1814 

1815 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1816 # subclass. 

1817 if response.status_code >= 400: 

1818 raise core_exceptions.from_http_response(response) 

1819 

1820 # Return the response 

1821 resp = rest_streaming.ResponseIterator( 

1822 response, firestore.RunAggregationQueryResponse 

1823 ) 

1824 resp = self._interceptor.post_run_aggregation_query(resp) 

1825 return resp 

1826 

1827 class _RunQuery(FirestoreRestStub): 

1828 def __hash__(self): 

1829 return hash("RunQuery") 

1830 

1831 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1832 

1833 @classmethod 

1834 def _get_unset_required_fields(cls, message_dict): 

1835 return { 

1836 k: v 

1837 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1838 if k not in message_dict 

1839 } 

1840 

1841 def __call__( 

1842 self, 

1843 request: firestore.RunQueryRequest, 

1844 *, 

1845 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1846 timeout: Optional[float] = None, 

1847 metadata: Sequence[Tuple[str, str]] = (), 

1848 ) -> rest_streaming.ResponseIterator: 

1849 r"""Call the run query method over HTTP. 

1850 

1851 Args: 

1852 request (~.firestore.RunQueryRequest): 

1853 The request object. The request for 

1854 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery]. 

1855 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1856 should be retried. 

1857 timeout (float): The timeout for this request. 

1858 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1859 sent along with the request as metadata. 

1860 

1861 Returns: 

1862 ~.firestore.RunQueryResponse: 

1863 The response for 

1864 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery]. 

1865 

1866 """ 

1867 

1868 http_options: List[Dict[str, str]] = [ 

1869 { 

1870 "method": "post", 

1871 "uri": "/v1/{parent=projects/*/databases/*/documents}:runQuery", 

1872 "body": "*", 

1873 }, 

1874 { 

1875 "method": "post", 

1876 "uri": "/v1/{parent=projects/*/databases/*/documents/*/**}:runQuery", 

1877 "body": "*", 

1878 }, 

1879 ] 

1880 request, metadata = self._interceptor.pre_run_query(request, metadata) 

1881 pb_request = firestore.RunQueryRequest.pb(request) 

1882 transcoded_request = path_template.transcode(http_options, pb_request) 

1883 

1884 # Jsonify the request body 

1885 

1886 body = json_format.MessageToJson( 

1887 transcoded_request["body"], 

1888 including_default_value_fields=False, 

1889 use_integers_for_enums=True, 

1890 ) 

1891 uri = transcoded_request["uri"] 

1892 method = transcoded_request["method"] 

1893 

1894 # Jsonify the query params 

1895 query_params = json.loads( 

1896 json_format.MessageToJson( 

1897 transcoded_request["query_params"], 

1898 including_default_value_fields=False, 

1899 use_integers_for_enums=True, 

1900 ) 

1901 ) 

1902 query_params.update(self._get_unset_required_fields(query_params)) 

1903 

1904 query_params["$alt"] = "json;enum-encoding=int" 

1905 

1906 # Send the request 

1907 headers = dict(metadata) 

1908 headers["Content-Type"] = "application/json" 

1909 response = getattr(self._session, method)( 

1910 "{host}{uri}".format(host=self._host, uri=uri), 

1911 timeout=timeout, 

1912 headers=headers, 

1913 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1914 data=body, 

1915 ) 

1916 

1917 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1918 # subclass. 

1919 if response.status_code >= 400: 

1920 raise core_exceptions.from_http_response(response) 

1921 

1922 # Return the response 

1923 resp = rest_streaming.ResponseIterator(response, firestore.RunQueryResponse) 

1924 resp = self._interceptor.post_run_query(resp) 

1925 return resp 

1926 

1927 class _UpdateDocument(FirestoreRestStub): 

1928 def __hash__(self): 

1929 return hash("UpdateDocument") 

1930 

1931 __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} 

1932 

1933 @classmethod 

1934 def _get_unset_required_fields(cls, message_dict): 

1935 return { 

1936 k: v 

1937 for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() 

1938 if k not in message_dict 

1939 } 

1940 

1941 def __call__( 

1942 self, 

1943 request: firestore.UpdateDocumentRequest, 

1944 *, 

1945 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1946 timeout: Optional[float] = None, 

1947 metadata: Sequence[Tuple[str, str]] = (), 

1948 ) -> gf_document.Document: 

1949 r"""Call the update document method over HTTP. 

1950 

1951 Args: 

1952 request (~.firestore.UpdateDocumentRequest): 

1953 The request object. The request for 

1954 [Firestore.UpdateDocument][google.firestore.v1.Firestore.UpdateDocument]. 

1955 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1956 should be retried. 

1957 timeout (float): The timeout for this request. 

1958 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1959 sent along with the request as metadata. 

1960 

1961 Returns: 

1962 ~.gf_document.Document: 

1963 A Firestore document. 

1964 

1965 Must not exceed 1 MiB - 4 bytes. 

1966 

1967 """ 

1968 

1969 http_options: List[Dict[str, str]] = [ 

1970 { 

1971 "method": "patch", 

1972 "uri": "/v1/{document.name=projects/*/databases/*/documents/*/**}", 

1973 "body": "document", 

1974 }, 

1975 ] 

1976 request, metadata = self._interceptor.pre_update_document(request, metadata) 

1977 pb_request = firestore.UpdateDocumentRequest.pb(request) 

1978 transcoded_request = path_template.transcode(http_options, pb_request) 

1979 

1980 # Jsonify the request body 

1981 

1982 body = json_format.MessageToJson( 

1983 transcoded_request["body"], 

1984 including_default_value_fields=False, 

1985 use_integers_for_enums=True, 

1986 ) 

1987 uri = transcoded_request["uri"] 

1988 method = transcoded_request["method"] 

1989 

1990 # Jsonify the query params 

1991 query_params = json.loads( 

1992 json_format.MessageToJson( 

1993 transcoded_request["query_params"], 

1994 including_default_value_fields=False, 

1995 use_integers_for_enums=True, 

1996 ) 

1997 ) 

1998 query_params.update(self._get_unset_required_fields(query_params)) 

1999 

2000 query_params["$alt"] = "json;enum-encoding=int" 

2001 

2002 # Send the request 

2003 headers = dict(metadata) 

2004 headers["Content-Type"] = "application/json" 

2005 response = getattr(self._session, method)( 

2006 "{host}{uri}".format(host=self._host, uri=uri), 

2007 timeout=timeout, 

2008 headers=headers, 

2009 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2010 data=body, 

2011 ) 

2012 

2013 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2014 # subclass. 

2015 if response.status_code >= 400: 

2016 raise core_exceptions.from_http_response(response) 

2017 

2018 # Return the response 

2019 resp = gf_document.Document() 

2020 pb_resp = gf_document.Document.pb(resp) 

2021 

2022 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2023 resp = self._interceptor.post_update_document(resp) 

2024 return resp 

2025 

2026 class _Write(FirestoreRestStub): 

2027 def __hash__(self): 

2028 return hash("Write") 

2029 

2030 def __call__( 

2031 self, 

2032 request: firestore.WriteRequest, 

2033 *, 

2034 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2035 timeout: Optional[float] = None, 

2036 metadata: Sequence[Tuple[str, str]] = (), 

2037 ) -> rest_streaming.ResponseIterator: 

2038 raise NotImplementedError( 

2039 "Method Write is not available over REST transport" 

2040 ) 

2041 

2042 @property 

2043 def batch_get_documents( 

2044 self, 

2045 ) -> Callable[ 

2046 [firestore.BatchGetDocumentsRequest], firestore.BatchGetDocumentsResponse 

2047 ]: 

2048 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2049 # In C++ this would require a dynamic_cast 

2050 return self._BatchGetDocuments(self._session, self._host, self._interceptor) # type: ignore 

2051 

2052 @property 

2053 def batch_write( 

2054 self, 

2055 ) -> Callable[[firestore.BatchWriteRequest], firestore.BatchWriteResponse]: 

2056 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2057 # In C++ this would require a dynamic_cast 

2058 return self._BatchWrite(self._session, self._host, self._interceptor) # type: ignore 

2059 

2060 @property 

2061 def begin_transaction( 

2062 self, 

2063 ) -> Callable[ 

2064 [firestore.BeginTransactionRequest], firestore.BeginTransactionResponse 

2065 ]: 

2066 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2067 # In C++ this would require a dynamic_cast 

2068 return self._BeginTransaction(self._session, self._host, self._interceptor) # type: ignore 

2069 

2070 @property 

2071 def commit(self) -> Callable[[firestore.CommitRequest], firestore.CommitResponse]: 

2072 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2073 # In C++ this would require a dynamic_cast 

2074 return self._Commit(self._session, self._host, self._interceptor) # type: ignore 

2075 

2076 @property 

2077 def create_document( 

2078 self, 

2079 ) -> Callable[[firestore.CreateDocumentRequest], document.Document]: 

2080 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2081 # In C++ this would require a dynamic_cast 

2082 return self._CreateDocument(self._session, self._host, self._interceptor) # type: ignore 

2083 

2084 @property 

2085 def delete_document( 

2086 self, 

2087 ) -> Callable[[firestore.DeleteDocumentRequest], empty_pb2.Empty]: 

2088 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2089 # In C++ this would require a dynamic_cast 

2090 return self._DeleteDocument(self._session, self._host, self._interceptor) # type: ignore 

2091 

2092 @property 

2093 def get_document( 

2094 self, 

2095 ) -> Callable[[firestore.GetDocumentRequest], document.Document]: 

2096 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2097 # In C++ this would require a dynamic_cast 

2098 return self._GetDocument(self._session, self._host, self._interceptor) # type: ignore 

2099 

2100 @property 

2101 def list_collection_ids( 

2102 self, 

2103 ) -> Callable[ 

2104 [firestore.ListCollectionIdsRequest], firestore.ListCollectionIdsResponse 

2105 ]: 

2106 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2107 # In C++ this would require a dynamic_cast 

2108 return self._ListCollectionIds(self._session, self._host, self._interceptor) # type: ignore 

2109 

2110 @property 

2111 def list_documents( 

2112 self, 

2113 ) -> Callable[[firestore.ListDocumentsRequest], firestore.ListDocumentsResponse]: 

2114 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2115 # In C++ this would require a dynamic_cast 

2116 return self._ListDocuments(self._session, self._host, self._interceptor) # type: ignore 

2117 

2118 @property 

2119 def listen(self) -> Callable[[firestore.ListenRequest], firestore.ListenResponse]: 

2120 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2121 # In C++ this would require a dynamic_cast 

2122 return self._Listen(self._session, self._host, self._interceptor) # type: ignore 

2123 

2124 @property 

2125 def partition_query( 

2126 self, 

2127 ) -> Callable[[firestore.PartitionQueryRequest], firestore.PartitionQueryResponse]: 

2128 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2129 # In C++ this would require a dynamic_cast 

2130 return self._PartitionQuery(self._session, self._host, self._interceptor) # type: ignore 

2131 

2132 @property 

2133 def rollback(self) -> Callable[[firestore.RollbackRequest], empty_pb2.Empty]: 

2134 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2135 # In C++ this would require a dynamic_cast 

2136 return self._Rollback(self._session, self._host, self._interceptor) # type: ignore 

2137 

2138 @property 

2139 def run_aggregation_query( 

2140 self, 

2141 ) -> Callable[ 

2142 [firestore.RunAggregationQueryRequest], firestore.RunAggregationQueryResponse 

2143 ]: 

2144 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2145 # In C++ this would require a dynamic_cast 

2146 return self._RunAggregationQuery(self._session, self._host, self._interceptor) # type: ignore 

2147 

2148 @property 

2149 def run_query( 

2150 self, 

2151 ) -> Callable[[firestore.RunQueryRequest], firestore.RunQueryResponse]: 

2152 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2153 # In C++ this would require a dynamic_cast 

2154 return self._RunQuery(self._session, self._host, self._interceptor) # type: ignore 

2155 

2156 @property 

2157 def update_document( 

2158 self, 

2159 ) -> Callable[[firestore.UpdateDocumentRequest], gf_document.Document]: 

2160 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2161 # In C++ this would require a dynamic_cast 

2162 return self._UpdateDocument(self._session, self._host, self._interceptor) # type: ignore 

2163 

2164 @property 

2165 def write(self) -> Callable[[firestore.WriteRequest], firestore.WriteResponse]: 

2166 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2167 # In C++ this would require a dynamic_cast 

2168 return self._Write(self._session, self._host, self._interceptor) # type: ignore 

2169 

2170 @property 

2171 def cancel_operation(self): 

2172 return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore 

2173 

2174 class _CancelOperation(FirestoreRestStub): 

2175 def __call__( 

2176 self, 

2177 request: operations_pb2.CancelOperationRequest, 

2178 *, 

2179 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2180 timeout: Optional[float] = None, 

2181 metadata: Sequence[Tuple[str, str]] = (), 

2182 ) -> None: 

2183 r"""Call the cancel operation method over HTTP. 

2184 

2185 Args: 

2186 request (operations_pb2.CancelOperationRequest): 

2187 The request object for CancelOperation method. 

2188 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2189 should be retried. 

2190 timeout (float): The timeout for this request. 

2191 metadata (Sequence[Tuple[str, str]]): Strings which should be 

2192 sent along with the request as metadata. 

2193 """ 

2194 

2195 http_options: List[Dict[str, str]] = [ 

2196 { 

2197 "method": "post", 

2198 "uri": "/v1/{name=projects/*/databases/*/operations/*}:cancel", 

2199 "body": "*", 

2200 }, 

2201 ] 

2202 

2203 request, metadata = self._interceptor.pre_cancel_operation( 

2204 request, metadata 

2205 ) 

2206 request_kwargs = json_format.MessageToDict(request) 

2207 transcoded_request = path_template.transcode(http_options, **request_kwargs) 

2208 

2209 body = json.dumps(transcoded_request["body"]) 

2210 uri = transcoded_request["uri"] 

2211 method = transcoded_request["method"] 

2212 

2213 # Jsonify the query params 

2214 query_params = json.loads(json.dumps(transcoded_request["query_params"])) 

2215 

2216 # Send the request 

2217 headers = dict(metadata) 

2218 headers["Content-Type"] = "application/json" 

2219 

2220 response = getattr(self._session, method)( 

2221 "{host}{uri}".format(host=self._host, uri=uri), 

2222 timeout=timeout, 

2223 headers=headers, 

2224 params=rest_helpers.flatten_query_params(query_params), 

2225 data=body, 

2226 ) 

2227 

2228 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2229 # subclass. 

2230 if response.status_code >= 400: 

2231 raise core_exceptions.from_http_response(response) 

2232 

2233 return self._interceptor.post_cancel_operation(None) 

2234 

2235 @property 

2236 def delete_operation(self): 

2237 return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore 

2238 

2239 class _DeleteOperation(FirestoreRestStub): 

2240 def __call__( 

2241 self, 

2242 request: operations_pb2.DeleteOperationRequest, 

2243 *, 

2244 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2245 timeout: Optional[float] = None, 

2246 metadata: Sequence[Tuple[str, str]] = (), 

2247 ) -> None: 

2248 r"""Call the delete operation method over HTTP. 

2249 

2250 Args: 

2251 request (operations_pb2.DeleteOperationRequest): 

2252 The request object for DeleteOperation method. 

2253 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2254 should be retried. 

2255 timeout (float): The timeout for this request. 

2256 metadata (Sequence[Tuple[str, str]]): Strings which should be 

2257 sent along with the request as metadata. 

2258 """ 

2259 

2260 http_options: List[Dict[str, str]] = [ 

2261 { 

2262 "method": "delete", 

2263 "uri": "/v1/{name=projects/*/databases/*/operations/*}", 

2264 }, 

2265 ] 

2266 

2267 request, metadata = self._interceptor.pre_delete_operation( 

2268 request, metadata 

2269 ) 

2270 request_kwargs = json_format.MessageToDict(request) 

2271 transcoded_request = path_template.transcode(http_options, **request_kwargs) 

2272 

2273 uri = transcoded_request["uri"] 

2274 method = transcoded_request["method"] 

2275 

2276 # Jsonify the query params 

2277 query_params = json.loads(json.dumps(transcoded_request["query_params"])) 

2278 

2279 # Send the request 

2280 headers = dict(metadata) 

2281 headers["Content-Type"] = "application/json" 

2282 

2283 response = getattr(self._session, method)( 

2284 "{host}{uri}".format(host=self._host, uri=uri), 

2285 timeout=timeout, 

2286 headers=headers, 

2287 params=rest_helpers.flatten_query_params(query_params), 

2288 ) 

2289 

2290 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2291 # subclass. 

2292 if response.status_code >= 400: 

2293 raise core_exceptions.from_http_response(response) 

2294 

2295 return self._interceptor.post_delete_operation(None) 

2296 

2297 @property 

2298 def get_operation(self): 

2299 return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore 

2300 

2301 class _GetOperation(FirestoreRestStub): 

2302 def __call__( 

2303 self, 

2304 request: operations_pb2.GetOperationRequest, 

2305 *, 

2306 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2307 timeout: Optional[float] = None, 

2308 metadata: Sequence[Tuple[str, str]] = (), 

2309 ) -> operations_pb2.Operation: 

2310 r"""Call the get operation method over HTTP. 

2311 

2312 Args: 

2313 request (operations_pb2.GetOperationRequest): 

2314 The request object for GetOperation method. 

2315 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2316 should be retried. 

2317 timeout (float): The timeout for this request. 

2318 metadata (Sequence[Tuple[str, str]]): Strings which should be 

2319 sent along with the request as metadata. 

2320 

2321 Returns: 

2322 operations_pb2.Operation: Response from GetOperation method. 

2323 """ 

2324 

2325 http_options: List[Dict[str, str]] = [ 

2326 { 

2327 "method": "get", 

2328 "uri": "/v1/{name=projects/*/databases/*/operations/*}", 

2329 }, 

2330 ] 

2331 

2332 request, metadata = self._interceptor.pre_get_operation(request, metadata) 

2333 request_kwargs = json_format.MessageToDict(request) 

2334 transcoded_request = path_template.transcode(http_options, **request_kwargs) 

2335 

2336 uri = transcoded_request["uri"] 

2337 method = transcoded_request["method"] 

2338 

2339 # Jsonify the query params 

2340 query_params = json.loads(json.dumps(transcoded_request["query_params"])) 

2341 

2342 # Send the request 

2343 headers = dict(metadata) 

2344 headers["Content-Type"] = "application/json" 

2345 

2346 response = getattr(self._session, method)( 

2347 "{host}{uri}".format(host=self._host, uri=uri), 

2348 timeout=timeout, 

2349 headers=headers, 

2350 params=rest_helpers.flatten_query_params(query_params), 

2351 ) 

2352 

2353 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2354 # subclass. 

2355 if response.status_code >= 400: 

2356 raise core_exceptions.from_http_response(response) 

2357 

2358 resp = operations_pb2.Operation() 

2359 resp = json_format.Parse(response.content.decode("utf-8"), resp) 

2360 resp = self._interceptor.post_get_operation(resp) 

2361 return resp 

2362 

2363 @property 

2364 def list_operations(self): 

2365 return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore 

2366 

2367 class _ListOperations(FirestoreRestStub): 

2368 def __call__( 

2369 self, 

2370 request: operations_pb2.ListOperationsRequest, 

2371 *, 

2372 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2373 timeout: Optional[float] = None, 

2374 metadata: Sequence[Tuple[str, str]] = (), 

2375 ) -> operations_pb2.ListOperationsResponse: 

2376 r"""Call the list operations method over HTTP. 

2377 

2378 Args: 

2379 request (operations_pb2.ListOperationsRequest): 

2380 The request object for ListOperations method. 

2381 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2382 should be retried. 

2383 timeout (float): The timeout for this request. 

2384 metadata (Sequence[Tuple[str, str]]): Strings which should be 

2385 sent along with the request as metadata. 

2386 

2387 Returns: 

2388 operations_pb2.ListOperationsResponse: Response from ListOperations method. 

2389 """ 

2390 

2391 http_options: List[Dict[str, str]] = [ 

2392 { 

2393 "method": "get", 

2394 "uri": "/v1/{name=projects/*/databases/*}/operations", 

2395 }, 

2396 ] 

2397 

2398 request, metadata = self._interceptor.pre_list_operations(request, metadata) 

2399 request_kwargs = json_format.MessageToDict(request) 

2400 transcoded_request = path_template.transcode(http_options, **request_kwargs) 

2401 

2402 uri = transcoded_request["uri"] 

2403 method = transcoded_request["method"] 

2404 

2405 # Jsonify the query params 

2406 query_params = json.loads(json.dumps(transcoded_request["query_params"])) 

2407 

2408 # Send the request 

2409 headers = dict(metadata) 

2410 headers["Content-Type"] = "application/json" 

2411 

2412 response = getattr(self._session, method)( 

2413 "{host}{uri}".format(host=self._host, uri=uri), 

2414 timeout=timeout, 

2415 headers=headers, 

2416 params=rest_helpers.flatten_query_params(query_params), 

2417 ) 

2418 

2419 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2420 # subclass. 

2421 if response.status_code >= 400: 

2422 raise core_exceptions.from_http_response(response) 

2423 

2424 resp = operations_pb2.ListOperationsResponse() 

2425 resp = json_format.Parse(response.content.decode("utf-8"), resp) 

2426 resp = self._interceptor.post_list_operations(resp) 

2427 return resp 

2428 

2429 @property 

2430 def kind(self) -> str: 

2431 return "rest" 

2432 

2433 def close(self): 

2434 self._session.close() 

2435 

2436 

2437__all__ = ("FirestoreRestTransport",)