diff --git a/firestore/docs/conf.py b/firestore/docs/conf.py new file mode 100644 index 000000000000..08dafcb41e4d --- /dev/null +++ b/firestore/docs/conf.py @@ -0,0 +1,310 @@ +# -*- coding: utf-8 -*- +# +# google-cloud-firestore documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('..')) + +__version__ = '0.1.0' + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', + 'sphinx.ext.intersphinx', + 'sphinx.ext.coverage', + 'sphinx.ext.napoleon', + 'sphinx.ext.viewcode', +] + +# autodoc/autosummary flags +autoclass_content = 'both' +autodoc_default_flags = ['members'] +autosummary_generate = True + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'google-cloud-firestore' +copyright = u'2017, Google' +author = u'Google APIs' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = '.'.join(release.split('.')[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'sphinx_rtd_theme' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = [] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'google-cloud-firestore-doc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + #'preamble': '', + + # Latex figure (float) alignment + #'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'google-cloud-firestore.tex', + u'google-cloud-firestore Documentation', author, 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [(master_doc, 'google-cloud-firestore', + u'google-cloud-firestore Documentation', [author], 1)] + +# If true, show URL addresses after external links. +#man_show_urls = False + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'google-cloud-firestore', + u'google-cloud-firestore Documentation', author, 'google-cloud-firestore', + 'GAPIC library for the {metadata.shortName} v1beta1 service', 'APIs'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + 'python': ('http://python.readthedocs.org/en/latest/', None), + 'gax': ('https://gax-python.readthedocs.org/en/latest/', None), +} + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/firestore/docs/gapic/v1beta1/api.rst b/firestore/docs/gapic/v1beta1/api.rst new file mode 100644 index 000000000000..56607e2b98ac --- /dev/null +++ b/firestore/docs/gapic/v1beta1/api.rst @@ -0,0 +1,6 @@ +Client for Google Cloud Firestore API +===================================== + +.. automodule:: google.cloud.firestore_v1beta1 + :members: + :inherited-members: \ No newline at end of file diff --git a/firestore/docs/gapic/v1beta1/types.rst b/firestore/docs/gapic/v1beta1/types.rst new file mode 100644 index 000000000000..ae3740065ccc --- /dev/null +++ b/firestore/docs/gapic/v1beta1/types.rst @@ -0,0 +1,5 @@ +Types for Google Cloud Firestore API Client +=========================================== + +.. automodule:: google.cloud.firestore_v1beta1.types + :members: \ No newline at end of file diff --git a/firestore/docs/index.rst b/firestore/docs/index.rst new file mode 100644 index 000000000000..236c52073c7f --- /dev/null +++ b/firestore/docs/index.rst @@ -0,0 +1,83 @@ +Python Client for Google Cloud Firestore API (`Alpha`_) +======================================================= + +`Google Cloud Firestore API`_: + +- `Client Library Documentation`_ +- `Product Documentation`_ + +.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst +.. _Google Cloud Firestore API: https://cloud.google.com/firestore +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/firestore/usage.html +.. _Product Documentation: https://cloud.google.com/firestore + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. `Enable the Google Cloud Firestore API.`_ +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Enable the Google Cloud Firestore API.: https://cloud.google.com/firestore +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + source /bin/activate + /bin/pip install google-cloud-firestore + + +Windows +^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + \Scripts\activate + \Scripts\pip.exe install google-cloud-firestore + +Next Steps +~~~~~~~~~~ + +- Read the `Client Library Documentation`_ for Google Cloud Firestore API + API to see other available methods on the client. +- Read the `Google Cloud Firestore API Product documentation`_ to learn + more about the product and see How-to Guides. +- View this `repository’s main README`_ to see the full list of Cloud + APIs that we cover. + +.. _Google Cloud Firestore API Product documentation: https://cloud.google.com/firestore +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst + +Api Reference +------------- +.. toctree:: + :maxdepth: 2 + + gapic/v1beta1/api + gapic/v1beta1/types \ No newline at end of file diff --git a/firestore/google/cloud/firestore_v1beta1/__init__.py b/firestore/google/cloud/firestore_v1beta1/__init__.py index e0069d68dc0d..ef882e73f291 100644 --- a/firestore/google/cloud/firestore_v1beta1/__init__.py +++ b/firestore/google/cloud/firestore_v1beta1/__init__.py @@ -1,10 +1,10 @@ -# Copyright 2017 Google LLC All rights reserved. +# Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -12,12 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import + +from google.cloud.firestore_v1beta1 import types +from google.cloud.firestore_v1beta1.gapic import enums +from google.cloud.firestore_v1beta1.gapic import firestore_client + + """Python idiomatic client for Google Cloud Firestore.""" from pkg_resources import get_distribution __version__ = get_distribution('google-cloud-firestore').version - -from google.cloud.firestore_v1beta1 import types + from google.cloud.firestore_v1beta1._helpers import GeoPoint from google.cloud.firestore_v1beta1._helpers import ReadAfterWriteError from google.cloud.firestore_v1beta1.batch import WriteBatch @@ -31,17 +37,19 @@ from google.cloud.firestore_v1beta1.constants import SERVER_TIMESTAMP from google.cloud.firestore_v1beta1.document import DocumentReference from google.cloud.firestore_v1beta1.document import DocumentSnapshot -from google.cloud.firestore_v1beta1.gapic import enums from google.cloud.firestore_v1beta1.gapic import firestore_admin_client from google.cloud.firestore_v1beta1.query import Query from google.cloud.firestore_v1beta1.transaction import Transaction from google.cloud.firestore_v1beta1.transaction import transactional - - + + AdminClient = firestore_admin_client.FirestoreAdminClient +class FirestoreClient(firestore_client.FirestoreClient): + __doc__ = firestore_client.FirestoreClient.__doc__ + enums = enums -__all__ = [ +__all__ = ( '__version__', 'AdminClient', 'Client', @@ -62,4 +70,4 @@ 'types', 'WriteBatch', 'WriteOption', -] +) diff --git a/firestore/google/cloud/firestore_v1beta1/_helpers.py b/firestore/google/cloud/firestore_v1beta1/_helpers.py index 3acda674b7dc..5dcbef262fc5 100644 --- a/firestore/google/cloud/firestore_v1beta1/_helpers.py +++ b/firestore/google/cloud/firestore_v1beta1/_helpers.py @@ -20,9 +20,6 @@ import datetime import sys -import google.gax -import google.gax.errors -import google.gax.grpc from google.protobuf import struct_pb2 from google.type import latlng_pb2 import grpc @@ -932,35 +929,3 @@ def get_transaction_id(transaction, read_operation=True): return transaction.id -@contextlib.contextmanager -def remap_gax_error_on_commit(): - """Remap GAX exceptions that happen in context. - - Remaps gRPC exceptions that can occur during the ``Comitt`` RPC to - the classes defined in :mod:`~google.cloud.exceptions`. - """ - try: - yield - except google.gax.errors.GaxError as exc: - status_code = google.gax.grpc.exc_to_code(exc.cause) - error_class = _GRPC_ERROR_MAPPING.get(status_code) - if error_class is None: - raise - else: - new_exc = error_class(exc.cause.details()) - six.reraise(error_class, new_exc, sys.exc_info()[2]) - - -def options_with_prefix(database_string): - """Create GAPIC options w / cloud resource prefix. - - Args: - database_string (str): A database string of the form - ``projects/{project_id}/databases/{database_id}``. - - Returns: - ~google.gax.CallOptions: GAPIC call options with supplied prefix. - """ - return google.gax.CallOptions( - metadata=[('google-cloud-resource-prefix', database_string)], - ) diff --git a/firestore/google/cloud/firestore_v1beta1/batch.py b/firestore/google/cloud/firestore_v1beta1/batch.py index 3263e0253f82..6f2331064b0d 100644 --- a/firestore/google/cloud/firestore_v1beta1/batch.py +++ b/firestore/google/cloud/firestore_v1beta1/batch.py @@ -129,10 +129,9 @@ def commit(self): changes were applied to this batch. A write result contains an ``update_time`` field. """ - with _helpers.remap_gax_error_on_commit(): - commit_response = self._client._firestore_api.commit( - self._client._database_string, self._write_pbs, - transaction=None, options=self._client._call_options) + commit_response = self._client._firestore_api.commit( + self._client._database_string, self._write_pbs, + transaction=None) self._write_pbs = [] return list(commit_response.write_results) diff --git a/firestore/google/cloud/firestore_v1beta1/client.py b/firestore/google/cloud/firestore_v1beta1/client.py index d19898bbb652..1f4a80866fec 100644 --- a/firestore/google/cloud/firestore_v1beta1/client.py +++ b/firestore/google/cloud/firestore_v1beta1/client.py @@ -127,20 +127,6 @@ def _database_string(self): return self._database_string_internal - @property - def _call_options(self): - """The call options for this client's associated database. - - Returns: - ~google.gax.CallOptions: GAPIC call options with a resource prefix - for the database associated with this client. - """ - if self._call_options_internal is None: - self._call_options_internal = _helpers.options_with_prefix( - self._database_string) - - return self._call_options_internal - def collection(self, *collection_path): """Get a reference to a collection. @@ -332,8 +318,7 @@ def get_all(self, references, field_paths=None, transaction=None): mask = _get_doc_mask(field_paths) response_iterator = self._firestore_api.batch_get_documents( self._database_string, document_paths, mask, - transaction=_helpers.get_transaction_id(transaction), - options=self._call_options) + transaction=_helpers.get_transaction_id(transaction)) for get_doc_response in response_iterator: yield _parse_batch_get(get_doc_response, reference_map, self) @@ -532,8 +517,7 @@ def _make_firestore_api(client): host = firestore_client.FirestoreClient.SERVICE_ADDRESS channel = make_secure_channel( client._credentials, DEFAULT_USER_AGENT, host) - return firestore_client.FirestoreClient( - channel=channel, lib_name='gccl', lib_version=__version__) + return firestore_client.FirestoreClient(channel=channel) def _reference_info(references): diff --git a/firestore/google/cloud/firestore_v1beta1/collection.py b/firestore/google/cloud/firestore_v1beta1/collection.py index 9c87b622c7f2..c285c5da7374 100644 --- a/firestore/google/cloud/firestore_v1beta1/collection.py +++ b/firestore/google/cloud/firestore_v1beta1/collection.py @@ -161,8 +161,7 @@ def add(self, document_data, document_id=None): created_document_pb = self._client._firestore_api.create_document( parent_path, collection_id=self.id, document_id=None, - document=document_pb, mask=None, - options=self._client._call_options) + document=document_pb, mask=None) new_document_id = _helpers.get_doc_id( created_document_pb, expected_prefix) diff --git a/firestore/google/cloud/firestore_v1beta1/document.py b/firestore/google/cloud/firestore_v1beta1/document.py index 3ba6a4a82ca3..09dd17f77100 100644 --- a/firestore/google/cloud/firestore_v1beta1/document.py +++ b/firestore/google/cloud/firestore_v1beta1/document.py @@ -392,10 +392,8 @@ def delete(self, option=None): ValueError: If the ``create_if_missing`` write option is used. """ write_pb = _helpers.pb_for_delete(self._document_path, option) - with _helpers.remap_gax_error_on_commit(): - commit_response = self._client._firestore_api.commit( - self._client._database_string, [write_pb], transaction=None, - options=self._client._call_options) + commit_response = self._client._firestore_api.commit( + self._client._database_string, [write_pb], transaction=None) return commit_response.commit_time diff --git a/firestore/google/cloud/firestore_v1beta1/gapic/enums.py b/firestore/google/cloud/firestore_v1beta1/gapic/enums.py index a591dc58424c..ff829a1c3563 100644 --- a/firestore/google/cloud/firestore_v1beta1/gapic/enums.py +++ b/firestore/google/cloud/firestore_v1beta1/gapic/enums.py @@ -1,10 +1,10 @@ -# Copyright 2017, Google LLC All rights reserved. +# Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -27,79 +27,6 @@ class NullValue(object): NULL_VALUE = 0 -class IndexField(object): - class Mode(object): - """ - The mode determines how a field is indexed. - - Attributes: - MODE_UNSPECIFIED (int): The mode is unspecified. - ASCENDING (int): The field's values are indexed so as to support sequencing in - ascending order and also query by <, >, <=, >=, and =. - DESCENDING (int): The field's values are indexed so as to support sequencing in - descending order and also query by <, >, <=, >=, and =. - """ - MODE_UNSPECIFIED = 0 - ASCENDING = 2 - DESCENDING = 3 - - -class Index(object): - class State(object): - """ - The state of an index. During index creation, an index will be in the - ``CREATING`` state. If the index is created successfully, it will transition - to the ``READY`` state. If the index is not able to be created, it will - transition to the ``ERROR`` state. - - Attributes: - STATE_UNSPECIFIED (int): The state is unspecified. - CREATING (int): The index is being created. - There is an active long-running operation for the index. - The index is updated when writing a document. - Some index data may exist. - READY (int): The index is ready to be used. - The index is updated when writing a document. - The index is fully populated from all stored documents it applies to. - ERROR (int): The index was being created, but something went wrong. - There is no active long-running operation for the index, - and the most recently finished long-running operation failed. - The index is not updated when writing a document. - Some index data may exist. - """ - STATE_UNSPECIFIED = 0 - CREATING = 3 - READY = 2 - ERROR = 5 - - -class IndexOperationMetadata(object): - class OperationType(object): - """ - The type of index operation. - - Attributes: - OPERATION_TYPE_UNSPECIFIED (int): Unspecified. Never set by server. - CREATING_INDEX (int): The operation is creating the index. Initiated by a ``CreateIndex`` call. - """ - OPERATION_TYPE_UNSPECIFIED = 0 - CREATING_INDEX = 1 - - -class DocumentTransform(object): - class FieldTransform(object): - class ServerValue(object): - """ - A value that is calculated by the server. - - Attributes: - SERVER_VALUE_UNSPECIFIED (int): Unspecified. This value must not be used. - REQUEST_TIME (int): The time at which the server processed the request. - """ - SERVER_VALUE_UNSPECIFIED = 0 - REQUEST_TIME = 1 - - class StructuredQuery(object): class Direction(object): """ @@ -162,6 +89,21 @@ class Operator(object): IS_NULL = 3 +class DocumentTransform(object): + class FieldTransform(object): + class ServerValue(object): + """ + A value that is calculated by the server. + + Attributes: + SERVER_VALUE_UNSPECIFIED (int): Unspecified. This value must not be used. + REQUEST_TIME (int): The time at which the server processed the request, with millisecond + precision. + """ + SERVER_VALUE_UNSPECIFIED = 0 + REQUEST_TIME = 1 + + class TargetChange(object): class TargetChangeType(object): """ diff --git a/firestore/google/cloud/firestore_v1beta1/gapic/firestore_admin_client.py b/firestore/google/cloud/firestore_v1beta1/gapic/firestore_admin_client.py index 4f3d89a119a7..b99435dd79f1 100644 --- a/firestore/google/cloud/firestore_v1beta1/gapic/firestore_admin_client.py +++ b/firestore/google/cloud/firestore_v1beta1/gapic/firestore_admin_client.py @@ -28,18 +28,12 @@ import pkg_resources import platform -from google.gax import api_callable -from google.gax import config -from google.gax import path_template -import google.gax from google.cloud.firestore_v1beta1.gapic import enums from google.cloud.firestore_v1beta1.gapic import firestore_admin_client_config from google.cloud.firestore_v1beta1.proto.admin import firestore_admin_pb2 from google.cloud.firestore_v1beta1.proto.admin import index_pb2 -_PageDesc = google.gax.PageDescriptor - class FirestoreAdminClient(object): """ @@ -94,25 +88,19 @@ class FirestoreAdminClient(object): DEFAULT_SERVICE_PORT = 443 """The default port of the service.""" - _PAGE_DESCRIPTORS = { - 'list_indexes': _PageDesc('page_token', 'next_page_token', 'indexes') - } - # The scopes needed to make gRPC calls to all of the methods defined in # this service _ALL_SCOPES = ( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/datastore', ) - _DATABASE_PATH_TEMPLATE = path_template.PathTemplate( - 'projects/{project}/databases/{database}') - _INDEX_PATH_TEMPLATE = path_template.PathTemplate( - 'projects/{project}/databases/{database}/indexes/{index}') + _DATABASE_PATH_TEMPLATE = 'projects/{project}/databases/{database}' + _INDEX_PATH_TEMPLATE = 'projects/{project}/databases/{database}/indexes/{index}' @classmethod def database_path(cls, project, database): """Returns a fully-qualified database resource name string.""" - return cls._DATABASE_PATH_TEMPLATE.render({ + return cls._DATABASE_PATH_TEMPLATE.format({ 'project': project, 'database': database, }) @@ -120,7 +108,7 @@ def database_path(cls, project, database): @classmethod def index_path(cls, project, database, index): """Returns a fully-qualified index resource name string.""" - return cls._INDEX_PATH_TEMPLATE.render({ + return cls._INDEX_PATH_TEMPLATE.format({ 'project': project, 'database': database, 'index': index, @@ -258,8 +246,7 @@ def __init__(self, firestore_admin_client_config.config, client_config, config.STATUS_CODE_NAMES, - metrics_headers=metrics_headers, - page_descriptors=self._PAGE_DESCRIPTORS, ) + metrics_headers=metrics_headers) self.firestore_admin_stub = config.create_stub( firestore_admin_pb2.FirestoreAdminStub, channel=channel, diff --git a/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py b/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py index 22962913ce5a..65e4598e927f 100644 --- a/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py +++ b/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client.py @@ -1,38 +1,28 @@ -# Copyright 2017, Google LLC All rights reserved. +# Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -# EDITING INSTRUCTIONS -# This file was generated from the file -# https://github.com/google/googleapis/blob/master/google/firestore/v1beta1/firestore.proto, -# and updates to that file get reflected here through a refresh process. -# For the short term, the refresh process will only be runnable by Google engineers. -# -# The only allowed edits are to method and file documentation. A 3-way -# merge preserves those additions if the generated source changes. """Accesses the google.firestore.v1beta1 Firestore API.""" -import collections -import json -import os +import functools import pkg_resources -import platform -from google.gax import api_callable -from google.gax import config -from google.gax import path_template -from google.gax.utils import oneof -import google.gax +import google.api_core.gapic_v1.client_info +import google.api_core.gapic_v1.config +import google.api_core.gapic_v1.method +import google.api_core.grpc_helpers +import google.api_core.page_iterator +import google.api_core.path_template +import google.api_core.protobuf_helpers from google.cloud.firestore_v1beta1.gapic import enums from google.cloud.firestore_v1beta1.gapic import firestore_client_config @@ -41,11 +31,10 @@ from google.cloud.firestore_v1beta1.proto import firestore_pb2 from google.cloud.firestore_v1beta1.proto import query_pb2 from google.cloud.firestore_v1beta1.proto import write_pb2 -from google.cloud.firestore_v1beta1.proto.admin import firestore_admin_pb2 -from google.cloud.firestore_v1beta1.proto.admin import index_pb2 from google.protobuf import timestamp_pb2 -_PageDesc = google.gax.PageDescriptor +_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution( + 'google-cloud-firestore', ).version class FirestoreClient(object): @@ -76,334 +65,195 @@ class FirestoreClient(object): to see the effects of the transaction. """ - SERVICE_ADDRESS = 'firestore.googleapis.com' + SERVICE_ADDRESS = 'firestore.googleapis.com:443' """The default address of the service.""" - DEFAULT_SERVICE_PORT = 443 - """The default port of the service.""" - - _PAGE_DESCRIPTORS = { - 'list_documents': - _PageDesc('page_token', 'next_page_token', 'documents'), - 'list_collection_ids': - _PageDesc('page_token', 'next_page_token', 'collection_ids') - } - # The scopes needed to make gRPC calls to all of the methods defined in # this service - _ALL_SCOPES = ( + _DEFAULT_SCOPES = ( 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/datastore', ) - - _DATABASE_ROOT_PATH_TEMPLATE = path_template.PathTemplate( - 'projects/{project}/databases/{database}') - _DOCUMENT_ROOT_PATH_TEMPLATE = path_template.PathTemplate( - 'projects/{project}/databases/{database}/documents') - _DOCUMENT_PATH_PATH_TEMPLATE = path_template.PathTemplate( - 'projects/{project}/databases/{database}/documents/{document_path=**}') - _ANY_PATH_PATH_TEMPLATE = path_template.PathTemplate( - 'projects/{project}/databases/{database}/documents/{document}/{any_path=**}' + 'https://www.googleapis.com/auth/datastore', ) + # The name of the interface for this client. This is the key used to find + # method configuration in the client_config dictionary. + _INTERFACE_NAME = 'google.firestore.v1beta1.Firestore' + @classmethod def database_root_path(cls, project, database): - """Returns a fully-qualified database_root resource name string.""" - return cls._DATABASE_ROOT_PATH_TEMPLATE.render({ - 'project': project, - 'database': database, - }) + """Return a fully-qualified database_root string.""" + return google.api_core.path_template.expand( + 'projects/{project}/databases/{database}', + project=project, + database=database, + ) @classmethod def document_root_path(cls, project, database): - """Returns a fully-qualified document_root resource name string.""" - return cls._DOCUMENT_ROOT_PATH_TEMPLATE.render({ - 'project': project, - 'database': database, - }) + """Return a fully-qualified document_root string.""" + return google.api_core.path_template.expand( + 'projects/{project}/databases/{database}/documents', + project=project, + database=database, + ) @classmethod def document_path_path(cls, project, database, document_path): - """Returns a fully-qualified document_path resource name string.""" - return cls._DOCUMENT_PATH_PATH_TEMPLATE.render({ - 'project': - project, - 'database': - database, - 'document_path': - document_path, - }) + """Return a fully-qualified document_path string.""" + return google.api_core.path_template.expand( + 'projects/{project}/databases/{database}/documents/{document_path=**}', + project=project, + database=database, + document_path=document_path, + ) @classmethod def any_path_path(cls, project, database, document, any_path): - """Returns a fully-qualified any_path resource name string.""" - return cls._ANY_PATH_PATH_TEMPLATE.render({ - 'project': project, - 'database': database, - 'document': document, - 'any_path': any_path, - }) - - @classmethod - def match_project_from_database_root_name(cls, database_root_name): - """Parses the project from a database_root resource. - - Args: - database_root_name (str): A fully-qualified path representing a database_root - resource. - - Returns: - A string representing the project. - """ - return cls._DATABASE_ROOT_PATH_TEMPLATE.match(database_root_name).get( - 'project') - - @classmethod - def match_database_from_database_root_name(cls, database_root_name): - """Parses the database from a database_root resource. - - Args: - database_root_name (str): A fully-qualified path representing a database_root - resource. - - Returns: - A string representing the database. - """ - return cls._DATABASE_ROOT_PATH_TEMPLATE.match(database_root_name).get( - 'database') - - @classmethod - def match_project_from_document_root_name(cls, document_root_name): - """Parses the project from a document_root resource. - - Args: - document_root_name (str): A fully-qualified path representing a document_root - resource. - - Returns: - A string representing the project. - """ - return cls._DOCUMENT_ROOT_PATH_TEMPLATE.match(document_root_name).get( - 'project') - - @classmethod - def match_database_from_document_root_name(cls, document_root_name): - """Parses the database from a document_root resource. - - Args: - document_root_name (str): A fully-qualified path representing a document_root - resource. - - Returns: - A string representing the database. - """ - return cls._DOCUMENT_ROOT_PATH_TEMPLATE.match(document_root_name).get( - 'database') - - @classmethod - def match_project_from_document_path_name(cls, document_path_name): - """Parses the project from a document_path resource. - - Args: - document_path_name (str): A fully-qualified path representing a document_path - resource. - - Returns: - A string representing the project. - """ - return cls._DOCUMENT_PATH_PATH_TEMPLATE.match(document_path_name).get( - 'project') - - @classmethod - def match_database_from_document_path_name(cls, document_path_name): - """Parses the database from a document_path resource. - - Args: - document_path_name (str): A fully-qualified path representing a document_path - resource. - - Returns: - A string representing the database. - """ - return cls._DOCUMENT_PATH_PATH_TEMPLATE.match(document_path_name).get( - 'database') - - @classmethod - def match_document_path_from_document_path_name(cls, document_path_name): - """Parses the document_path from a document_path resource. - - Args: - document_path_name (str): A fully-qualified path representing a document_path - resource. - - Returns: - A string representing the document_path. - """ - return cls._DOCUMENT_PATH_PATH_TEMPLATE.match(document_path_name).get( - 'document_path') - - @classmethod - def match_project_from_any_path_name(cls, any_path_name): - """Parses the project from a any_path resource. - - Args: - any_path_name (str): A fully-qualified path representing a any_path - resource. - - Returns: - A string representing the project. - """ - return cls._ANY_PATH_PATH_TEMPLATE.match(any_path_name).get('project') - - @classmethod - def match_database_from_any_path_name(cls, any_path_name): - """Parses the database from a any_path resource. - - Args: - any_path_name (str): A fully-qualified path representing a any_path - resource. - - Returns: - A string representing the database. - """ - return cls._ANY_PATH_PATH_TEMPLATE.match(any_path_name).get('database') - - @classmethod - def match_document_from_any_path_name(cls, any_path_name): - """Parses the document from a any_path resource. - - Args: - any_path_name (str): A fully-qualified path representing a any_path - resource. - - Returns: - A string representing the document. - """ - return cls._ANY_PATH_PATH_TEMPLATE.match(any_path_name).get('document') - - @classmethod - def match_any_path_from_any_path_name(cls, any_path_name): - """Parses the any_path from a any_path resource. - - Args: - any_path_name (str): A fully-qualified path representing a any_path - resource. - - Returns: - A string representing the any_path. - """ - return cls._ANY_PATH_PATH_TEMPLATE.match(any_path_name).get('any_path') + """Return a fully-qualified any_path string.""" + return google.api_core.path_template.expand( + 'projects/{project}/databases/{database}/documents/{document}/{any_path=**}', + project=project, + database=database, + document=document, + any_path=any_path, + ) def __init__(self, channel=None, credentials=None, - ssl_credentials=None, - scopes=None, - client_config=None, - lib_name=None, - lib_version='', - metrics_headers=()): + client_config=firestore_client_config.config, + client_info=None): """Constructor. Args: - channel (~grpc.Channel): A ``Channel`` instance through - which to make calls. - credentials (~google.auth.credentials.Credentials): The authorization - credentials to attach to requests. These credentials identify this - application to the service. - ssl_credentials (~grpc.ChannelCredentials): A - ``ChannelCredentials`` instance for use with an SSL-enabled - channel. - scopes (Sequence[str]): A list of OAuth2 scopes to attach to requests. - client_config (dict): - A dictionary for call options for each method. See - :func:`google.gax.construct_settings` for the structure of - this data. Falls back to the default config if not specified - or the specified config is missing data points. - lib_name (str): The API library software used for calling - the service. (Unless you are writing an API client itself, - leave this as default.) - lib_version (str): The API library software version used - for calling the service. (Unless you are writing an API client - itself, leave this as default.) - metrics_headers (dict): A dictionary of values for tracking - client library metrics. Ultimately serializes to a string - (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be - considered private. + channel (grpc.Channel): A ``Channel`` instance through + which to make calls. This argument is mutually exclusive + with ``credentials``; providing both will raise an exception. + credentials (google.auth.credentials.Credentials): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If none + are specified, the client will attempt to ascertain the + credentials from the environment. + client_config (dict): A dictionary of call options for each + method. If not specified, the default configuration is used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. """ - # Unless the calling application specifically requested - # OAuth scopes, request everything. - if scopes is None: - scopes = self._ALL_SCOPES - - # Initialize an empty client config, if none is set. - if client_config is None: - client_config = {} - - # Initialize metrics_headers as an ordered dictionary - # (cuts down on cardinality of the resulting string slightly). - metrics_headers = collections.OrderedDict(metrics_headers) - metrics_headers['gl-python'] = platform.python_version() - - # The library may or may not be set, depending on what is - # calling this client. Newer client libraries set the library name - # and version. - if lib_name: - metrics_headers[lib_name] = lib_version - - # Finally, track the GAPIC package version. - metrics_headers['gapic'] = pkg_resources.get_distribution( - 'google-cloud-firestore', ).version - - # Load the configuration defaults. - defaults = api_callable.construct_settings( - 'google.firestore.v1beta1.Firestore', - firestore_client_config.config, - client_config, - config.STATUS_CODE_NAMES, - metrics_headers=metrics_headers, - page_descriptors=self._PAGE_DESCRIPTORS, ) - self.firestore_stub = config.create_stub( - firestore_pb2.FirestoreStub, - channel=channel, - service_path=self.SERVICE_ADDRESS, - service_port=self.DEFAULT_SERVICE_PORT, - credentials=credentials, - scopes=scopes, - ssl_credentials=ssl_credentials) - - self._get_document = api_callable.create_api_call( - self.firestore_stub.GetDocument, settings=defaults['get_document']) - self._list_documents = api_callable.create_api_call( + # If both `channel` and `credentials` are specified, raise an + # exception (channels come with credentials baked in already). + if channel is not None and credentials is not None: + raise ValueError( + 'The `channel` and `credentials` arguments to {} are mutually ' + 'exclusive.'.format(self.__class__.__name__), ) + + # Create the channel. + if channel is None: + channel = google.api_core.grpc_helpers.create_channel( + self.SERVICE_ADDRESS, + credentials=credentials, + scopes=self._DEFAULT_SCOPES, + ) + + # Create the gRPC stubs. + self.firestore_stub = (firestore_pb2.FirestoreStub(channel)) + + if client_info is None: + client_info = ( + google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO) + client_info.gapic_version = _GAPIC_LIBRARY_VERSION + + # Parse out the default settings for retry and timeout for each RPC + # from the client configuration. + # (Ordinarily, these are the defaults specified in the `*_config.py` + # file next to this one.) + method_configs = google.api_core.gapic_v1.config.parse_method_configs( + client_config['interfaces'][self._INTERFACE_NAME], ) + + # Write the "inner API call" methods to the class. + # These are wrapped versions of the gRPC stub methods, with retry and + # timeout configuration applied, called by the public methods on + # this class. + self._get_document = google.api_core.gapic_v1.method.wrap_method( + self.firestore_stub.GetDocument, + default_retry=method_configs['GetDocument'].retry, + default_timeout=method_configs['GetDocument'].timeout, + client_info=client_info, + ) + self._list_documents = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.ListDocuments, - settings=defaults['list_documents']) - self._create_document = api_callable.create_api_call( + default_retry=method_configs['ListDocuments'].retry, + default_timeout=method_configs['ListDocuments'].timeout, + client_info=client_info, + ) + self._create_document = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.CreateDocument, - settings=defaults['create_document']) - self._update_document = api_callable.create_api_call( + default_retry=method_configs['CreateDocument'].retry, + default_timeout=method_configs['CreateDocument'].timeout, + client_info=client_info, + ) + self._update_document = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.UpdateDocument, - settings=defaults['update_document']) - self._delete_document = api_callable.create_api_call( + default_retry=method_configs['UpdateDocument'].retry, + default_timeout=method_configs['UpdateDocument'].timeout, + client_info=client_info, + ) + self._delete_document = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.DeleteDocument, - settings=defaults['delete_document']) - self._batch_get_documents = api_callable.create_api_call( + default_retry=method_configs['DeleteDocument'].retry, + default_timeout=method_configs['DeleteDocument'].timeout, + client_info=client_info, + ) + self._batch_get_documents = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.BatchGetDocuments, - settings=defaults['batch_get_documents']) - self._begin_transaction = api_callable.create_api_call( + default_retry=method_configs['BatchGetDocuments'].retry, + default_timeout=method_configs['BatchGetDocuments'].timeout, + client_info=client_info, + ) + self._begin_transaction = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.BeginTransaction, - settings=defaults['begin_transaction']) - self._commit = api_callable.create_api_call( - self.firestore_stub.Commit, settings=defaults['commit']) - self._rollback = api_callable.create_api_call( - self.firestore_stub.Rollback, settings=defaults['rollback']) - self._run_query = api_callable.create_api_call( - self.firestore_stub.RunQuery, settings=defaults['run_query']) - self._write = api_callable.create_api_call( - self.firestore_stub.Write, settings=defaults['write']) - self._listen = api_callable.create_api_call( - self.firestore_stub.Listen, settings=defaults['listen']) - self._list_collection_ids = api_callable.create_api_call( + default_retry=method_configs['BeginTransaction'].retry, + default_timeout=method_configs['BeginTransaction'].timeout, + client_info=client_info, + ) + self._commit = google.api_core.gapic_v1.method.wrap_method( + self.firestore_stub.Commit, + default_retry=method_configs['Commit'].retry, + default_timeout=method_configs['Commit'].timeout, + client_info=client_info, + ) + self._rollback = google.api_core.gapic_v1.method.wrap_method( + self.firestore_stub.Rollback, + default_retry=method_configs['Rollback'].retry, + default_timeout=method_configs['Rollback'].timeout, + client_info=client_info, + ) + self._run_query = google.api_core.gapic_v1.method.wrap_method( + self.firestore_stub.RunQuery, + default_retry=method_configs['RunQuery'].retry, + default_timeout=method_configs['RunQuery'].timeout, + client_info=client_info, + ) + self._write = google.api_core.gapic_v1.method.wrap_method( + self.firestore_stub.Write, + default_retry=method_configs['Write'].retry, + default_timeout=method_configs['Write'].timeout, + client_info=client_info, + ) + self._listen = google.api_core.gapic_v1.method.wrap_method( + self.firestore_stub.Listen, + default_retry=method_configs['Listen'].retry, + default_timeout=method_configs['Listen'].timeout, + client_info=client_info, + ) + self._list_collection_ids = google.api_core.gapic_v1.method.wrap_method( self.firestore_stub.ListCollectionIds, - settings=defaults['list_collection_ids']) + default_retry=method_configs['ListCollectionIds'].retry, + default_timeout=method_configs['ListCollectionIds'].timeout, + client_info=client_info, + ) # Service calls def get_document(self, @@ -411,7 +261,9 @@ def get_document(self, mask=None, transaction=None, read_time=None, - options=None): + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Gets a single document. @@ -438,25 +290,43 @@ def get_document(self, This may not be older than 60 seconds. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.Timestamp` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.cloud.firestore_v1beta1.types.Document` instance. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) # Sanity check: We have some fields which are mutually exclusive; # raise ValueError if more than one is sent. - oneof.check_oneof( + google.api_core.protobuf_helpers.check_oneof( transaction=transaction, - read_time=read_time, ) + read_time=read_time, + ) request = firestore_pb2.GetDocumentRequest( - name=name, mask=mask, transaction=transaction, read_time=read_time) - return self._get_document(request, options) + name=name, + mask=mask, + transaction=transaction, + read_time=read_time, + ) + return self._get_document( + request, retry=retry, timeout=timeout, metadata=metadata) def list_documents(self, parent, @@ -467,13 +337,14 @@ def list_documents(self, transaction=None, read_time=None, show_missing=None, - options=None): + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Lists documents. Example: >>> from google.cloud import firestore_v1beta1 - >>> from google.gax import CallOptions, INITIAL_PAGE >>> >>> client = firestore_v1beta1.FirestoreClient() >>> @@ -525,8 +396,14 @@ def list_documents(self, Requests with ``show_missing`` may not specify ``where`` or ``order_by``. - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.gax.PageIterator` instance. By default, this @@ -535,14 +412,21 @@ def list_documents(self, of the response through the `options` parameter. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) # Sanity check: We have some fields which are mutually exclusive; # raise ValueError if more than one is sent. - oneof.check_oneof( + google.api_core.protobuf_helpers.check_oneof( transaction=transaction, - read_time=read_time, ) + read_time=read_time, + ) request = firestore_pb2.ListDocumentsRequest( parent=parent, @@ -552,8 +436,21 @@ def list_documents(self, mask=mask, transaction=transaction, read_time=read_time, - show_missing=show_missing) - return self._list_documents(request, options) + show_missing=show_missing, + ) + iterator = google.api_core.page_iterator.GRPCIterator( + client=None, + method=functools.partial( + self._list_documents, + retry=retry, + timeout=timeout, + metadata=metadata), + request=request, + items_field='documents', + request_token_field='page_token', + response_token_field='next_page_token', + ) + return iterator def create_document(self, parent, @@ -561,7 +458,9 @@ def create_document(self, document_id, document, mask=None, - options=None): + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Creates a new document. @@ -594,30 +493,46 @@ def create_document(self, will not be returned in the response. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.DocumentMask` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.cloud.firestore_v1beta1.types.Document` instance. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.CreateDocumentRequest( parent=parent, collection_id=collection_id, document_id=document_id, document=document, - mask=mask) - return self._create_document(request, options) + mask=mask, + ) + return self._create_document( + request, retry=retry, timeout=timeout, metadata=metadata) def update_document(self, document, update_mask, mask=None, current_document=None, - options=None): + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Updates or inserts a document. @@ -655,24 +570,43 @@ def update_document(self, The request will fail if this is set and not met by the target document. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.Precondition` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.cloud.firestore_v1beta1.types.Document` instance. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.UpdateDocumentRequest( document=document, update_mask=update_mask, mask=mask, - current_document=current_document) - return self._update_document(request, options) + current_document=current_document, + ) + return self._update_document( + request, retry=retry, timeout=timeout, metadata=metadata) - def delete_document(self, name, current_document=None, options=None): + def delete_document(self, + name, + current_document=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Deletes a document. @@ -692,16 +626,31 @@ def delete_document(self, name, current_document=None, options=None): The request will fail if this is set and not met by the target document. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.Precondition` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.DeleteDocumentRequest( - name=name, current_document=current_document) - self._delete_document(request, options) + name=name, + current_document=current_document, + ) + self._delete_document( + request, retry=retry, timeout=timeout, metadata=metadata) def batch_get_documents(self, database, @@ -710,7 +659,9 @@ def batch_get_documents(self, transaction=None, new_transaction=None, read_time=None, - options=None): + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Gets multiple documents. @@ -753,22 +704,35 @@ def batch_get_documents(self, This may not be older than 60 seconds. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.Timestamp` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: Iterable[~google.cloud.firestore_v1beta1.types.BatchGetDocumentsResponse]. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) # Sanity check: We have some fields which are mutually exclusive; # raise ValueError if more than one is sent. - oneof.check_oneof( + google.api_core.protobuf_helpers.check_oneof( transaction=transaction, new_transaction=new_transaction, - read_time=read_time, ) + read_time=read_time, + ) request = firestore_pb2.BatchGetDocumentsRequest( database=database, @@ -776,10 +740,17 @@ def batch_get_documents(self, mask=mask, transaction=transaction, new_transaction=new_transaction, - read_time=read_time) - return self._batch_get_documents(request, options) - - def begin_transaction(self, database, options_=None, options=None): + read_time=read_time, + ) + return self._batch_get_documents( + request, retry=retry, timeout=timeout, metadata=metadata) + + def begin_transaction(self, + database, + options_=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Starts a new transaction. @@ -799,21 +770,42 @@ def begin_transaction(self, database, options_=None, options=None): Defaults to a read-write transaction. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.TransactionOptions` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.cloud.firestore_v1beta1.types.BeginTransactionResponse` instance. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.BeginTransactionRequest( - database=database, options=options_) - return self._begin_transaction(request, options) - - def commit(self, database, writes, transaction=None, options=None): + database=database, + options=options_, + ) + return self._begin_transaction( + request, retry=retry, timeout=timeout, metadata=metadata) + + def commit(self, + database, + writes, + transaction=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Commits a transaction, while optionally updating documents. @@ -836,21 +828,42 @@ def commit(self, database, writes, transaction=None, options=None): If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.Write` transaction (bytes): If set, applies all writes in this transaction, and commits it. - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.cloud.firestore_v1beta1.types.CommitResponse` instance. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.CommitRequest( - database=database, writes=writes, transaction=transaction) - return self._commit(request, options) - - def rollback(self, database, transaction, options=None): + database=database, + writes=writes, + transaction=transaction, + ) + return self._commit( + request, retry=retry, timeout=timeout, metadata=metadata) + + def rollback(self, + database, + transaction, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Rolls back a transaction. @@ -868,16 +881,31 @@ def rollback(self, database, transaction, options=None): database (str): The database name. In the format: ``projects/{project_id}/databases/{database_id}``. transaction (bytes): The transaction to roll back. - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.RollbackRequest( - database=database, transaction=transaction) - self._rollback(request, options) + database=database, + transaction=transaction, + ) + self._rollback( + request, retry=retry, timeout=timeout, metadata=metadata) def run_query(self, parent, @@ -885,7 +913,9 @@ def run_query(self, transaction=None, new_transaction=None, read_time=None, - options=None): + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Runs a query. @@ -921,36 +951,56 @@ def run_query(self, This may not be older than 60 seconds. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.Timestamp` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: Iterable[~google.cloud.firestore_v1beta1.types.RunQueryResponse]. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) # Sanity check: We have some fields which are mutually exclusive; # raise ValueError if more than one is sent. - oneof.check_oneof(structured_query=structured_query, ) + google.api_core.protobuf_helpers.check_oneof( + structured_query=structured_query, ) # Sanity check: We have some fields which are mutually exclusive; # raise ValueError if more than one is sent. - oneof.check_oneof( + google.api_core.protobuf_helpers.check_oneof( transaction=transaction, new_transaction=new_transaction, - read_time=read_time, ) + read_time=read_time, + ) request = firestore_pb2.RunQueryRequest( parent=parent, structured_query=structured_query, transaction=transaction, new_transaction=new_transaction, - read_time=read_time) - return self._run_query(request, options) - - def write(self, requests, options=None): + read_time=read_time, + ) + return self._run_query( + request, retry=retry, timeout=timeout, metadata=metadata) + + def write(self, + requests, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Streams batches of document updates and deletes, in order. @@ -972,19 +1022,36 @@ def write(self, requests, options=None): Args: requests (iterator[dict|google.cloud.firestore_v1beta1.proto.firestore_pb2.WriteRequest]): The input objects. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.WriteRequest` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: Iterable[~google.cloud.firestore_v1beta1.types.WriteResponse]. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ - return self._write(requests, options) - - def listen(self, requests, options=None): + if metadata is None: + metadata = [] + metadata = list(metadata) + return self._write( + requests, retry=retry, timeout=timeout, metadata=metadata) + + def listen(self, + requests, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Listens to changes. @@ -1006,25 +1073,42 @@ def listen(self, requests, options=None): Args: requests (iterator[dict|google.cloud.firestore_v1beta1.proto.firestore_pb2.ListenRequest]): The input objects. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_v1beta1.types.ListenRequest` - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: Iterable[~google.cloud.firestore_v1beta1.types.ListenResponse]. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ - return self._listen(requests, options) - - def list_collection_ids(self, parent, page_size=None, options=None): + if metadata is None: + metadata = [] + metadata = list(metadata) + return self._listen( + requests, retry=retry, timeout=timeout, metadata=metadata) + + def list_collection_ids(self, + parent, + page_size=None, + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + metadata=None): """ Lists all the collection IDs underneath a document. Example: >>> from google.cloud import firestore_v1beta1 - >>> from google.gax import CallOptions, INITIAL_PAGE >>> >>> client = firestore_v1beta1.FirestoreClient() >>> @@ -1052,8 +1136,14 @@ def list_collection_ids(self, parent, page_size=None, options=None): resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. - options (~google.gax.CallOptions): Overrides the default - settings for this call, e.g, timeout, retries etc. + retry (Optional[google.api_core.retry.Retry]): A retry object used + to retry requests. If ``None`` is specified, requests will not + be retried. + timeout (Optional[float]): The amount of time, in seconds, to wait + for the request to complete. Note that if ``retry`` is + specified, the timeout applies to each individual attempt. + metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata + that is provided to the method. Returns: A :class:`~google.gax.PageIterator` instance. By default, this @@ -1062,9 +1152,29 @@ def list_collection_ids(self, parent, page_size=None, options=None): of the response through the `options` parameter. Raises: - :exc:`google.gax.errors.GaxError` if the RPC is aborted. - :exc:`ValueError` if the parameters are invalid. + google.api_core.exceptions.GoogleAPICallError: If the request + failed for any reason. + google.api_core.exceptions.RetryError: If the request failed due + to a retryable error and retry attempts failed. + ValueError: If the parameters are invalid. """ + if metadata is None: + metadata = [] + metadata = list(metadata) request = firestore_pb2.ListCollectionIdsRequest( - parent=parent, page_size=page_size) - return self._list_collection_ids(request, options) + parent=parent, + page_size=page_size, + ) + iterator = google.api_core.page_iterator.GRPCIterator( + client=None, + method=functools.partial( + self._list_collection_ids, + retry=retry, + timeout=timeout, + metadata=metadata), + request=request, + items_field='collection_ids', + request_token_field='page_token', + response_token_field='next_page_token', + ) + return iterator diff --git a/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client_config.py b/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client_config.py index 8dcfd5d256a3..09a55507d3fd 100644 --- a/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client_config.py +++ b/firestore/google/cloud/firestore_v1beta1/gapic/firestore_client_config.py @@ -14,6 +14,15 @@ "rpc_timeout_multiplier": 1.0, "max_rpc_timeout_millis": 20000, "total_timeout_millis": 600000 + }, + "streaming": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 300000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 300000, + "total_timeout_millis": 600000 } }, "methods": { @@ -43,9 +52,9 @@ "retry_params_name": "default" }, "BatchGetDocuments": { - "timeout_millis": 9223372036854775807, + "timeout_millis": 300000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "streaming" }, "BeginTransaction": { "timeout_millis": 60000, @@ -63,19 +72,19 @@ "retry_params_name": "default" }, "RunQuery": { - "timeout_millis": 9223372036854775807, + "timeout_millis": 60000, "retry_codes_name": "idempotent", "retry_params_name": "default" }, "Write": { - "timeout_millis": 9223372036854775807, + "timeout_millis": 300000, "retry_codes_name": "non_idempotent", - "retry_params_name": "default" + "retry_params_name": "streaming" }, "Listen": { - "timeout_millis": 9223372036854775807, + "timeout_millis": 300000, "retry_codes_name": "idempotent", - "retry_params_name": "default" + "retry_params_name": "streaming" }, "ListCollectionIds": { "timeout_millis": 60000, diff --git a/firestore/google/cloud/firestore_v1beta1/proto/common_pb2.py b/firestore/google/cloud/firestore_v1beta1/proto/common_pb2.py index 24f48fa0d22f..77ea8e07576a 100644 --- a/firestore/google/cloud/firestore_v1beta1/proto/common_pb2.py +++ b/firestore/google/cloud/firestore_v1beta1/proto/common_pb2.py @@ -21,9 +21,10 @@ name='google/cloud/firestore_v1beta1/proto/common.proto', package='google.firestore.v1beta1', syntax='proto3', - serialized_pb=_b('\n1google/cloud/firestore_v1beta1/proto/common.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"#\n\x0c\x44ocumentMask\x12\x13\n\x0b\x66ield_paths\x18\x01 \x03(\t\"e\n\x0cPrecondition\x12\x10\n\x06\x65xists\x18\x01 \x01(\x08H\x00\x12\x31\n\x0bupdate_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x10\n\x0e\x63ondition_type\"\xb3\x02\n\x12TransactionOptions\x12J\n\tread_only\x18\x02 \x01(\x0b\x32\x35.google.firestore.v1beta1.TransactionOptions.ReadOnlyH\x00\x12L\n\nread_write\x18\x03 \x01(\x0b\x32\x36.google.firestore.v1beta1.TransactionOptions.ReadWriteH\x00\x1a&\n\tReadWrite\x12\x19\n\x11retry_transaction\x18\x01 \x01(\x0c\x1aS\n\x08ReadOnly\x12/\n\tread_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x16\n\x14\x63onsistency_selectorB\x06\n\x04modeB\x98\x01\n\x1c\x63om.google.firestore.v1beta1B\x0b\x43ommonProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1b\x06proto3') + serialized_pb=_b('\n1google/cloud/firestore_v1beta1/proto/common.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"#\n\x0c\x44ocumentMask\x12\x13\n\x0b\x66ield_paths\x18\x01 \x03(\t\"e\n\x0cPrecondition\x12\x10\n\x06\x65xists\x18\x01 \x01(\x08H\x00\x12\x31\n\x0bupdate_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x10\n\x0e\x63ondition_type\"\xb3\x02\n\x12TransactionOptions\x12J\n\tread_only\x18\x02 \x01(\x0b\x32\x35.google.firestore.v1beta1.TransactionOptions.ReadOnlyH\x00\x12L\n\nread_write\x18\x03 \x01(\x0b\x32\x36.google.firestore.v1beta1.TransactionOptions.ReadWriteH\x00\x1a&\n\tReadWrite\x12\x19\n\x11retry_transaction\x18\x01 \x01(\x0c\x1aS\n\x08ReadOnly\x12/\n\tread_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x16\n\x14\x63onsistency_selectorB\x06\n\x04modeB\xb9\x01\n\x1c\x63om.google.firestore.v1beta1B\x0b\x43ommonProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1\xca\x02\x1eGoogle\\Cloud\\Firestore\\V1beta1b\x06proto3') , dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -227,7 +228,6 @@ DESCRIPTOR.message_types_by_name['DocumentMask'] = _DOCUMENTMASK DESCRIPTOR.message_types_by_name['Precondition'] = _PRECONDITION DESCRIPTOR.message_types_by_name['TransactionOptions'] = _TRANSACTIONOPTIONS -_sym_db.RegisterFileDescriptor(DESCRIPTOR) DocumentMask = _reflection.GeneratedProtocolMessageType('DocumentMask', (_message.Message,), dict( DESCRIPTOR = _DOCUMENTMASK, @@ -278,6 +278,11 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.common_pb2' , __doc__ = """Options for a transaction that can be used to read and write documents. + + + Attributes: + retry_transaction: + An optional transaction to retry. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.TransactionOptions.ReadWrite) )) @@ -288,6 +293,15 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.common_pb2' , __doc__ = """Options for a transaction that can only be used to read documents. + + + Attributes: + consistency_selector: + The consistency mode for this transaction. If not set, + defaults to strong consistency. + read_time: + Reads documents at the given time. This may not be older than + 60 seconds. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.TransactionOptions.ReadOnly) )) @@ -299,14 +313,6 @@ Attributes: - retry_transaction: - An optional transaction to retry. - consistency_selector: - The consistency mode for this transaction. If not set, - defaults to strong consistency. - read_time: - Reads documents at the given time. This may not be older than - 60 seconds. mode: The mode of the transaction. read_only: @@ -323,7 +329,7 @@ DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\013CommonProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1')) +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\013CommonProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1\312\002\036Google\\Cloud\\Firestore\\V1beta1')) try: # THESE ELEMENTS WILL BE DEPRECATED. # Please use the generated *_pb2_grpc.py files instead. diff --git a/firestore/google/cloud/firestore_v1beta1/proto/document_pb2.py b/firestore/google/cloud/firestore_v1beta1/proto/document_pb2.py index 5a0414f80fa1..12bd6c286fdb 100644 --- a/firestore/google/cloud/firestore_v1beta1/proto/document_pb2.py +++ b/firestore/google/cloud/firestore_v1beta1/proto/document_pb2.py @@ -23,9 +23,10 @@ name='google/cloud/firestore_v1beta1/proto/document.proto', package='google.firestore.v1beta1', syntax='proto3', - serialized_pb=_b('\n3google/cloud/firestore_v1beta1/proto/document.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x18google/type/latlng.proto\"\x8a\x02\n\x08\x44ocument\x12\x0c\n\x04name\x18\x01 \x01(\t\x12>\n\x06\x66ields\x18\x02 \x03(\x0b\x32..google.firestore.v1beta1.Document.FieldsEntry\x12/\n\x0b\x63reate_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12/\n\x0bupdate_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1aN\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12.\n\x05value\x18\x02 \x01(\x0b\x32\x1f.google.firestore.v1beta1.Value:\x02\x38\x01\"\xb8\x03\n\x05Value\x12\x30\n\nnull_value\x18\x0b \x01(\x0e\x32\x1a.google.protobuf.NullValueH\x00\x12\x17\n\rboolean_value\x18\x01 \x01(\x08H\x00\x12\x17\n\rinteger_value\x18\x02 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x03 \x01(\x01H\x00\x12\x35\n\x0ftimestamp_value\x18\n \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x16\n\x0cstring_value\x18\x11 \x01(\tH\x00\x12\x15\n\x0b\x62ytes_value\x18\x12 \x01(\x0cH\x00\x12\x19\n\x0freference_value\x18\x05 \x01(\tH\x00\x12.\n\x0fgeo_point_value\x18\x08 \x01(\x0b\x32\x13.google.type.LatLngH\x00\x12;\n\x0b\x61rray_value\x18\t \x01(\x0b\x32$.google.firestore.v1beta1.ArrayValueH\x00\x12\x37\n\tmap_value\x18\x06 \x01(\x0b\x32\".google.firestore.v1beta1.MapValueH\x00\x42\x0c\n\nvalue_type\"=\n\nArrayValue\x12/\n\x06values\x18\x01 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Value\"\x9a\x01\n\x08MapValue\x12>\n\x06\x66ields\x18\x01 \x03(\x0b\x32..google.firestore.v1beta1.MapValue.FieldsEntry\x1aN\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12.\n\x05value\x18\x02 \x01(\x0b\x32\x1f.google.firestore.v1beta1.Value:\x02\x38\x01\x42\x9a\x01\n\x1c\x63om.google.firestore.v1beta1B\rDocumentProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1b\x06proto3') + serialized_pb=_b('\n3google/cloud/firestore_v1beta1/proto/document.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x18google/type/latlng.proto\"\x8a\x02\n\x08\x44ocument\x12\x0c\n\x04name\x18\x01 \x01(\t\x12>\n\x06\x66ields\x18\x02 \x03(\x0b\x32..google.firestore.v1beta1.Document.FieldsEntry\x12/\n\x0b\x63reate_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12/\n\x0bupdate_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x1aN\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12.\n\x05value\x18\x02 \x01(\x0b\x32\x1f.google.firestore.v1beta1.Value:\x02\x38\x01\"\xb8\x03\n\x05Value\x12\x30\n\nnull_value\x18\x0b \x01(\x0e\x32\x1a.google.protobuf.NullValueH\x00\x12\x17\n\rboolean_value\x18\x01 \x01(\x08H\x00\x12\x17\n\rinteger_value\x18\x02 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x03 \x01(\x01H\x00\x12\x35\n\x0ftimestamp_value\x18\n \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x16\n\x0cstring_value\x18\x11 \x01(\tH\x00\x12\x15\n\x0b\x62ytes_value\x18\x12 \x01(\x0cH\x00\x12\x19\n\x0freference_value\x18\x05 \x01(\tH\x00\x12.\n\x0fgeo_point_value\x18\x08 \x01(\x0b\x32\x13.google.type.LatLngH\x00\x12;\n\x0b\x61rray_value\x18\t \x01(\x0b\x32$.google.firestore.v1beta1.ArrayValueH\x00\x12\x37\n\tmap_value\x18\x06 \x01(\x0b\x32\".google.firestore.v1beta1.MapValueH\x00\x42\x0c\n\nvalue_type\"=\n\nArrayValue\x12/\n\x06values\x18\x01 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Value\"\x9a\x01\n\x08MapValue\x12>\n\x06\x66ields\x18\x01 \x03(\x0b\x32..google.firestore.v1beta1.MapValue.FieldsEntry\x1aN\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12.\n\x05value\x18\x02 \x01(\x0b\x32\x1f.google.firestore.v1beta1.Value:\x02\x38\x01\x42\xbb\x01\n\x1c\x63om.google.firestore.v1beta1B\rDocumentProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1\xca\x02\x1eGoogle\\Cloud\\Firestore\\V1beta1b\x06proto3') , dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_struct__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,google_dot_type_dot_latlng__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -372,7 +373,6 @@ DESCRIPTOR.message_types_by_name['Value'] = _VALUE DESCRIPTOR.message_types_by_name['ArrayValue'] = _ARRAYVALUE DESCRIPTOR.message_types_by_name['MapValue'] = _MAPVALUE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) Document = _reflection.GeneratedProtocolMessageType('Document', (_message.Message,), dict( @@ -517,7 +517,7 @@ DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\rDocumentProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1')) +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\rDocumentProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1\312\002\036Google\\Cloud\\Firestore\\V1beta1')) _DOCUMENT_FIELDSENTRY.has_options = True _DOCUMENT_FIELDSENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) _MAPVALUE_FIELDSENTRY.has_options = True diff --git a/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2.py b/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2.py index 6986d5b8f5b6..be7f47ec18f5 100644 --- a/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2.py +++ b/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2.py @@ -27,9 +27,10 @@ name='google/cloud/firestore_v1beta1/proto/firestore.proto', package='google.firestore.v1beta1', syntax='proto3', - serialized_pb=_b('\n4google/cloud/firestore_v1beta1/proto/firestore.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x31google/cloud/firestore_v1beta1/proto/common.proto\x1a\x33google/cloud/firestore_v1beta1/proto/document.proto\x1a\x30google/cloud/firestore_v1beta1/proto/query.proto\x1a\x30google/cloud/firestore_v1beta1/proto/write.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17google/rpc/status.proto\"\xb8\x01\n\x12GetDocumentRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x34\n\x04mask\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x15\n\x0btransaction\x18\x03 \x01(\x0cH\x00\x12/\n\tread_time\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x16\n\x14\x63onsistency_selector\"\xa2\x02\n\x14ListDocumentsRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x15\n\rcollection_id\x18\x02 \x01(\t\x12\x11\n\tpage_size\x18\x03 \x01(\x05\x12\x12\n\npage_token\x18\x04 \x01(\t\x12\x10\n\x08order_by\x18\x06 \x01(\t\x12\x34\n\x04mask\x18\x07 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x15\n\x0btransaction\x18\x08 \x01(\x0cH\x00\x12/\n\tread_time\x18\n \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x14\n\x0cshow_missing\x18\x0c \x01(\x08\x42\x16\n\x14\x63onsistency_selector\"g\n\x15ListDocumentsResponse\x12\x35\n\tdocuments\x18\x01 \x03(\x0b\x32\".google.firestore.v1beta1.Document\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t\"\xbf\x01\n\x15\x43reateDocumentRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x15\n\rcollection_id\x18\x02 \x01(\t\x12\x13\n\x0b\x64ocument_id\x18\x03 \x01(\t\x12\x34\n\x08\x64ocument\x18\x04 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12\x34\n\x04mask\x18\x05 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\"\x82\x02\n\x15UpdateDocumentRequest\x12\x34\n\x08\x64ocument\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12;\n\x0bupdate_mask\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x34\n\x04mask\x18\x03 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12@\n\x10\x63urrent_document\x18\x04 \x01(\x0b\x32&.google.firestore.v1beta1.Precondition\"g\n\x15\x44\x65leteDocumentRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12@\n\x10\x63urrent_document\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.Precondition\"\x9e\x02\n\x18\x42\x61tchGetDocumentsRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x11\n\tdocuments\x18\x02 \x03(\t\x12\x34\n\x04mask\x18\x03 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x15\n\x0btransaction\x18\x04 \x01(\x0cH\x00\x12G\n\x0fnew_transaction\x18\x05 \x01(\x0b\x32,.google.firestore.v1beta1.TransactionOptionsH\x00\x12/\n\tread_time\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x16\n\x14\x63onsistency_selector\"\xb1\x01\n\x19\x42\x61tchGetDocumentsResponse\x12\x33\n\x05\x66ound\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.DocumentH\x00\x12\x11\n\x07missing\x18\x02 \x01(\tH\x00\x12\x13\n\x0btransaction\x18\x03 \x01(\x0c\x12-\n\tread_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.TimestampB\x08\n\x06result\"j\n\x17\x42\x65ginTransactionRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12=\n\x07options\x18\x02 \x01(\x0b\x32,.google.firestore.v1beta1.TransactionOptions\"/\n\x18\x42\x65ginTransactionResponse\x12\x13\n\x0btransaction\x18\x01 \x01(\x0c\"g\n\rCommitRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12/\n\x06writes\x18\x02 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Write\x12\x13\n\x0btransaction\x18\x03 \x01(\x0c\"\x7f\n\x0e\x43ommitResponse\x12<\n\rwrite_results\x18\x01 \x03(\x0b\x32%.google.firestore.v1beta1.WriteResult\x12/\n\x0b\x63ommit_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"8\n\x0fRollbackRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x13\n\x0btransaction\x18\x02 \x01(\x0c\"\x9f\x02\n\x0fRunQueryRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x45\n\x10structured_query\x18\x02 \x01(\x0b\x32).google.firestore.v1beta1.StructuredQueryH\x00\x12\x15\n\x0btransaction\x18\x05 \x01(\x0cH\x01\x12G\n\x0fnew_transaction\x18\x06 \x01(\x0b\x32,.google.firestore.v1beta1.TransactionOptionsH\x01\x12/\n\tread_time\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x01\x42\x0c\n\nquery_typeB\x16\n\x14\x63onsistency_selector\"\xa5\x01\n\x10RunQueryResponse\x12\x13\n\x0btransaction\x18\x02 \x01(\x0c\x12\x34\n\x08\x64ocument\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12-\n\tread_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x17\n\x0fskipped_results\x18\x04 \x01(\x05\"\xed\x01\n\x0cWriteRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x11\n\tstream_id\x18\x02 \x01(\t\x12/\n\x06writes\x18\x03 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Write\x12\x14\n\x0cstream_token\x18\x04 \x01(\x0c\x12\x42\n\x06labels\x18\x05 \x03(\x0b\x32\x32.google.firestore.v1beta1.WriteRequest.LabelsEntry\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xa7\x01\n\rWriteResponse\x12\x11\n\tstream_id\x18\x01 \x01(\t\x12\x14\n\x0cstream_token\x18\x02 \x01(\x0c\x12<\n\rwrite_results\x18\x03 \x03(\x0b\x32%.google.firestore.v1beta1.WriteResult\x12/\n\x0b\x63ommit_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xf7\x01\n\rListenRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x36\n\nadd_target\x18\x02 \x01(\x0b\x32 .google.firestore.v1beta1.TargetH\x00\x12\x17\n\rremove_target\x18\x03 \x01(\x05H\x00\x12\x43\n\x06labels\x18\x04 \x03(\x0b\x32\x33.google.firestore.v1beta1.ListenRequest.LabelsEntry\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42\x0f\n\rtarget_change\"\xee\x02\n\x0eListenResponse\x12?\n\rtarget_change\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.TargetChangeH\x00\x12\x43\n\x0f\x64ocument_change\x18\x03 \x01(\x0b\x32(.google.firestore.v1beta1.DocumentChangeH\x00\x12\x43\n\x0f\x64ocument_delete\x18\x04 \x01(\x0b\x32(.google.firestore.v1beta1.DocumentDeleteH\x00\x12\x43\n\x0f\x64ocument_remove\x18\x06 \x01(\x0b\x32(.google.firestore.v1beta1.DocumentRemoveH\x00\x12;\n\x06\x66ilter\x18\x05 \x01(\x0b\x32).google.firestore.v1beta1.ExistenceFilterH\x00\x42\x0f\n\rresponse_type\"\xb0\x03\n\x06Target\x12=\n\x05query\x18\x02 \x01(\x0b\x32,.google.firestore.v1beta1.Target.QueryTargetH\x00\x12\x45\n\tdocuments\x18\x03 \x01(\x0b\x32\x30.google.firestore.v1beta1.Target.DocumentsTargetH\x00\x12\x16\n\x0cresume_token\x18\x04 \x01(\x0cH\x01\x12/\n\tread_time\x18\x0b \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x01\x12\x11\n\ttarget_id\x18\x05 \x01(\x05\x12\x0c\n\x04once\x18\x06 \x01(\x08\x1a$\n\x0f\x44ocumentsTarget\x12\x11\n\tdocuments\x18\x02 \x03(\t\x1ar\n\x0bQueryTarget\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x45\n\x10structured_query\x18\x02 \x01(\x0b\x32).google.firestore.v1beta1.StructuredQueryH\x00\x42\x0c\n\nquery_typeB\r\n\x0btarget_typeB\r\n\x0bresume_type\"\xaf\x02\n\x0cTargetChange\x12S\n\x12target_change_type\x18\x01 \x01(\x0e\x32\x37.google.firestore.v1beta1.TargetChange.TargetChangeType\x12\x12\n\ntarget_ids\x18\x02 \x03(\x05\x12!\n\x05\x63\x61use\x18\x03 \x01(\x0b\x32\x12.google.rpc.Status\x12\x14\n\x0cresume_token\x18\x04 \x01(\x0c\x12-\n\tread_time\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"N\n\x10TargetChangeType\x12\r\n\tNO_CHANGE\x10\x00\x12\x07\n\x03\x41\x44\x44\x10\x01\x12\n\n\x06REMOVE\x10\x02\x12\x0b\n\x07\x43URRENT\x10\x03\x12\t\n\x05RESET\x10\x04\"Q\n\x18ListCollectionIdsRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t\"L\n\x19ListCollectionIdsResponse\x12\x16\n\x0e\x63ollection_ids\x18\x01 \x03(\t\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t2\xad\x12\n\tFirestore\x12\x9e\x01\n\x0bGetDocument\x12,.google.firestore.v1beta1.GetDocumentRequest\x1a\".google.firestore.v1beta1.Document\"=\x82\xd3\xe4\x93\x02\x37\x12\x35/v1beta1/{name=projects/*/databases/*/documents/*/**}\x12\xc1\x01\n\rListDocuments\x12..google.firestore.v1beta1.ListDocumentsRequest\x1a/.google.firestore.v1beta1.ListDocumentsResponse\"O\x82\xd3\xe4\x93\x02I\x12G/v1beta1/{parent=projects/*/databases/*/documents/*/**}/{collection_id}\x12\xbe\x01\n\x0e\x43reateDocument\x12/.google.firestore.v1beta1.CreateDocumentRequest\x1a\".google.firestore.v1beta1.Document\"W\x82\xd3\xe4\x93\x02Q\"E/v1beta1/{parent=projects/*/databases/*/documents/**}/{collection_id}:\x08\x64ocument\x12\xb7\x01\n\x0eUpdateDocument\x12/.google.firestore.v1beta1.UpdateDocumentRequest\x1a\".google.firestore.v1beta1.Document\"P\x82\xd3\xe4\x93\x02J2>/v1beta1/{document.name=projects/*/databases/*/documents/*/**}:\x08\x64ocument\x12\x98\x01\n\x0e\x44\x65leteDocument\x12/.google.firestore.v1beta1.DeleteDocumentRequest\x1a\x16.google.protobuf.Empty\"=\x82\xd3\xe4\x93\x02\x37*5/v1beta1/{name=projects/*/databases/*/documents/*/**}\x12\xc8\x01\n\x11\x42\x61tchGetDocuments\x12\x32.google.firestore.v1beta1.BatchGetDocumentsRequest\x1a\x33.google.firestore.v1beta1.BatchGetDocumentsResponse\"H\x82\xd3\xe4\x93\x02\x42\"=/v1beta1/{database=projects/*/databases/*}/documents:batchGet:\x01*0\x01\x12\xcb\x01\n\x10\x42\x65ginTransaction\x12\x31.google.firestore.v1beta1.BeginTransactionRequest\x1a\x32.google.firestore.v1beta1.BeginTransactionResponse\"P\x82\xd3\xe4\x93\x02J\"E/v1beta1/{database=projects/*/databases/*}/documents:beginTransaction:\x01*\x12\xa3\x01\n\x06\x43ommit\x12\'.google.firestore.v1beta1.CommitRequest\x1a(.google.firestore.v1beta1.CommitResponse\"F\x82\xd3\xe4\x93\x02@\";/v1beta1/{database=projects/*/databases/*}/documents:commit:\x01*\x12\x97\x01\n\x08Rollback\x12).google.firestore.v1beta1.RollbackRequest\x1a\x16.google.protobuf.Empty\"H\x82\xd3\xe4\x93\x02\x42\"=/v1beta1/{database=projects/*/databases/*}/documents:rollback:\x01*\x12\xab\x01\n\x08RunQuery\x12).google.firestore.v1beta1.RunQueryRequest\x1a*.google.firestore.v1beta1.RunQueryResponse\"F\x82\xd3\xe4\x93\x02@\";/v1beta1/{parent=projects/*/databases/*/documents}:runQuery:\x01*0\x01\x12\xa3\x01\n\x05Write\x12&.google.firestore.v1beta1.WriteRequest\x1a\'.google.firestore.v1beta1.WriteResponse\"E\x82\xd3\xe4\x93\x02?\":/v1beta1/{database=projects/*/databases/*}/documents:write:\x01*(\x01\x30\x01\x12\xa7\x01\n\x06Listen\x12\'.google.firestore.v1beta1.ListenRequest\x1a(.google.firestore.v1beta1.ListenResponse\"F\x82\xd3\xe4\x93\x02@\";/v1beta1/{database=projects/*/databases/*}/documents:listen:\x01*(\x01\x30\x01\x12\xcd\x01\n\x11ListCollectionIds\x12\x32.google.firestore.v1beta1.ListCollectionIdsRequest\x1a\x33.google.firestore.v1beta1.ListCollectionIdsResponse\"O\x82\xd3\xe4\x93\x02I\"D/v1beta1/{parent=projects/*/databases/*/documents}:listCollectionIds:\x01*B\x9b\x01\n\x1c\x63om.google.firestore.v1beta1B\x0e\x46irestoreProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1b\x06proto3') + serialized_pb=_b('\n4google/cloud/firestore_v1beta1/proto/firestore.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x31google/cloud/firestore_v1beta1/proto/common.proto\x1a\x33google/cloud/firestore_v1beta1/proto/document.proto\x1a\x30google/cloud/firestore_v1beta1/proto/query.proto\x1a\x30google/cloud/firestore_v1beta1/proto/write.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17google/rpc/status.proto\"\xb8\x01\n\x12GetDocumentRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x34\n\x04mask\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x15\n\x0btransaction\x18\x03 \x01(\x0cH\x00\x12/\n\tread_time\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x16\n\x14\x63onsistency_selector\"\xa2\x02\n\x14ListDocumentsRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x15\n\rcollection_id\x18\x02 \x01(\t\x12\x11\n\tpage_size\x18\x03 \x01(\x05\x12\x12\n\npage_token\x18\x04 \x01(\t\x12\x10\n\x08order_by\x18\x06 \x01(\t\x12\x34\n\x04mask\x18\x07 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x15\n\x0btransaction\x18\x08 \x01(\x0cH\x00\x12/\n\tread_time\x18\n \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x14\n\x0cshow_missing\x18\x0c \x01(\x08\x42\x16\n\x14\x63onsistency_selector\"g\n\x15ListDocumentsResponse\x12\x35\n\tdocuments\x18\x01 \x03(\x0b\x32\".google.firestore.v1beta1.Document\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t\"\xbf\x01\n\x15\x43reateDocumentRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x15\n\rcollection_id\x18\x02 \x01(\t\x12\x13\n\x0b\x64ocument_id\x18\x03 \x01(\t\x12\x34\n\x08\x64ocument\x18\x04 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12\x34\n\x04mask\x18\x05 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\"\x82\x02\n\x15UpdateDocumentRequest\x12\x34\n\x08\x64ocument\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12;\n\x0bupdate_mask\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x34\n\x04mask\x18\x03 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12@\n\x10\x63urrent_document\x18\x04 \x01(\x0b\x32&.google.firestore.v1beta1.Precondition\"g\n\x15\x44\x65leteDocumentRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12@\n\x10\x63urrent_document\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.Precondition\"\x9e\x02\n\x18\x42\x61tchGetDocumentsRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x11\n\tdocuments\x18\x02 \x03(\t\x12\x34\n\x04mask\x18\x03 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12\x15\n\x0btransaction\x18\x04 \x01(\x0cH\x00\x12G\n\x0fnew_transaction\x18\x05 \x01(\x0b\x32,.google.firestore.v1beta1.TransactionOptionsH\x00\x12/\n\tread_time\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x42\x16\n\x14\x63onsistency_selector\"\xb1\x01\n\x19\x42\x61tchGetDocumentsResponse\x12\x33\n\x05\x66ound\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.DocumentH\x00\x12\x11\n\x07missing\x18\x02 \x01(\tH\x00\x12\x13\n\x0btransaction\x18\x03 \x01(\x0c\x12-\n\tread_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.TimestampB\x08\n\x06result\"j\n\x17\x42\x65ginTransactionRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12=\n\x07options\x18\x02 \x01(\x0b\x32,.google.firestore.v1beta1.TransactionOptions\"/\n\x18\x42\x65ginTransactionResponse\x12\x13\n\x0btransaction\x18\x01 \x01(\x0c\"g\n\rCommitRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12/\n\x06writes\x18\x02 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Write\x12\x13\n\x0btransaction\x18\x03 \x01(\x0c\"\x7f\n\x0e\x43ommitResponse\x12<\n\rwrite_results\x18\x01 \x03(\x0b\x32%.google.firestore.v1beta1.WriteResult\x12/\n\x0b\x63ommit_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"8\n\x0fRollbackRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x13\n\x0btransaction\x18\x02 \x01(\x0c\"\x9f\x02\n\x0fRunQueryRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x45\n\x10structured_query\x18\x02 \x01(\x0b\x32).google.firestore.v1beta1.StructuredQueryH\x00\x12\x15\n\x0btransaction\x18\x05 \x01(\x0cH\x01\x12G\n\x0fnew_transaction\x18\x06 \x01(\x0b\x32,.google.firestore.v1beta1.TransactionOptionsH\x01\x12/\n\tread_time\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x01\x42\x0c\n\nquery_typeB\x16\n\x14\x63onsistency_selector\"\xa5\x01\n\x10RunQueryResponse\x12\x13\n\x0btransaction\x18\x02 \x01(\x0c\x12\x34\n\x08\x64ocument\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12-\n\tread_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x17\n\x0fskipped_results\x18\x04 \x01(\x05\"\xed\x01\n\x0cWriteRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x11\n\tstream_id\x18\x02 \x01(\t\x12/\n\x06writes\x18\x03 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Write\x12\x14\n\x0cstream_token\x18\x04 \x01(\x0c\x12\x42\n\x06labels\x18\x05 \x03(\x0b\x32\x32.google.firestore.v1beta1.WriteRequest.LabelsEntry\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xa7\x01\n\rWriteResponse\x12\x11\n\tstream_id\x18\x01 \x01(\t\x12\x14\n\x0cstream_token\x18\x02 \x01(\x0c\x12<\n\rwrite_results\x18\x03 \x03(\x0b\x32%.google.firestore.v1beta1.WriteResult\x12/\n\x0b\x63ommit_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xf7\x01\n\rListenRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\x12\x36\n\nadd_target\x18\x02 \x01(\x0b\x32 .google.firestore.v1beta1.TargetH\x00\x12\x17\n\rremove_target\x18\x03 \x01(\x05H\x00\x12\x43\n\x06labels\x18\x04 \x03(\x0b\x32\x33.google.firestore.v1beta1.ListenRequest.LabelsEntry\x1a-\n\x0bLabelsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42\x0f\n\rtarget_change\"\xee\x02\n\x0eListenResponse\x12?\n\rtarget_change\x18\x02 \x01(\x0b\x32&.google.firestore.v1beta1.TargetChangeH\x00\x12\x43\n\x0f\x64ocument_change\x18\x03 \x01(\x0b\x32(.google.firestore.v1beta1.DocumentChangeH\x00\x12\x43\n\x0f\x64ocument_delete\x18\x04 \x01(\x0b\x32(.google.firestore.v1beta1.DocumentDeleteH\x00\x12\x43\n\x0f\x64ocument_remove\x18\x06 \x01(\x0b\x32(.google.firestore.v1beta1.DocumentRemoveH\x00\x12;\n\x06\x66ilter\x18\x05 \x01(\x0b\x32).google.firestore.v1beta1.ExistenceFilterH\x00\x42\x0f\n\rresponse_type\"\xb0\x03\n\x06Target\x12=\n\x05query\x18\x02 \x01(\x0b\x32,.google.firestore.v1beta1.Target.QueryTargetH\x00\x12\x45\n\tdocuments\x18\x03 \x01(\x0b\x32\x30.google.firestore.v1beta1.Target.DocumentsTargetH\x00\x12\x16\n\x0cresume_token\x18\x04 \x01(\x0cH\x01\x12/\n\tread_time\x18\x0b \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x01\x12\x11\n\ttarget_id\x18\x05 \x01(\x05\x12\x0c\n\x04once\x18\x06 \x01(\x08\x1a$\n\x0f\x44ocumentsTarget\x12\x11\n\tdocuments\x18\x02 \x03(\t\x1ar\n\x0bQueryTarget\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x45\n\x10structured_query\x18\x02 \x01(\x0b\x32).google.firestore.v1beta1.StructuredQueryH\x00\x42\x0c\n\nquery_typeB\r\n\x0btarget_typeB\r\n\x0bresume_type\"\xaf\x02\n\x0cTargetChange\x12S\n\x12target_change_type\x18\x01 \x01(\x0e\x32\x37.google.firestore.v1beta1.TargetChange.TargetChangeType\x12\x12\n\ntarget_ids\x18\x02 \x03(\x05\x12!\n\x05\x63\x61use\x18\x03 \x01(\x0b\x32\x12.google.rpc.Status\x12\x14\n\x0cresume_token\x18\x04 \x01(\x0c\x12-\n\tread_time\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"N\n\x10TargetChangeType\x12\r\n\tNO_CHANGE\x10\x00\x12\x07\n\x03\x41\x44\x44\x10\x01\x12\n\n\x06REMOVE\x10\x02\x12\x0b\n\x07\x43URRENT\x10\x03\x12\t\n\x05RESET\x10\x04\"Q\n\x18ListCollectionIdsRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t\"L\n\x19ListCollectionIdsResponse\x12\x16\n\x0e\x63ollection_ids\x18\x01 \x03(\t\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t2\xad\x12\n\tFirestore\x12\x9e\x01\n\x0bGetDocument\x12,.google.firestore.v1beta1.GetDocumentRequest\x1a\".google.firestore.v1beta1.Document\"=\x82\xd3\xe4\x93\x02\x37\x12\x35/v1beta1/{name=projects/*/databases/*/documents/*/**}\x12\xc1\x01\n\rListDocuments\x12..google.firestore.v1beta1.ListDocumentsRequest\x1a/.google.firestore.v1beta1.ListDocumentsResponse\"O\x82\xd3\xe4\x93\x02I\x12G/v1beta1/{parent=projects/*/databases/*/documents/*/**}/{collection_id}\x12\xbe\x01\n\x0e\x43reateDocument\x12/.google.firestore.v1beta1.CreateDocumentRequest\x1a\".google.firestore.v1beta1.Document\"W\x82\xd3\xe4\x93\x02Q\"E/v1beta1/{parent=projects/*/databases/*/documents/**}/{collection_id}:\x08\x64ocument\x12\xb7\x01\n\x0eUpdateDocument\x12/.google.firestore.v1beta1.UpdateDocumentRequest\x1a\".google.firestore.v1beta1.Document\"P\x82\xd3\xe4\x93\x02J2>/v1beta1/{document.name=projects/*/databases/*/documents/*/**}:\x08\x64ocument\x12\x98\x01\n\x0e\x44\x65leteDocument\x12/.google.firestore.v1beta1.DeleteDocumentRequest\x1a\x16.google.protobuf.Empty\"=\x82\xd3\xe4\x93\x02\x37*5/v1beta1/{name=projects/*/databases/*/documents/*/**}\x12\xc8\x01\n\x11\x42\x61tchGetDocuments\x12\x32.google.firestore.v1beta1.BatchGetDocumentsRequest\x1a\x33.google.firestore.v1beta1.BatchGetDocumentsResponse\"H\x82\xd3\xe4\x93\x02\x42\"=/v1beta1/{database=projects/*/databases/*}/documents:batchGet:\x01*0\x01\x12\xcb\x01\n\x10\x42\x65ginTransaction\x12\x31.google.firestore.v1beta1.BeginTransactionRequest\x1a\x32.google.firestore.v1beta1.BeginTransactionResponse\"P\x82\xd3\xe4\x93\x02J\"E/v1beta1/{database=projects/*/databases/*}/documents:beginTransaction:\x01*\x12\xa3\x01\n\x06\x43ommit\x12\'.google.firestore.v1beta1.CommitRequest\x1a(.google.firestore.v1beta1.CommitResponse\"F\x82\xd3\xe4\x93\x02@\";/v1beta1/{database=projects/*/databases/*}/documents:commit:\x01*\x12\x97\x01\n\x08Rollback\x12).google.firestore.v1beta1.RollbackRequest\x1a\x16.google.protobuf.Empty\"H\x82\xd3\xe4\x93\x02\x42\"=/v1beta1/{database=projects/*/databases/*}/documents:rollback:\x01*\x12\xab\x01\n\x08RunQuery\x12).google.firestore.v1beta1.RunQueryRequest\x1a*.google.firestore.v1beta1.RunQueryResponse\"F\x82\xd3\xe4\x93\x02@\";/v1beta1/{parent=projects/*/databases/*/documents}:runQuery:\x01*0\x01\x12\xa3\x01\n\x05Write\x12&.google.firestore.v1beta1.WriteRequest\x1a\'.google.firestore.v1beta1.WriteResponse\"E\x82\xd3\xe4\x93\x02?\":/v1beta1/{database=projects/*/databases/*}/documents:write:\x01*(\x01\x30\x01\x12\xa7\x01\n\x06Listen\x12\'.google.firestore.v1beta1.ListenRequest\x1a(.google.firestore.v1beta1.ListenResponse\"F\x82\xd3\xe4\x93\x02@\";/v1beta1/{database=projects/*/databases/*}/documents:listen:\x01*(\x01\x30\x01\x12\xcd\x01\n\x11ListCollectionIds\x12\x32.google.firestore.v1beta1.ListCollectionIdsRequest\x1a\x33.google.firestore.v1beta1.ListCollectionIdsResponse\"O\x82\xd3\xe4\x93\x02I\"D/v1beta1/{parent=projects/*/databases/*/documents}:listCollectionIds:\x01*B\xbc\x01\n\x1c\x63om.google.firestore.v1beta1B\x0e\x46irestoreProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1\xca\x02\x1eGoogle\\Cloud\\Firestore\\V1beta1b\x06proto3') , dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_common__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_query__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_write__pb2.DESCRIPTOR,google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,google_dot_rpc_dot_status__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -1564,7 +1565,6 @@ DESCRIPTOR.message_types_by_name['TargetChange'] = _TARGETCHANGE DESCRIPTOR.message_types_by_name['ListCollectionIdsRequest'] = _LISTCOLLECTIONIDSREQUEST DESCRIPTOR.message_types_by_name['ListCollectionIdsResponse'] = _LISTCOLLECTIONIDSRESPONSE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) GetDocumentRequest = _reflection.GeneratedProtocolMessageType('GetDocumentRequest', (_message.Message,), dict( DESCRIPTOR = _GETDOCUMENTREQUEST, @@ -2147,6 +2147,15 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.firestore_pb2' , __doc__ = """A target specified by a set of documents names. + + + Attributes: + documents: + The names of the documents to retrieve. In the format: ``proje + cts/{project_id}/databases/{database_id}/documents/{document_p + ath}``. The request will fail if any of the document is not a + child resource of the given ``database``. Duplicate names will + be elided. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.Target.DocumentsTarget) )) @@ -2157,6 +2166,21 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.firestore_pb2' , __doc__ = """A target specified by a query. + + + Attributes: + parent: + The parent resource name. In the format: + ``projects/{project_id}/databases/{database_id}/documents`` or + ``projects/{project_id}/databases/{database_id}/documents/{doc + ument_path}``. For example: ``projects/my- + project/databases/my-database/documents`` or ``projects/my- + project/databases/my-database/documents/chatrooms/my- + chatroom`` + query_type: + The query to run. + structured_query: + A structured query. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.Target.QueryTarget) )) @@ -2168,24 +2192,12 @@ Attributes: - documents: - A target specified by a set of document names. - parent: - The parent resource name. In the format: - ``projects/{project_id}/databases/{database_id}/documents`` or - ``projects/{project_id}/databases/{database_id}/documents/{doc - ument_path}``. For example: ``projects/my- - project/databases/my-database/documents`` or ``projects/my- - project/databases/my-database/documents/chatrooms/my- - chatroom`` - query_type: - The query to run. - structured_query: - A structured query. target_type: The type of target to listen to. query: A target specified by a query. + documents: + A target specified by a set of document names. resume_type: When to start listening. If not specified, all matching Documents are returned before any subsequent changes. @@ -2297,143 +2309,11 @@ DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\016FirestoreProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1')) +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\016FirestoreProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1\312\002\036Google\\Cloud\\Firestore\\V1beta1')) _WRITEREQUEST_LABELSENTRY.has_options = True _WRITEREQUEST_LABELSENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) _LISTENREQUEST_LABELSENTRY.has_options = True _LISTENREQUEST_LABELSENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) - -_FIRESTORE = _descriptor.ServiceDescriptor( - name='Firestore', - full_name='google.firestore.v1beta1.Firestore', - file=DESCRIPTOR, - index=0, - options=None, - serialized_start=4856, - serialized_end=7205, - methods=[ - _descriptor.MethodDescriptor( - name='GetDocument', - full_name='google.firestore.v1beta1.Firestore.GetDocument', - index=0, - containing_service=None, - input_type=_GETDOCUMENTREQUEST, - output_type=google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2._DOCUMENT, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\0027\0225/v1beta1/{name=projects/*/databases/*/documents/*/**}')), - ), - _descriptor.MethodDescriptor( - name='ListDocuments', - full_name='google.firestore.v1beta1.Firestore.ListDocuments', - index=1, - containing_service=None, - input_type=_LISTDOCUMENTSREQUEST, - output_type=_LISTDOCUMENTSRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002I\022G/v1beta1/{parent=projects/*/databases/*/documents/*/**}/{collection_id}')), - ), - _descriptor.MethodDescriptor( - name='CreateDocument', - full_name='google.firestore.v1beta1.Firestore.CreateDocument', - index=2, - containing_service=None, - input_type=_CREATEDOCUMENTREQUEST, - output_type=google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2._DOCUMENT, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002Q\"E/v1beta1/{parent=projects/*/databases/*/documents/**}/{collection_id}:\010document')), - ), - _descriptor.MethodDescriptor( - name='UpdateDocument', - full_name='google.firestore.v1beta1.Firestore.UpdateDocument', - index=3, - containing_service=None, - input_type=_UPDATEDOCUMENTREQUEST, - output_type=google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2._DOCUMENT, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002J2>/v1beta1/{document.name=projects/*/databases/*/documents/*/**}:\010document')), - ), - _descriptor.MethodDescriptor( - name='DeleteDocument', - full_name='google.firestore.v1beta1.Firestore.DeleteDocument', - index=4, - containing_service=None, - input_type=_DELETEDOCUMENTREQUEST, - output_type=google_dot_protobuf_dot_empty__pb2._EMPTY, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\0027*5/v1beta1/{name=projects/*/databases/*/documents/*/**}')), - ), - _descriptor.MethodDescriptor( - name='BatchGetDocuments', - full_name='google.firestore.v1beta1.Firestore.BatchGetDocuments', - index=5, - containing_service=None, - input_type=_BATCHGETDOCUMENTSREQUEST, - output_type=_BATCHGETDOCUMENTSRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002B\"=/v1beta1/{database=projects/*/databases/*}/documents:batchGet:\001*')), - ), - _descriptor.MethodDescriptor( - name='BeginTransaction', - full_name='google.firestore.v1beta1.Firestore.BeginTransaction', - index=6, - containing_service=None, - input_type=_BEGINTRANSACTIONREQUEST, - output_type=_BEGINTRANSACTIONRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002J\"E/v1beta1/{database=projects/*/databases/*}/documents:beginTransaction:\001*')), - ), - _descriptor.MethodDescriptor( - name='Commit', - full_name='google.firestore.v1beta1.Firestore.Commit', - index=7, - containing_service=None, - input_type=_COMMITREQUEST, - output_type=_COMMITRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002@\";/v1beta1/{database=projects/*/databases/*}/documents:commit:\001*')), - ), - _descriptor.MethodDescriptor( - name='Rollback', - full_name='google.firestore.v1beta1.Firestore.Rollback', - index=8, - containing_service=None, - input_type=_ROLLBACKREQUEST, - output_type=google_dot_protobuf_dot_empty__pb2._EMPTY, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002B\"=/v1beta1/{database=projects/*/databases/*}/documents:rollback:\001*')), - ), - _descriptor.MethodDescriptor( - name='RunQuery', - full_name='google.firestore.v1beta1.Firestore.RunQuery', - index=9, - containing_service=None, - input_type=_RUNQUERYREQUEST, - output_type=_RUNQUERYRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002@\";/v1beta1/{parent=projects/*/databases/*/documents}:runQuery:\001*')), - ), - _descriptor.MethodDescriptor( - name='Write', - full_name='google.firestore.v1beta1.Firestore.Write', - index=10, - containing_service=None, - input_type=_WRITEREQUEST, - output_type=_WRITERESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002?\":/v1beta1/{database=projects/*/databases/*}/documents:write:\001*')), - ), - _descriptor.MethodDescriptor( - name='Listen', - full_name='google.firestore.v1beta1.Firestore.Listen', - index=11, - containing_service=None, - input_type=_LISTENREQUEST, - output_type=_LISTENRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002@\";/v1beta1/{database=projects/*/databases/*}/documents:listen:\001*')), - ), - _descriptor.MethodDescriptor( - name='ListCollectionIds', - full_name='google.firestore.v1beta1.Firestore.ListCollectionIds', - index=12, - containing_service=None, - input_type=_LISTCOLLECTIONIDSREQUEST, - output_type=_LISTCOLLECTIONIDSRESPONSE, - options=_descriptor._ParseOptions(descriptor_pb2.MethodOptions(), _b('\202\323\344\223\002I\"D/v1beta1/{parent=projects/*/databases/*/documents}:listCollectionIds:\001*')), - ), -]) -_sym_db.RegisterServiceDescriptor(_FIRESTORE) - -DESCRIPTOR.services_by_name['Firestore'] = _FIRESTORE - try: # THESE ELEMENTS WILL BE DEPRECATED. # Please use the generated *_pb2_grpc.py files instead. diff --git a/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2_grpc.py b/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2_grpc.py index 10962f04eb1f..8c8b82d24fd5 100644 --- a/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2_grpc.py +++ b/firestore/google/cloud/firestore_v1beta1/proto/firestore_pb2_grpc.py @@ -1,9 +1,9 @@ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc -from google.cloud.firestore_v1beta1.proto import document_pb2 as google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2 -from google.cloud.firestore_v1beta1.proto import firestore_pb2 as google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_firestore__pb2 -from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 +import google.cloud.firestore_v1beta1.proto.document_pb2 as google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2 +import google.cloud.firestore_v1beta1.proto.firestore_pb2 as google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_firestore__pb2 +import google.protobuf.empty_pb2 as google_dot_protobuf_dot_empty__pb2 class FirestoreStub(object): diff --git a/firestore/google/cloud/firestore_v1beta1/proto/query_pb2.py b/firestore/google/cloud/firestore_v1beta1/proto/query_pb2.py index 386e36512e8e..a4e9a2d4752b 100644 --- a/firestore/google/cloud/firestore_v1beta1/proto/query_pb2.py +++ b/firestore/google/cloud/firestore_v1beta1/proto/query_pb2.py @@ -22,9 +22,10 @@ name='google/cloud/firestore_v1beta1/proto/query.proto', package='google.firestore.v1beta1', syntax='proto3', - serialized_pb=_b('\n0google/cloud/firestore_v1beta1/proto/query.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x33google/cloud/firestore_v1beta1/proto/document.proto\x1a\x1egoogle/protobuf/wrappers.proto\"\xa5\x0f\n\x0fStructuredQuery\x12\x44\n\x06select\x18\x01 \x01(\x0b\x32\x34.google.firestore.v1beta1.StructuredQuery.Projection\x12J\n\x04\x66rom\x18\x02 \x03(\x0b\x32<.google.firestore.v1beta1.StructuredQuery.CollectionSelector\x12?\n\x05where\x18\x03 \x01(\x0b\x32\x30.google.firestore.v1beta1.StructuredQuery.Filter\x12\x41\n\x08order_by\x18\x04 \x03(\x0b\x32/.google.firestore.v1beta1.StructuredQuery.Order\x12\x32\n\x08start_at\x18\x07 \x01(\x0b\x32 .google.firestore.v1beta1.Cursor\x12\x30\n\x06\x65nd_at\x18\x08 \x01(\x0b\x32 .google.firestore.v1beta1.Cursor\x12\x0e\n\x06offset\x18\x06 \x01(\x05\x12*\n\x05limit\x18\x05 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x1a\x44\n\x12\x43ollectionSelector\x12\x15\n\rcollection_id\x18\x02 \x01(\t\x12\x17\n\x0f\x61ll_descendants\x18\x03 \x01(\x08\x1a\x8c\x02\n\x06\x46ilter\x12U\n\x10\x63omposite_filter\x18\x01 \x01(\x0b\x32\x39.google.firestore.v1beta1.StructuredQuery.CompositeFilterH\x00\x12M\n\x0c\x66ield_filter\x18\x02 \x01(\x0b\x32\x35.google.firestore.v1beta1.StructuredQuery.FieldFilterH\x00\x12M\n\x0cunary_filter\x18\x03 \x01(\x0b\x32\x35.google.firestore.v1beta1.StructuredQuery.UnaryFilterH\x00\x42\r\n\x0b\x66ilter_type\x1a\xd3\x01\n\x0f\x43ompositeFilter\x12N\n\x02op\x18\x01 \x01(\x0e\x32\x42.google.firestore.v1beta1.StructuredQuery.CompositeFilter.Operator\x12\x41\n\x07\x66ilters\x18\x02 \x03(\x0b\x32\x30.google.firestore.v1beta1.StructuredQuery.Filter\"-\n\x08Operator\x12\x18\n\x14OPERATOR_UNSPECIFIED\x10\x00\x12\x07\n\x03\x41ND\x10\x01\x1a\xd8\x02\n\x0b\x46ieldFilter\x12G\n\x05\x66ield\x18\x01 \x01(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReference\x12J\n\x02op\x18\x02 \x01(\x0e\x32>.google.firestore.v1beta1.StructuredQuery.FieldFilter.Operator\x12.\n\x05value\x18\x03 \x01(\x0b\x32\x1f.google.firestore.v1beta1.Value\"\x83\x01\n\x08Operator\x12\x18\n\x14OPERATOR_UNSPECIFIED\x10\x00\x12\r\n\tLESS_THAN\x10\x01\x12\x16\n\x12LESS_THAN_OR_EQUAL\x10\x02\x12\x10\n\x0cGREATER_THAN\x10\x03\x12\x19\n\x15GREATER_THAN_OR_EQUAL\x10\x04\x12\t\n\x05\x45QUAL\x10\x05\x1a\xf3\x01\n\x0bUnaryFilter\x12J\n\x02op\x18\x01 \x01(\x0e\x32>.google.firestore.v1beta1.StructuredQuery.UnaryFilter.Operator\x12I\n\x05\x66ield\x18\x02 \x01(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReferenceH\x00\"=\n\x08Operator\x12\x18\n\x14OPERATOR_UNSPECIFIED\x10\x00\x12\n\n\x06IS_NAN\x10\x02\x12\x0b\n\x07IS_NULL\x10\x03\x42\x0e\n\x0coperand_type\x1a\x98\x01\n\x05Order\x12G\n\x05\x66ield\x18\x01 \x01(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReference\x12\x46\n\tdirection\x18\x02 \x01(\x0e\x32\x33.google.firestore.v1beta1.StructuredQuery.Direction\x1a$\n\x0e\x46ieldReference\x12\x12\n\nfield_path\x18\x02 \x01(\t\x1aV\n\nProjection\x12H\n\x06\x66ields\x18\x02 \x03(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReference\"E\n\tDirection\x12\x19\n\x15\x44IRECTION_UNSPECIFIED\x10\x00\x12\r\n\tASCENDING\x10\x01\x12\x0e\n\nDESCENDING\x10\x02\"I\n\x06\x43ursor\x12/\n\x06values\x18\x01 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Value\x12\x0e\n\x06\x62\x65\x66ore\x18\x02 \x01(\x08\x42\x97\x01\n\x1c\x63om.google.firestore.v1beta1B\nQueryProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1b\x06proto3') + serialized_pb=_b('\n0google/cloud/firestore_v1beta1/proto/query.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x33google/cloud/firestore_v1beta1/proto/document.proto\x1a\x1egoogle/protobuf/wrappers.proto\"\xa5\x0f\n\x0fStructuredQuery\x12\x44\n\x06select\x18\x01 \x01(\x0b\x32\x34.google.firestore.v1beta1.StructuredQuery.Projection\x12J\n\x04\x66rom\x18\x02 \x03(\x0b\x32<.google.firestore.v1beta1.StructuredQuery.CollectionSelector\x12?\n\x05where\x18\x03 \x01(\x0b\x32\x30.google.firestore.v1beta1.StructuredQuery.Filter\x12\x41\n\x08order_by\x18\x04 \x03(\x0b\x32/.google.firestore.v1beta1.StructuredQuery.Order\x12\x32\n\x08start_at\x18\x07 \x01(\x0b\x32 .google.firestore.v1beta1.Cursor\x12\x30\n\x06\x65nd_at\x18\x08 \x01(\x0b\x32 .google.firestore.v1beta1.Cursor\x12\x0e\n\x06offset\x18\x06 \x01(\x05\x12*\n\x05limit\x18\x05 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x1a\x44\n\x12\x43ollectionSelector\x12\x15\n\rcollection_id\x18\x02 \x01(\t\x12\x17\n\x0f\x61ll_descendants\x18\x03 \x01(\x08\x1a\x8c\x02\n\x06\x46ilter\x12U\n\x10\x63omposite_filter\x18\x01 \x01(\x0b\x32\x39.google.firestore.v1beta1.StructuredQuery.CompositeFilterH\x00\x12M\n\x0c\x66ield_filter\x18\x02 \x01(\x0b\x32\x35.google.firestore.v1beta1.StructuredQuery.FieldFilterH\x00\x12M\n\x0cunary_filter\x18\x03 \x01(\x0b\x32\x35.google.firestore.v1beta1.StructuredQuery.UnaryFilterH\x00\x42\r\n\x0b\x66ilter_type\x1a\xd3\x01\n\x0f\x43ompositeFilter\x12N\n\x02op\x18\x01 \x01(\x0e\x32\x42.google.firestore.v1beta1.StructuredQuery.CompositeFilter.Operator\x12\x41\n\x07\x66ilters\x18\x02 \x03(\x0b\x32\x30.google.firestore.v1beta1.StructuredQuery.Filter\"-\n\x08Operator\x12\x18\n\x14OPERATOR_UNSPECIFIED\x10\x00\x12\x07\n\x03\x41ND\x10\x01\x1a\xd8\x02\n\x0b\x46ieldFilter\x12G\n\x05\x66ield\x18\x01 \x01(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReference\x12J\n\x02op\x18\x02 \x01(\x0e\x32>.google.firestore.v1beta1.StructuredQuery.FieldFilter.Operator\x12.\n\x05value\x18\x03 \x01(\x0b\x32\x1f.google.firestore.v1beta1.Value\"\x83\x01\n\x08Operator\x12\x18\n\x14OPERATOR_UNSPECIFIED\x10\x00\x12\r\n\tLESS_THAN\x10\x01\x12\x16\n\x12LESS_THAN_OR_EQUAL\x10\x02\x12\x10\n\x0cGREATER_THAN\x10\x03\x12\x19\n\x15GREATER_THAN_OR_EQUAL\x10\x04\x12\t\n\x05\x45QUAL\x10\x05\x1a\xf3\x01\n\x0bUnaryFilter\x12J\n\x02op\x18\x01 \x01(\x0e\x32>.google.firestore.v1beta1.StructuredQuery.UnaryFilter.Operator\x12I\n\x05\x66ield\x18\x02 \x01(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReferenceH\x00\"=\n\x08Operator\x12\x18\n\x14OPERATOR_UNSPECIFIED\x10\x00\x12\n\n\x06IS_NAN\x10\x02\x12\x0b\n\x07IS_NULL\x10\x03\x42\x0e\n\x0coperand_type\x1a\x98\x01\n\x05Order\x12G\n\x05\x66ield\x18\x01 \x01(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReference\x12\x46\n\tdirection\x18\x02 \x01(\x0e\x32\x33.google.firestore.v1beta1.StructuredQuery.Direction\x1a$\n\x0e\x46ieldReference\x12\x12\n\nfield_path\x18\x02 \x01(\t\x1aV\n\nProjection\x12H\n\x06\x66ields\x18\x02 \x03(\x0b\x32\x38.google.firestore.v1beta1.StructuredQuery.FieldReference\"E\n\tDirection\x12\x19\n\x15\x44IRECTION_UNSPECIFIED\x10\x00\x12\r\n\tASCENDING\x10\x01\x12\x0e\n\nDESCENDING\x10\x02\"I\n\x06\x43ursor\x12/\n\x06values\x18\x01 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Value\x12\x0e\n\x06\x62\x65\x66ore\x18\x02 \x01(\x08\x42\xb8\x01\n\x1c\x63om.google.firestore.v1beta1B\nQueryProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1\xca\x02\x1eGoogle\\Cloud\\Firestore\\V1beta1b\x06proto3') , dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2.DESCRIPTOR,google_dot_protobuf_dot_wrappers__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -611,7 +612,6 @@ _CURSOR.fields_by_name['values'].message_type = google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2._VALUE DESCRIPTOR.message_types_by_name['StructuredQuery'] = _STRUCTUREDQUERY DESCRIPTOR.message_types_by_name['Cursor'] = _CURSOR -_sym_db.RegisterFileDescriptor(DESCRIPTOR) StructuredQuery = _reflection.GeneratedProtocolMessageType('StructuredQuery', (_message.Message,), dict( @@ -620,6 +620,17 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """A selection of a collection, such as ``messages as m1``. + + + Attributes: + collection_id: + The collection ID. When set, selects only collections with + this ID. + all_descendants: + When false, selects only collections that are immediate + children of the ``parent`` specified in the containing + ``RunQueryRequest``. When true, selects all descendant + collections. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.CollectionSelector) )) @@ -630,6 +641,17 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """A filter. + + + Attributes: + filter_type: + The type of filter. + composite_filter: + A composite filter. + field_filter: + A filter on a document field. + unary_filter: + A filter that takes exactly one argument. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.Filter) )) @@ -640,6 +662,14 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """A filter that merges multiple other filters using the given operator. + + + Attributes: + op: + The operator for combining multiple filters. + filters: + The list of filters to combine. Must contain at least one + filter. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.CompositeFilter) )) @@ -650,6 +680,15 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """A filter on a specific field. + + + Attributes: + field: + The field to filter by. + op: + The operator to filter by. + value: + The value to compare to. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.FieldFilter) )) @@ -660,6 +699,15 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """A filter with a single operand. + + + Attributes: + op: + The unary operator to apply. + operand_type: + The argument to the filter. + field: + The field to which to apply the operator. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.UnaryFilter) )) @@ -670,6 +718,13 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """An order on a field. + + + Attributes: + field: + The field to order by. + direction: + The direction to order by. Defaults to ``ASCENDING``. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.Order) )) @@ -690,6 +745,12 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.query_pb2' , __doc__ = """The projection of document's fields to return. + + + Attributes: + fields: + The fields to return. If empty, all fields are returned. To + only return the name of the document, use ``['__name__']``. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.StructuredQuery.Projection) )) @@ -701,38 +762,6 @@ Attributes: - collection_id: - The collection ID. When set, selects only collections with - this ID. - all_descendants: - When false, selects only collections that are immediate - children of the ``parent`` specified in the containing - ``RunQueryRequest``. When true, selects all descendant - collections. - filter_type: - The type of filter. - composite_filter: - A composite filter. - field_filter: - A filter on a document field. - unary_filter: - A filter that takes exactly one argument. - op: - The unary operator to apply. - filters: - The list of filters to combine. Must contain at least one - filter. - field: - The field to order by. - value: - The value to compare to. - operand_type: - The argument to the filter. - direction: - The direction to order by. Defaults to ``ASCENDING``. - fields: - The fields to return. If empty, all fields are returned. To - only return the name of the document, use ``['__name__']``. select: The projection to return. from: @@ -799,7 +828,7 @@ DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\nQueryProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1')) +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\nQueryProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1\312\002\036Google\\Cloud\\Firestore\\V1beta1')) try: # THESE ELEMENTS WILL BE DEPRECATED. # Please use the generated *_pb2_grpc.py files instead. diff --git a/firestore/google/cloud/firestore_v1beta1/proto/write_pb2.py b/firestore/google/cloud/firestore_v1beta1/proto/write_pb2.py index 8dcd96432ab1..8d4f9a7d29c3 100644 --- a/firestore/google/cloud/firestore_v1beta1/proto/write_pb2.py +++ b/firestore/google/cloud/firestore_v1beta1/proto/write_pb2.py @@ -23,9 +23,10 @@ name='google/cloud/firestore_v1beta1/proto/write.proto', package='google.firestore.v1beta1', syntax='proto3', - serialized_pb=_b('\n0google/cloud/firestore_v1beta1/proto/write.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x31google/cloud/firestore_v1beta1/proto/common.proto\x1a\x33google/cloud/firestore_v1beta1/proto/document.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\x9d\x02\n\x05Write\x12\x34\n\x06update\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.DocumentH\x00\x12\x10\n\x06\x64\x65lete\x18\x02 \x01(\tH\x00\x12@\n\ttransform\x18\x06 \x01(\x0b\x32+.google.firestore.v1beta1.DocumentTransformH\x00\x12;\n\x0bupdate_mask\x18\x03 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12@\n\x10\x63urrent_document\x18\x04 \x01(\x0b\x32&.google.firestore.v1beta1.PreconditionB\x0b\n\toperation\"\xda\x02\n\x11\x44ocumentTransform\x12\x10\n\x08\x64ocument\x18\x01 \x01(\t\x12T\n\x10\x66ield_transforms\x18\x02 \x03(\x0b\x32:.google.firestore.v1beta1.DocumentTransform.FieldTransform\x1a\xdc\x01\n\x0e\x46ieldTransform\x12\x12\n\nfield_path\x18\x01 \x01(\t\x12\x65\n\x13set_to_server_value\x18\x02 \x01(\x0e\x32\x46.google.firestore.v1beta1.DocumentTransform.FieldTransform.ServerValueH\x00\"=\n\x0bServerValue\x12\x1c\n\x18SERVER_VALUE_UNSPECIFIED\x10\x00\x12\x10\n\x0cREQUEST_TIME\x10\x01\x42\x10\n\x0etransform_type\"z\n\x0bWriteResult\x12/\n\x0bupdate_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x11transform_results\x18\x02 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Value\"v\n\x0e\x44ocumentChange\x12\x34\n\x08\x64ocument\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12\x12\n\ntarget_ids\x18\x05 \x03(\x05\x12\x1a\n\x12removed_target_ids\x18\x06 \x03(\x05\"m\n\x0e\x44ocumentDelete\x12\x10\n\x08\x64ocument\x18\x01 \x01(\t\x12\x1a\n\x12removed_target_ids\x18\x06 \x03(\x05\x12-\n\tread_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"m\n\x0e\x44ocumentRemove\x12\x10\n\x08\x64ocument\x18\x01 \x01(\t\x12\x1a\n\x12removed_target_ids\x18\x02 \x03(\x05\x12-\n\tread_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"3\n\x0f\x45xistenceFilter\x12\x11\n\ttarget_id\x18\x01 \x01(\x05\x12\r\n\x05\x63ount\x18\x02 \x01(\x05\x42\x97\x01\n\x1c\x63om.google.firestore.v1beta1B\nWriteProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1b\x06proto3') + serialized_pb=_b('\n0google/cloud/firestore_v1beta1/proto/write.proto\x12\x18google.firestore.v1beta1\x1a\x1cgoogle/api/annotations.proto\x1a\x31google/cloud/firestore_v1beta1/proto/common.proto\x1a\x33google/cloud/firestore_v1beta1/proto/document.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\x9d\x02\n\x05Write\x12\x34\n\x06update\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.DocumentH\x00\x12\x10\n\x06\x64\x65lete\x18\x02 \x01(\tH\x00\x12@\n\ttransform\x18\x06 \x01(\x0b\x32+.google.firestore.v1beta1.DocumentTransformH\x00\x12;\n\x0bupdate_mask\x18\x03 \x01(\x0b\x32&.google.firestore.v1beta1.DocumentMask\x12@\n\x10\x63urrent_document\x18\x04 \x01(\x0b\x32&.google.firestore.v1beta1.PreconditionB\x0b\n\toperation\"\xda\x02\n\x11\x44ocumentTransform\x12\x10\n\x08\x64ocument\x18\x01 \x01(\t\x12T\n\x10\x66ield_transforms\x18\x02 \x03(\x0b\x32:.google.firestore.v1beta1.DocumentTransform.FieldTransform\x1a\xdc\x01\n\x0e\x46ieldTransform\x12\x12\n\nfield_path\x18\x01 \x01(\t\x12\x65\n\x13set_to_server_value\x18\x02 \x01(\x0e\x32\x46.google.firestore.v1beta1.DocumentTransform.FieldTransform.ServerValueH\x00\"=\n\x0bServerValue\x12\x1c\n\x18SERVER_VALUE_UNSPECIFIED\x10\x00\x12\x10\n\x0cREQUEST_TIME\x10\x01\x42\x10\n\x0etransform_type\"z\n\x0bWriteResult\x12/\n\x0bupdate_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x11transform_results\x18\x02 \x03(\x0b\x32\x1f.google.firestore.v1beta1.Value\"v\n\x0e\x44ocumentChange\x12\x34\n\x08\x64ocument\x18\x01 \x01(\x0b\x32\".google.firestore.v1beta1.Document\x12\x12\n\ntarget_ids\x18\x05 \x03(\x05\x12\x1a\n\x12removed_target_ids\x18\x06 \x03(\x05\"m\n\x0e\x44ocumentDelete\x12\x10\n\x08\x64ocument\x18\x01 \x01(\t\x12\x1a\n\x12removed_target_ids\x18\x06 \x03(\x05\x12-\n\tread_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"m\n\x0e\x44ocumentRemove\x12\x10\n\x08\x64ocument\x18\x01 \x01(\t\x12\x1a\n\x12removed_target_ids\x18\x02 \x03(\x05\x12-\n\tread_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"3\n\x0f\x45xistenceFilter\x12\x11\n\ttarget_id\x18\x01 \x01(\x05\x12\r\n\x05\x63ount\x18\x02 \x01(\x05\x42\xb8\x01\n\x1c\x63om.google.firestore.v1beta1B\nWriteProtoP\x01ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\xa2\x02\x04GCFS\xaa\x02\x1eGoogle.Cloud.Firestore.V1Beta1\xca\x02\x1eGoogle\\Cloud\\Firestore\\V1beta1b\x06proto3') , dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_common__pb2.DESCRIPTOR,google_dot_cloud_dot_firestore__v1beta1_dot_proto_dot_document__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -435,7 +436,6 @@ DESCRIPTOR.message_types_by_name['DocumentDelete'] = _DOCUMENTDELETE DESCRIPTOR.message_types_by_name['DocumentRemove'] = _DOCUMENTREMOVE DESCRIPTOR.message_types_by_name['ExistenceFilter'] = _EXISTENCEFILTER -_sym_db.RegisterFileDescriptor(DESCRIPTOR) Write = _reflection.GeneratedProtocolMessageType('Write', (_message.Message,), dict( DESCRIPTOR = _WRITE, @@ -481,6 +481,17 @@ __module__ = 'google.cloud.firestore_v1beta1.proto.write_pb2' , __doc__ = """A transformation of a field of the document. + + + Attributes: + field_path: + The path of the field. See + [Document.fields][google.firestore.v1beta1.Document.fields] + for the field path syntax reference. + transform_type: + The transformation to apply on the field. + set_to_server_value: + Sets the field to the given server value. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.DocumentTransform.FieldTransform) )) @@ -492,19 +503,11 @@ Attributes: - field_path: - The path of the field. See - [Document.fields][google.firestore.v1beta1.Document.fields] - for the field path syntax reference. - transform_type: - The transformation to apply on the field. - set_to_server_value: - Sets the field to the given server value. document: The name of the document to transform. field_transforms: The list of transformations to apply to the fields of the - document, in order. + document, in order. This must not be empty. """, # @@protoc_insertion_point(class_scope:google.firestore.v1beta1.DocumentTransform) )) @@ -648,7 +651,7 @@ DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\nWriteProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1')) +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.firestore.v1beta1B\nWriteProtoP\001ZAgoogle.golang.org/genproto/googleapis/firestore/v1beta1;firestore\242\002\004GCFS\252\002\036Google.Cloud.Firestore.V1Beta1\312\002\036Google\\Cloud\\Firestore\\V1beta1')) try: # THESE ELEMENTS WILL BE DEPRECATED. # Please use the generated *_pb2_grpc.py files instead. diff --git a/firestore/google/cloud/firestore_v1beta1/query.py b/firestore/google/cloud/firestore_v1beta1/query.py index 5c133ad72e09..2f2be6177453 100644 --- a/firestore/google/cloud/firestore_v1beta1/query.py +++ b/firestore/google/cloud/firestore_v1beta1/query.py @@ -581,8 +581,7 @@ def get(self, transaction=None): parent_path, expected_prefix = self._parent._parent_info() response_iterator = self._client._firestore_api.run_query( parent_path, self._to_protobuf(), - transaction=_helpers.get_transaction_id(transaction), - options=self._client._call_options) + transaction=_helpers.get_transaction_id(transaction)) empty_stream = False for index, response_pb in enumerate(response_iterator): diff --git a/firestore/google/cloud/firestore_v1beta1/transaction.py b/firestore/google/cloud/firestore_v1beta1/transaction.py index f272d023f8d8..78c057297b55 100644 --- a/firestore/google/cloud/firestore_v1beta1/transaction.py +++ b/firestore/google/cloud/firestore_v1beta1/transaction.py @@ -18,11 +18,11 @@ import random import time -import google.gax.errors -import google.gax.grpc import grpc import six +from google.api_core import exceptions +from google.api_core import retry from google.cloud.firestore_v1beta1 import _helpers from google.cloud.firestore_v1beta1 import batch from google.cloud.firestore_v1beta1 import types @@ -153,7 +153,6 @@ def _begin(self, retry_id=None): transaction_response = self._client._firestore_api.begin_transaction( self._client._database_string, options_=self._options_protobuf(retry_id), - options=self._client._call_options, ) self._id = transaction_response.transaction @@ -177,8 +176,7 @@ def _rollback(self): try: # NOTE: The response is just ``google.protobuf.Empty``. self._client._firestore_api.rollback( - self._client._database_string, self._id, - options=self._client._call_options) + self._client._database_string, self._id) finally: self._clean_up() @@ -198,9 +196,8 @@ def _commit(self): if not self.in_progress: raise ValueError(_CANT_COMMIT) - with _helpers.remap_gax_error_on_commit(): - commit_response = _commit_with_retry( - self._client, self._write_pbs, self._id) + commit_response = self._client._firestore_api.commit(self._client._database_string, + self._write_pbs, transaction=self._id) self._clean_up() return list(commit_response.write_results) @@ -284,16 +281,14 @@ def _maybe_commit(self, transaction): try: transaction._commit() return True - except google.gax.errors.GaxError as exc: + except exceptions.GoogleAPICallError as exc: if transaction._read_only: - raise - - status_code = google.gax.grpc.exc_to_code(exc.cause) + raise exc # If a read-write transaction returns ABORTED, retry. - if status_code == grpc.StatusCode.ABORTED: + if exc.grpc_status_code == grpc.StatusCode.ABORTED: return False else: - raise + raise exc def __call__(self, transaction, *args, **kwargs): """Execute the wrapped callable within a transaction. @@ -345,75 +340,3 @@ def transactional(to_wrap): wrapped callable. """ return _Transactional(to_wrap) - - -def _commit_with_retry(client, write_pbs, transaction_id): - """Call ``Commit`` on the GAPIC client with retry / sleep. - - This function is **distinct** from - :func:`~.firestore_v1beta1._helpers.remap_gax_error_on_commit` in - that it does not seek to re-wrap exceptions, it just seeks to retry. - - Retries the ``Commit`` RPC on Unavailable. Usually this RPC-level - retry is handled by the underlying GAPICd client, but in this case it - doesn't because ``Commit`` is not always idempotent. But here we know it - is "idempotent"-like because it has a transaction ID. We also need to do - our own retry to special-case the ``INVALID_ARGUMENT`` error. - - Args: - client (~.firestore_v1beta1.client.Client): A client with - GAPIC client and configuration details. - write_pbs (List[google.cloud.proto.firestore.v1beta1.\ - write_pb2.Write, ...]): A ``Write`` protobuf instance to - be committed. - transaction_id (bytes): ID of an existing transaction that - this commit will run in. - - Returns: - google.cloud.firestore_v1beta1.types.CommitResponse: - The protobuf response from ``Commit``. - - Raises: - ~google.gax.errors.GaxError: If a non-retryable exception - is encountered. - """ - current_sleep = _INITIAL_SLEEP - while True: - try: - return client._firestore_api.commit( - client._database_string, write_pbs, - transaction=transaction_id, - options=client._call_options) - except google.gax.errors.GaxError as exc: - status_code = google.gax.grpc.exc_to_code(exc.cause) - if status_code == grpc.StatusCode.UNAVAILABLE: - pass # Retry - else: - raise - - current_sleep = _sleep(current_sleep) - - -def _sleep(current_sleep, max_sleep=_MAX_SLEEP, multiplier=_MULTIPLIER): - """Sleep and produce a new sleep time. - - .. _Exponential Backoff And Jitter: https://www.awsarchitectureblog.com/\ - 2015/03/backoff.html - - Select a duration between zero and ``current_sleep``. It might seem - counterintuitive to have so much jitter, but - `Exponential Backoff And Jitter`_ argues that "full jitter" is - the best strategy. - - Args: - current_sleep (float): The current "max" for sleep interval. - max_sleep (Optional[float]): Eventual "max" sleep time - multiplier (Optional[float]): Multiplier for exponential backoff. - - Returns: - float: Newly doubled ``current_sleep`` or ``max_sleep`` (whichever - is smaller) - """ - actual_sleep = random.uniform(0.0, current_sleep) - time.sleep(actual_sleep) - return min(multiplier * current_sleep, max_sleep) diff --git a/firestore/google/cloud/firestore_v1beta1/types.py b/firestore/google/cloud/firestore_v1beta1/types.py index c0bc9e6456b8..43804fd3876b 100644 --- a/firestore/google/cloud/firestore_v1beta1/types.py +++ b/firestore/google/cloud/firestore_v1beta1/types.py @@ -1,10 +1,10 @@ -# Copyright 2017, Google LLC All rights reserved. +# Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -15,7 +15,7 @@ from __future__ import absolute_import import sys -from google.gax.utils.messages import get_messages +from google.api_core.protobuf_helpers import get_messages from google.api import http_pb2 from google.cloud.firestore_v1beta1.proto import common_pb2 @@ -23,9 +23,6 @@ from google.cloud.firestore_v1beta1.proto import firestore_pb2 from google.cloud.firestore_v1beta1.proto import query_pb2 from google.cloud.firestore_v1beta1.proto import write_pb2 -from google.cloud.firestore_v1beta1.proto.admin import firestore_admin_pb2 -from google.cloud.firestore_v1beta1.proto.admin import index_pb2 -from google.longrunning import operations_pb2 from google.protobuf import any_pb2 from google.protobuf import descriptor_pb2 from google.protobuf import empty_pb2 @@ -40,12 +37,9 @@ http_pb2, common_pb2, document_pb2, - firestore_admin_pb2, firestore_pb2, - index_pb2, query_pb2, write_pb2, - operations_pb2, any_pb2, descriptor_pb2, empty_pb2, @@ -53,7 +47,8 @@ timestamp_pb2, wrappers_pb2, status_pb2, - latlng_pb2, ): + latlng_pb2, +): for name, message in get_messages(module).items(): message.__module__ = 'google.cloud.firestore_v1beta1.types' setattr(sys.modules[__name__], name, message) diff --git a/firestore/setup.py b/firestore/setup.py index 51ae8a10f8a9..8bc1bc73e056 100644 --- a/firestore/setup.py +++ b/firestore/setup.py @@ -52,7 +52,7 @@ REQUIREMENTS = [ 'google-cloud-core >= 0.28.0, < 0.29dev', 'google-api-core >= 0.1.1, < 0.2.0dev', - 'google-gax >= 0.15.7, < 0.16dev', + 'grpcio >= 1.8.2' ] setuptools.setup( diff --git a/firestore/tests/system.py b/firestore/tests/system.py index 082e42262b43..fabb2819b1cc 100644 --- a/firestore/tests/system.py +++ b/firestore/tests/system.py @@ -19,8 +19,6 @@ import re from google.auth._default import _load_credentials_from_file -from google.gax.errors import GaxError -from google.gax.grpc import exc_to_code from google.protobuf import timestamp_pb2 from grpc import StatusCode import pytest @@ -117,7 +115,6 @@ def test_cannot_use_foreign_key(client, cleanup): database='dee-bee') assert other_client._database_string != client._database_string fake_doc = other_client.document('foo', 'bar') - # NOTE: google-gax **does not** raise a GaxError for INVALID_ARGUMENT. with pytest.raises(ValueError) as exc_info: document.create({'ref': fake_doc}) @@ -177,8 +174,7 @@ def test_document_set(client, cleanup): # 4. Call ``set()`` with invalid (in the past) "last timestamp" option. assert_timestamp_less(option3._last_update_time, snapshot3.update_time) - with pytest.raises(GaxError) as exc_info: - document.set({'bad': 'time-past'}, option=option3) + document.set({'bad': 'time-past'}, option=option3) assert exc_to_code(exc_info.value.cause) == StatusCode.FAILED_PRECONDITION @@ -188,8 +184,7 @@ def test_document_set(client, cleanup): nanos=snapshot3.update_time.nanos, ) option5 = client.write_option(last_update_time=timestamp_pb) - with pytest.raises(GaxError) as exc_info: - document.set({'bad': 'time-future'}, option=option5) + document.set({'bad': 'time-future'}, option=option5) assert exc_to_code(exc_info.value.cause) == StatusCode.FAILED_PRECONDITION @@ -259,8 +254,7 @@ def test_update_document(client, cleanup): # 5. Call ``update()`` with invalid (in the past) "last timestamp" option. assert_timestamp_less(option4._last_update_time, snapshot4.update_time) - with pytest.raises(GaxError) as exc_info: - document.update({'bad': 'time-past'}, option=option4) + document.update({'bad': 'time-past'}, option=option4) assert exc_to_code(exc_info.value.cause) == StatusCode.FAILED_PRECONDITION @@ -270,8 +264,7 @@ def test_update_document(client, cleanup): nanos=snapshot4.update_time.nanos, ) option6 = client.write_option(last_update_time=timestamp_pb) - with pytest.raises(GaxError) as exc_info: - document.set({'bad': 'time-future'}, option=option6) + document.set({'bad': 'time-future'}, option=option6) assert exc_to_code(exc_info.value.cause) == StatusCode.FAILED_PRECONDITION @@ -336,8 +329,7 @@ def test_document_delete(client, cleanup): nanos=snapshot1.update_time.nanos, ) option1 = client.write_option(last_update_time=timestamp_pb) - with pytest.raises(GaxError) as exc_info: - document.delete(option=option1) + document.delete(option=option1) assert exc_to_code(exc_info.value.cause) == StatusCode.FAILED_PRECONDITION @@ -347,8 +339,8 @@ def test_document_delete(client, cleanup): nanos=snapshot1.update_time.nanos, ) option2 = client.write_option(last_update_time=timestamp_pb) - with pytest.raises(GaxError) as exc_info: - document.delete(option=option2) + + document.delete(option=option2) assert exc_to_code(exc_info.value.cause) == StatusCode.FAILED_PRECONDITION diff --git a/firestore/tests/system/gapic/v1beta1/test_firestore_client_v1beta1.py b/firestore/tests/system/gapic/v1beta1/test_firestore_client_v1beta1.py new file mode 100644 index 000000000000..284265769eac --- /dev/null +++ b/firestore/tests/system/gapic/v1beta1/test_firestore_client_v1beta1.py @@ -0,0 +1,569 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Unit tests.""" + +import pytest + +from google.cloud import firestore_v1beta1 +from google.cloud.firestore_v1beta1.proto import common_pb2 +from google.cloud.firestore_v1beta1.proto import document_pb2 +from google.cloud.firestore_v1beta1.proto import firestore_pb2 +from google.protobuf import empty_pb2 + + +class MultiCallableStub(object): + """Stub for the grpc.UnaryUnaryMultiCallable interface.""" + + def __init__(self, method, channel_stub): + self.method = method + self.channel_stub = channel_stub + + def __call__(self, request, timeout=None, metadata=None, credentials=None): + self.channel_stub.requests.append((self.method, request)) + + response = None + if self.channel_stub.responses: + response = self.channel_stub.responses.pop() + + if isinstance(response, Exception): + raise response + + if response: + return response + + +class ChannelStub(object): + """Stub for the grpc.Channel interface.""" + + def __init__(self, responses=[]): + self.responses = responses + self.requests = [] + + def unary_unary(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + def unary_stream(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + def stream_stream(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + +class CustomException(Exception): + pass + + +class TestFirestoreClient(object): + def test_get_document(self): + # Setup Expected Response + name_2 = 'name2-1052831874' + expected_response = {'name': name_2} + expected_response = document_pb2.Document(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + response = client.get_document(name) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.GetDocumentRequest(name=name) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_get_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + with pytest.raises(CustomException): + client.get_document(name) + + def test_list_documents(self): + # Setup Expected Response + next_page_token = '' + documents_element = {} + documents = [documents_element] + expected_response = { + 'next_page_token': next_page_token, + 'documents': documents + } + expected_response = firestore_pb2.ListDocumentsResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + + paged_list_response = client.list_documents(parent, collection_id) + resources = list(paged_list_response) + assert len(resources) == 1 + + assert expected_response.documents[0] == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.ListDocumentsRequest( + parent=parent, collection_id=collection_id) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_list_documents_exception(self): + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + + paged_list_response = client.list_documents(parent, collection_id) + with pytest.raises(CustomException): + list(paged_list_response) + + def test_create_document(self): + # Setup Expected Response + name = 'name3373707' + expected_response = {'name': name} + expected_response = document_pb2.Document(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + document_id = 'documentId506676927' + document = {} + + response = client.create_document(parent, collection_id, document_id, + document) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.CreateDocumentRequest( + parent=parent, + collection_id=collection_id, + document_id=document_id, + document=document) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_create_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + document_id = 'documentId506676927' + document = {} + + with pytest.raises(CustomException): + client.create_document(parent, collection_id, document_id, + document) + + def test_update_document(self): + # Setup Expected Response + name = 'name3373707' + expected_response = {'name': name} + expected_response = document_pb2.Document(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + document = {} + update_mask = {} + + response = client.update_document(document, update_mask) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.UpdateDocumentRequest( + document=document, update_mask=update_mask) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_update_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + document = {} + update_mask = {} + + with pytest.raises(CustomException): + client.update_document(document, update_mask) + + def test_delete_document(self): + channel = ChannelStub() + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + client.delete_document(name) + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.DeleteDocumentRequest(name=name) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_delete_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + with pytest.raises(CustomException): + client.delete_document(name) + + def test_batch_get_documents(self): + # Setup Expected Response + missing = 'missing1069449574' + transaction = b'-34' + expected_response = {'missing': missing, 'transaction': transaction} + expected_response = firestore_pb2.BatchGetDocumentsResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + documents = [] + + response = client.batch_get_documents(database, documents) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.BatchGetDocumentsRequest( + database=database, documents=documents) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_batch_get_documents_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + documents = [] + + with pytest.raises(CustomException): + client.batch_get_documents(database, documents) + + def test_begin_transaction(self): + # Setup Expected Response + transaction = b'-34' + expected_response = {'transaction': transaction} + expected_response = firestore_pb2.BeginTransactionResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + + response = client.begin_transaction(database) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.BeginTransactionRequest( + database=database) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_begin_transaction_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + + with pytest.raises(CustomException): + client.begin_transaction(database) + + def test_commit(self): + # Setup Expected Response + expected_response = {} + expected_response = firestore_pb2.CommitResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + writes = [] + + response = client.commit(database, writes) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.CommitRequest( + database=database, writes=writes) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_commit_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + writes = [] + + with pytest.raises(CustomException): + client.commit(database, writes) + + def test_rollback(self): + channel = ChannelStub() + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + transaction = b'-34' + + client.rollback(database, transaction) + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.RollbackRequest( + database=database, transaction=transaction) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_rollback_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + transaction = b'-34' + + with pytest.raises(CustomException): + client.rollback(database, transaction) + + def test_run_query(self): + # Setup Expected Response + transaction = b'-34' + skipped_results = 880286183 + expected_response = { + 'transaction': transaction, + 'skipped_results': skipped_results + } + expected_response = firestore_pb2.RunQueryResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + response = client.run_query(parent) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.RunQueryRequest(parent=parent) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_run_query_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + with pytest.raises(CustomException): + client.run_query(parent) + + def test_write(self): + # Setup Expected Response + stream_id = 'streamId-315624902' + stream_token = b'122' + expected_response = { + 'stream_id': stream_id, + 'stream_token': stream_token + } + expected_response = firestore_pb2.WriteResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + request = firestore_pb2.WriteRequest(**request) + requests = [request] + + response = client.write(requests) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + actual_requests = channel.requests[0][1] + assert len(actual_requests) == 1 + actual_request = list(actual_requests)[0] + assert request == actual_request + + def test_write_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + + request = firestore_pb2.WriteRequest(**request) + requests = [request] + + with pytest.raises(CustomException): + client.write(requests) + + def test_listen(self): + # Setup Expected Response + expected_response = {} + expected_response = firestore_pb2.ListenResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + request = firestore_pb2.ListenRequest(**request) + requests = [request] + + response = client.listen(requests) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + actual_requests = channel.requests[0][1] + assert len(actual_requests) == 1 + actual_request = list(actual_requests)[0] + assert request == actual_request + + def test_listen_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + + request = firestore_pb2.ListenRequest(**request) + requests = [request] + + with pytest.raises(CustomException): + client.listen(requests) + + def test_list_collection_ids(self): + # Setup Expected Response + next_page_token = '' + collection_ids_element = 'collectionIdsElement1368994900' + collection_ids = [collection_ids_element] + expected_response = { + 'next_page_token': next_page_token, + 'collection_ids': collection_ids + } + expected_response = firestore_pb2.ListCollectionIdsResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + paged_list_response = client.list_collection_ids(parent) + resources = list(paged_list_response) + assert len(resources) == 1 + + assert expected_response.collection_ids[0] == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.ListCollectionIdsRequest( + parent=parent) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_list_collection_ids_exception(self): + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + paged_list_response = client.list_collection_ids(parent) + with pytest.raises(CustomException): + list(paged_list_response) diff --git a/firestore/tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py b/firestore/tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py new file mode 100644 index 000000000000..284265769eac --- /dev/null +++ b/firestore/tests/unit/gapic/v1beta1/test_firestore_client_v1beta1.py @@ -0,0 +1,569 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Unit tests.""" + +import pytest + +from google.cloud import firestore_v1beta1 +from google.cloud.firestore_v1beta1.proto import common_pb2 +from google.cloud.firestore_v1beta1.proto import document_pb2 +from google.cloud.firestore_v1beta1.proto import firestore_pb2 +from google.protobuf import empty_pb2 + + +class MultiCallableStub(object): + """Stub for the grpc.UnaryUnaryMultiCallable interface.""" + + def __init__(self, method, channel_stub): + self.method = method + self.channel_stub = channel_stub + + def __call__(self, request, timeout=None, metadata=None, credentials=None): + self.channel_stub.requests.append((self.method, request)) + + response = None + if self.channel_stub.responses: + response = self.channel_stub.responses.pop() + + if isinstance(response, Exception): + raise response + + if response: + return response + + +class ChannelStub(object): + """Stub for the grpc.Channel interface.""" + + def __init__(self, responses=[]): + self.responses = responses + self.requests = [] + + def unary_unary(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + def unary_stream(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + def stream_stream(self, + method, + request_serializer=None, + response_deserializer=None): + return MultiCallableStub(method, self) + + +class CustomException(Exception): + pass + + +class TestFirestoreClient(object): + def test_get_document(self): + # Setup Expected Response + name_2 = 'name2-1052831874' + expected_response = {'name': name_2} + expected_response = document_pb2.Document(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + response = client.get_document(name) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.GetDocumentRequest(name=name) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_get_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + with pytest.raises(CustomException): + client.get_document(name) + + def test_list_documents(self): + # Setup Expected Response + next_page_token = '' + documents_element = {} + documents = [documents_element] + expected_response = { + 'next_page_token': next_page_token, + 'documents': documents + } + expected_response = firestore_pb2.ListDocumentsResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + + paged_list_response = client.list_documents(parent, collection_id) + resources = list(paged_list_response) + assert len(resources) == 1 + + assert expected_response.documents[0] == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.ListDocumentsRequest( + parent=parent, collection_id=collection_id) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_list_documents_exception(self): + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + + paged_list_response = client.list_documents(parent, collection_id) + with pytest.raises(CustomException): + list(paged_list_response) + + def test_create_document(self): + # Setup Expected Response + name = 'name3373707' + expected_response = {'name': name} + expected_response = document_pb2.Document(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + document_id = 'documentId506676927' + document = {} + + response = client.create_document(parent, collection_id, document_id, + document) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.CreateDocumentRequest( + parent=parent, + collection_id=collection_id, + document_id=document_id, + document=document) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_create_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + collection_id = 'collectionId-821242276' + document_id = 'documentId506676927' + document = {} + + with pytest.raises(CustomException): + client.create_document(parent, collection_id, document_id, + document) + + def test_update_document(self): + # Setup Expected Response + name = 'name3373707' + expected_response = {'name': name} + expected_response = document_pb2.Document(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + document = {} + update_mask = {} + + response = client.update_document(document, update_mask) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.UpdateDocumentRequest( + document=document, update_mask=update_mask) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_update_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + document = {} + update_mask = {} + + with pytest.raises(CustomException): + client.update_document(document, update_mask) + + def test_delete_document(self): + channel = ChannelStub() + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + client.delete_document(name) + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.DeleteDocumentRequest(name=name) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_delete_document_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + name = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + with pytest.raises(CustomException): + client.delete_document(name) + + def test_batch_get_documents(self): + # Setup Expected Response + missing = 'missing1069449574' + transaction = b'-34' + expected_response = {'missing': missing, 'transaction': transaction} + expected_response = firestore_pb2.BatchGetDocumentsResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + documents = [] + + response = client.batch_get_documents(database, documents) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.BatchGetDocumentsRequest( + database=database, documents=documents) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_batch_get_documents_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + documents = [] + + with pytest.raises(CustomException): + client.batch_get_documents(database, documents) + + def test_begin_transaction(self): + # Setup Expected Response + transaction = b'-34' + expected_response = {'transaction': transaction} + expected_response = firestore_pb2.BeginTransactionResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + + response = client.begin_transaction(database) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.BeginTransactionRequest( + database=database) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_begin_transaction_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + + with pytest.raises(CustomException): + client.begin_transaction(database) + + def test_commit(self): + # Setup Expected Response + expected_response = {} + expected_response = firestore_pb2.CommitResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + writes = [] + + response = client.commit(database, writes) + assert expected_response == response + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.CommitRequest( + database=database, writes=writes) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_commit_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + writes = [] + + with pytest.raises(CustomException): + client.commit(database, writes) + + def test_rollback(self): + channel = ChannelStub() + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + transaction = b'-34' + + client.rollback(database, transaction) + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.RollbackRequest( + database=database, transaction=transaction) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_rollback_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + transaction = b'-34' + + with pytest.raises(CustomException): + client.rollback(database, transaction) + + def test_run_query(self): + # Setup Expected Response + transaction = b'-34' + skipped_results = 880286183 + expected_response = { + 'transaction': transaction, + 'skipped_results': skipped_results + } + expected_response = firestore_pb2.RunQueryResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + response = client.run_query(parent) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.RunQueryRequest(parent=parent) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_run_query_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + with pytest.raises(CustomException): + client.run_query(parent) + + def test_write(self): + # Setup Expected Response + stream_id = 'streamId-315624902' + stream_token = b'122' + expected_response = { + 'stream_id': stream_id, + 'stream_token': stream_token + } + expected_response = firestore_pb2.WriteResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + request = firestore_pb2.WriteRequest(**request) + requests = [request] + + response = client.write(requests) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + actual_requests = channel.requests[0][1] + assert len(actual_requests) == 1 + actual_request = list(actual_requests)[0] + assert request == actual_request + + def test_write_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + + request = firestore_pb2.WriteRequest(**request) + requests = [request] + + with pytest.raises(CustomException): + client.write(requests) + + def test_listen(self): + # Setup Expected Response + expected_response = {} + expected_response = firestore_pb2.ListenResponse(**expected_response) + + # Mock the API response + channel = ChannelStub(responses=[iter([expected_response])]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + request = firestore_pb2.ListenRequest(**request) + requests = [request] + + response = client.listen(requests) + resources = list(response) + assert len(resources) == 1 + assert expected_response == resources[0] + + assert len(channel.requests) == 1 + actual_requests = channel.requests[0][1] + assert len(actual_requests) == 1 + actual_request = list(actual_requests)[0] + assert request == actual_request + + def test_listen_exception(self): + # Mock the API response + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + database = client.database_root_path('[PROJECT]', '[DATABASE]') + request = {'database': database} + + request = firestore_pb2.ListenRequest(**request) + requests = [request] + + with pytest.raises(CustomException): + client.listen(requests) + + def test_list_collection_ids(self): + # Setup Expected Response + next_page_token = '' + collection_ids_element = 'collectionIdsElement1368994900' + collection_ids = [collection_ids_element] + expected_response = { + 'next_page_token': next_page_token, + 'collection_ids': collection_ids + } + expected_response = firestore_pb2.ListCollectionIdsResponse( + **expected_response) + + # Mock the API response + channel = ChannelStub(responses=[expected_response]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup Request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + paged_list_response = client.list_collection_ids(parent) + resources = list(paged_list_response) + assert len(resources) == 1 + + assert expected_response.collection_ids[0] == resources[0] + + assert len(channel.requests) == 1 + expected_request = firestore_pb2.ListCollectionIdsRequest( + parent=parent) + actual_request = channel.requests[0][1] + assert expected_request == actual_request + + def test_list_collection_ids_exception(self): + channel = ChannelStub(responses=[CustomException()]) + client = firestore_v1beta1.FirestoreClient(channel=channel) + + # Setup request + parent = client.any_path_path('[PROJECT]', '[DATABASE]', '[DOCUMENT]', + '[ANY_PATH]') + + paged_list_response = client.list_collection_ids(parent) + with pytest.raises(CustomException): + list(paged_list_response) diff --git a/firestore/tests/unit/test__helpers.py b/firestore/tests/unit/test__helpers.py index 5669ba1da71f..7f69278acd2b 100644 --- a/firestore/tests/unit/test__helpers.py +++ b/firestore/tests/unit/test__helpers.py @@ -1364,105 +1364,6 @@ def test_good_transaction(self): self.assertEqual(self._call_fut(transaction), txn_id) -class Test_remap_gax_error_on_commit(unittest.TestCase): - - @staticmethod - def _call_fut(): - from google.cloud.firestore_v1beta1._helpers import ( - remap_gax_error_on_commit) - - return remap_gax_error_on_commit() - - @staticmethod - def _fake_method(exc, result=None): - if exc is None: - return result - else: - raise exc - - @staticmethod - def _make_rendezvous(status_code, details): - from grpc import _channel - from google.cloud import exceptions - - exc_state = _channel._RPCState((), None, None, status_code, details) - return exceptions.GrpcRendezvous(exc_state, None, None, None) - - def _make_gax_error(self, err_name, details): - from google.gax import errors - import grpc - - # First, create low-level GrpcRendezvous exception. - status_code = getattr(grpc.StatusCode, err_name) - cause = self._make_rendezvous(status_code, details) - # Then put it into a high-level GaxError. - return errors.GaxError('RPC failed', cause=cause) - - def test_success(self): - expected = object() - with self._call_fut(): - result = self._fake_method(None, expected) - self.assertIs(result, expected) - - def test_non_grpc_err(self): - exc = RuntimeError('Not a gRPC error') - with self.assertRaises(RuntimeError): - with self._call_fut(): - self._fake_method(exc) - - def test_already_exists(self): - from google.cloud import exceptions - - exc = self._make_gax_error( - 'ALREADY_EXISTS', 'entity already exists: app: ...') - with self.assertRaises(exceptions.Conflict): - with self._call_fut(): - self._fake_method(exc) - - def test_not_found(self): - from google.cloud import exceptions - - exc = self._make_gax_error( - 'NOT_FOUND', 'no entity to update: app: ...') - with self.assertRaises(exceptions.NotFound): - with self._call_fut(): - self._fake_method(exc) - - def test_gax_error_not_mapped(self): - from google.gax import errors - - exc = self._make_gax_error( - 'INVALID_ARGUMENT', 'transaction closed') - with self.assertRaises(errors.GaxError) as exc_info: - with self._call_fut(): - self._fake_method(exc) - - self.assertIs(exc_info.exception, exc) - - -class Test_options_with_prefix(unittest.TestCase): - - @staticmethod - def _call_fut(database_string): - from google.cloud.firestore_v1beta1._helpers import options_with_prefix - - return options_with_prefix(database_string) - - def test_it(self): - import google.gax - - database_string = u'projects/prahj/databases/dee-bee' - options = self._call_fut(database_string) - - self.assertIsInstance(options, google.gax.CallOptions) - expected_kwargs = { - 'metadata': [ - ('google-cloud-resource-prefix', database_string), - ], - } - self.assertEqual(options.kwargs, expected_kwargs) - - def _value_pb(**kwargs): from google.cloud.firestore_v1beta1.proto.document_pb2 import Value diff --git a/firestore/tests/unit/test_batch.py b/firestore/tests/unit/test_batch.py index 8f66b5211d17..0cc41c848974 100644 --- a/firestore/tests/unit/test_batch.py +++ b/firestore/tests/unit/test_batch.py @@ -14,9 +14,6 @@ import unittest -from google.gax.errors import GaxError -from grpc import StatusCode -from grpc._channel import _RPCState import mock @@ -169,8 +166,7 @@ def test_commit(self): # Verify the mocks. firestore_api.commit.assert_called_once_with( - client._database_string, write_pbs, transaction=None, - options=client._call_options) + client._database_string, write_pbs, transaction=None) def _value_pb(**kwargs): diff --git a/firestore/tests/unit/test_client.py b/firestore/tests/unit/test_client.py index edb0bdfcdccf..2415e43e3587 100644 --- a/firestore/tests/unit/test_client.py +++ b/firestore/tests/unit/test_client.py @@ -86,30 +86,6 @@ def test___database_string_property(self): client._database_string_internal = mock.sentinel.cached self.assertIs(client._database_string, mock.sentinel.cached) - def test___call_options_property(self): - import google.gax - - credentials = _make_credentials() - database = 'quanta' - client = self._make_one( - project=self.PROJECT, credentials=credentials, database=database) - self.assertIsNone(client._call_options_internal) - - call_options = client._call_options - self.assertIsInstance(call_options, google.gax.CallOptions) - expected_kwargs = { - 'metadata': [ - ('google-cloud-resource-prefix', client._database_string), - ], - } - self.assertEqual(call_options.kwargs, expected_kwargs) - - self.assertIs(call_options, client._call_options_internal) - - # Swap it out with a unique value to verify it is cached. - client._call_options_internal = mock.sentinel.cached - self.assertIs(client._call_options, mock.sentinel.cached) - def test_collection_factory(self): from google.cloud.firestore_v1beta1.collection import CollectionReference @@ -312,8 +288,7 @@ def test_get_all(self): doc_paths = [document1._document_path, document2._document_path] mask = common_pb2.DocumentMask(field_paths=field_paths) client._firestore_api.batch_get_documents.assert_called_once_with( - client._database_string, doc_paths, mask, transaction=None, - options=client._call_options) + client._database_string, doc_paths, mask, transaction=None) def test_get_all_with_transaction(self): from google.cloud.firestore_v1beta1.document import DocumentSnapshot @@ -338,8 +313,7 @@ def test_get_all_with_transaction(self): # Verify the call to the mock. doc_paths = [document._document_path] client._firestore_api.batch_get_documents.assert_called_once_with( - client._database_string, doc_paths, None, transaction=txn_id, - options=client._call_options) + client._database_string, doc_paths, None, transaction=txn_id) def test_get_all_unknown_result(self): from google.cloud.firestore_v1beta1.client import _BAD_DOC_TEMPLATE @@ -358,8 +332,7 @@ def test_get_all_unknown_result(self): # Verify the call to the mock. doc_paths = [document._document_path] client._firestore_api.batch_get_documents.assert_called_once_with( - client._database_string, doc_paths, None, transaction=None, - options=client._call_options) + client._database_string, doc_paths, None, transaction=None) def test_get_all_wrong_order(self): from google.cloud.firestore_v1beta1.document import DocumentSnapshot @@ -397,8 +370,7 @@ def test_get_all_wrong_order(self): document3._document_path, ] client._firestore_api.batch_get_documents.assert_called_once_with( - client._database_string, doc_paths, None, transaction=None, - options=client._call_options) + client._database_string, doc_paths, None, transaction=None) def test_batch(self): from google.cloud.firestore_v1beta1.batch import WriteBatch @@ -585,8 +557,7 @@ def test_it(self, make_chan, mock_klass): make_chan.assert_called_once_with( mock.sentinel.credentials, DEFAULT_USER_AGENT, host) mock_klass.assert_called_once_with( - channel=mock.sentinel.channel, lib_name='gccl', - lib_version=__version__) + channel=mock.sentinel.channel) class Test__reference_info(unittest.TestCase): diff --git a/firestore/tests/unit/test_collection.py b/firestore/tests/unit/test_collection.py index 365c98622ca0..39be3bbeed53 100644 --- a/firestore/tests/unit/test_collection.py +++ b/firestore/tests/unit/test_collection.py @@ -201,8 +201,7 @@ def test_add_auto_assigned(self): fields=_helpers.encode_dict(document_data)) firestore_api.create_document.assert_called_once_with( parent_path, collection_id=collection.id, document_id=None, - document=expected_document_pb, mask=None, - options=client._call_options) + document=expected_document_pb, mask=None) @staticmethod def _write_pb_for_create(document_path, document_data): @@ -253,8 +252,7 @@ def test_add_explicit_id(self): write_pb = self._write_pb_for_create( document_ref._document_path, document_data) firestore_api.commit.assert_called_once_with( - client._database_string, [write_pb], transaction=None, - options=client._call_options) + client._database_string, [write_pb], transaction=None) def test_select(self): from google.cloud.firestore_v1beta1.query import Query diff --git a/firestore/tests/unit/test_cross_language.py b/firestore/tests/unit/test_cross_language.py index c35919ab13a7..1d37774dac48 100644 --- a/firestore/tests/unit/test_cross_language.py +++ b/firestore/tests/unit/test_cross_language.py @@ -98,8 +98,7 @@ def run_write_test(self, test_proto, desc): firestore_api.commit.assert_called_once_with( client._database_string, list(tp.request.writes), - transaction=None, - options=client._call_options) + transaction=None) def setup(self, firestore_api, proto): diff --git a/firestore/tests/unit/test_document.py b/firestore/tests/unit/test_document.py index 8607c6fb6a6e..9495aa4165dc 100644 --- a/firestore/tests/unit/test_document.py +++ b/firestore/tests/unit/test_document.py @@ -232,8 +232,7 @@ def test_create(self): write_pb = self._write_pb_for_create( document._document_path, document_data) firestore_api.commit.assert_called_once_with( - client._database_string, [write_pb], transaction=None, - options=client._call_options) + client._database_string, [write_pb], transaction=None) @staticmethod def _write_pb_for_set(document_path, document_data): @@ -280,8 +279,7 @@ def _set_helper(self, **option_kwargs): if option is not None: option.modify_write(write_pb) firestore_api.commit.assert_called_once_with( - client._database_string, [write_pb], transaction=None, - options=client._call_options) + client._database_string, [write_pb], transaction=None) def test_set(self): self._set_helper() @@ -348,8 +346,7 @@ def _update_helper(self, **option_kwargs): if option is not None: option.modify_write(write_pb) firestore_api.commit.assert_called_once_with( - client._database_string, [write_pb], transaction=None, - options=client._call_options) + client._database_string, [write_pb], transaction=None) def test_update(self): self._update_helper() @@ -385,8 +382,7 @@ def _delete_helper(self, **option_kwargs): if option is not None: option.modify_write(write_pb) firestore_api.commit.assert_called_once_with( - client._database_string, [write_pb], transaction=None, - options=client._call_options) + client._database_string, [write_pb], transaction=None) def test_delete(self): self._delete_helper() diff --git a/firestore/tests/unit/test_query.py b/firestore/tests/unit/test_query.py index 0843c7ca6604..0060e004f33e 100644 --- a/firestore/tests/unit/test_query.py +++ b/firestore/tests/unit/test_query.py @@ -684,8 +684,7 @@ def test_get_simple(self): # Verify the mock call. parent_path, _ = parent._parent_info() firestore_api.run_query.assert_called_once_with( - parent_path, query._to_protobuf(), transaction=None, - options=client._call_options) + parent_path, query._to_protobuf(), transaction=None) def test_get_with_transaction(self): # Create a minimal fake GAPIC. @@ -722,8 +721,7 @@ def test_get_with_transaction(self): # Verify the mock call. firestore_api.run_query.assert_called_once_with( - parent_path, query._to_protobuf(), transaction=txn_id, - options=client._call_options) + parent_path, query._to_protobuf(), transaction=txn_id) def test_get_no_results(self): # Create a minimal fake GAPIC with a dummy response. @@ -747,8 +745,7 @@ def test_get_no_results(self): # Verify the mock call. parent_path, _ = parent._parent_info() firestore_api.run_query.assert_called_once_with( - parent_path, query._to_protobuf(), transaction=None, - options=client._call_options) + parent_path, query._to_protobuf(), transaction=None) def test_get_second_response_in_empty_stream(self): # Create a minimal fake GAPIC with a dummy response. @@ -779,8 +776,7 @@ def test_get_second_response_in_empty_stream(self): # Verify the mock call. parent_path, _ = parent._parent_info() firestore_api.run_query.assert_called_once_with( - parent_path, query._to_protobuf(), transaction=None, - options=client._call_options) + parent_path, query._to_protobuf(), transaction=None) def test_get_with_skipped_results(self): # Create a minimal fake GAPIC. @@ -816,8 +812,7 @@ def test_get_with_skipped_results(self): # Verify the mock call. parent_path, _ = parent._parent_info() firestore_api.run_query.assert_called_once_with( - parent_path, query._to_protobuf(), transaction=None, - options=client._call_options) + parent_path, query._to_protobuf(), transaction=None) def test_get_empty_after_first_response(self): from google.cloud.firestore_v1beta1.query import _EMPTY_DOC_TEMPLATE @@ -856,8 +851,7 @@ def test_get_empty_after_first_response(self): # Verify the mock call. parent_path, _ = parent._parent_info() firestore_api.run_query.assert_called_once_with( - parent_path, query._to_protobuf(), transaction=None, - options=client._call_options) + parent_path, query._to_protobuf(), transaction=None) class Test__enum_from_op_string(unittest.TestCase): diff --git a/firestore/tests/unit/test_transaction.py b/firestore/tests/unit/test_transaction.py index 2da7a5327172..ac216fce430e 100644 --- a/firestore/tests/unit/test_transaction.py +++ b/firestore/tests/unit/test_transaction.py @@ -140,8 +140,7 @@ def test__begin(self): # Verify the called mock. firestore_api.begin_transaction.assert_called_once_with( - client._database_string, options_=None, - options=client._call_options) + client._database_string, options_=None) def test__begin_failure(self): from google.cloud.firestore_v1beta1.transaction import _CANT_BEGIN @@ -191,7 +190,7 @@ def test__rollback(self): # Verify the called mock. firestore_api.rollback.assert_called_once_with( - client._database_string, txn_id, options=client._call_options) + client._database_string, txn_id) def test__rollback_not_allowed(self): from google.cloud.firestore_v1beta1.transaction import _CANT_ROLLBACK @@ -206,14 +205,15 @@ def test__rollback_not_allowed(self): self.assertEqual(exc_info.exception.args, (_CANT_ROLLBACK,)) def test__rollback_failure(self): - from google.gax import errors + import grpc + from google.api_core import exceptions from google.protobuf import empty_pb2 from google.cloud.firestore_v1beta1.gapic import firestore_client # Create a minimal fake GAPIC with a dummy failure. firestore_api = mock.create_autospec( firestore_client.FirestoreClient, instance=True) - exc = _make_gax_error('INTERNAL', 'Fire during rollback.') + exc = _make_gapic_error(grpc.StatusCode.INTERNAL, 'Fire during rollback.') firestore_api.rollback.side_effect = exc # Attach the fake GAPIC to a real client. @@ -225,8 +225,8 @@ def test__rollback_failure(self): txn_id = b'roll-bad-server' transaction._id = txn_id - with self.assertRaises(errors.GaxError) as exc_info: - transaction._rollback() + with self.assertRaises(exceptions.InternalServerError) as exc_info: + transaction._rollback() self.assertIs(exc_info.exception, exc) self.assertIsNone(transaction._id) @@ -234,7 +234,7 @@ def test__rollback_failure(self): # Verify the called mock. firestore_api.rollback.assert_called_once_with( - client._database_string, txn_id, options=client._call_options) + client._database_string, txn_id) def test__commit(self): from google.cloud.firestore_v1beta1.gapic import firestore_client @@ -271,8 +271,7 @@ def test__commit(self): # Verify the mocks. firestore_api.commit.assert_called_once_with( - client._database_string, write_pbs, transaction=txn_id, - options=client._call_options) + client._database_string, write_pbs, transaction=txn_id) def test__commit_not_allowed(self): from google.cloud.firestore_v1beta1.transaction import _CANT_COMMIT @@ -285,7 +284,8 @@ def test__commit_not_allowed(self): self.assertEqual(exc_info.exception.args, (_CANT_COMMIT,)) def test__commit_failure(self): - from google.gax import errors + import grpc + from google.api_core import exceptions from google.cloud.firestore_v1beta1.gapic import firestore_client from google.cloud.firestore_v1beta1.proto import firestore_pb2 from google.cloud.firestore_v1beta1.proto import write_pb2 @@ -293,7 +293,7 @@ def test__commit_failure(self): # Create a minimal fake GAPIC with a dummy failure. firestore_api = mock.create_autospec( firestore_client.FirestoreClient, instance=True) - exc = _make_gax_error('INTERNAL', 'Fire during commit.') + exc = _make_gapic_error(grpc.StatusCode.INTERNAL, 'Fire during commit.') firestore_api.commit.side_effect = exc # Attach the fake GAPIC to a real client. @@ -308,7 +308,7 @@ def test__commit_failure(self): transaction.delete(client.document('up', 'left')) write_pbs = transaction._write_pbs[::] - with self.assertRaises(errors.GaxError) as exc_info: + with self.assertRaises(exceptions.InternalServerError) as exc_info: transaction._commit() self.assertIs(exc_info.exception, exc) @@ -317,8 +317,7 @@ def test__commit_failure(self): # Verify the called mock. firestore_api.commit.assert_called_once_with( - client._database_string, write_pbs, transaction=txn_id, - options=client._call_options) + client._database_string, write_pbs, transaction=txn_id) class Test_Transactional(unittest.TestCase): @@ -367,8 +366,7 @@ def test__pre_commit_success(self): to_wrap.assert_called_once_with(transaction, 'pos', key='word') firestore_api = transaction._client._firestore_api firestore_api.begin_transaction.assert_called_once_with( - transaction._client._database_string, options_=None, - options=transaction._client._call_options) + transaction._client._database_string, options_=None) firestore_api.rollback.assert_not_called() firestore_api.commit.assert_not_called() @@ -398,8 +396,7 @@ def test__pre_commit_retry_id_already_set_success(self): ), ) firestore_api.begin_transaction.assert_called_once_with( - transaction._client._database_string, options_=options_, - options=transaction._client._call_options) + transaction._client._database_string, options_=options_) firestore_api.rollback.assert_not_called() firestore_api.commit.assert_not_called() @@ -422,15 +419,14 @@ def test__pre_commit_failure(self): to_wrap.assert_called_once_with(transaction, 10, 20) firestore_api = transaction._client._firestore_api firestore_api.begin_transaction.assert_called_once_with( - transaction._client._database_string, options_=None, - options=transaction._client._call_options) + transaction._client._database_string, options_=None) firestore_api.rollback.assert_called_once_with( - transaction._client._database_string, txn_id, - options=transaction._client._call_options) + transaction._client._database_string, txn_id) firestore_api.commit.assert_not_called() def test__pre_commit_failure_with_rollback_failure(self): - from google.gax import errors + from google.api_core import exceptions + import grpc exc1 = ValueError('I will not be only failure.') to_wrap = mock.Mock(side_effect=exc1, spec=[]) @@ -439,15 +435,15 @@ def test__pre_commit_failure_with_rollback_failure(self): txn_id = b'both-will-fail' transaction = _make_transaction(txn_id) # Actually force the ``rollback`` to fail as well. - exc2 = _make_gax_error('INTERNAL', 'Rollback blues.') + exc2 = _make_gapic_error(grpc.StatusCode.INTERNAL, 'Rollback blues.') firestore_api = transaction._client._firestore_api firestore_api.rollback.side_effect = exc2 # Try to ``_pre_commit`` - with self.assertRaises(errors.GaxError) as exc_info: - wrapped._pre_commit(transaction, a='b', c='zebra') - self.assertIs(exc_info.exception, exc2) + with self.assertRaises(exceptions.InternalServerError) as exc_info: + wrapped._pre_commit(transaction, a='b', c='zebra') + self.assertIs(exc_info.exception, exc2) self.assertIsNone(transaction._id) self.assertEqual(wrapped.current_id, txn_id) self.assertEqual(wrapped.retry_id, txn_id) @@ -455,11 +451,9 @@ def test__pre_commit_failure_with_rollback_failure(self): # Verify mocks. to_wrap.assert_called_once_with(transaction, a='b', c='zebra') firestore_api.begin_transaction.assert_called_once_with( - transaction._client._database_string, options_=None, - options=transaction._client._call_options) + transaction._client._database_string, options_=None) firestore_api.rollback.assert_called_once_with( - transaction._client._database_string, txn_id, - options=transaction._client._call_options) + transaction._client._database_string, txn_id) firestore_api.commit.assert_not_called() def test__maybe_commit_success(self): @@ -479,11 +473,12 @@ def test__maybe_commit_success(self): firestore_api.begin_transaction.assert_not_called() firestore_api.rollback.assert_not_called() firestore_api.commit.assert_called_once_with( - transaction._client._database_string, [], transaction=txn_id, - options=transaction._client._call_options) + transaction._client._database_string, [], transaction=txn_id) def test__maybe_commit_failure_read_only(self): - from google.gax import errors + import grpc + from google.api_core import exceptions + wrapped = self._make_one(mock.sentinel.callable_) @@ -495,12 +490,13 @@ def test__maybe_commit_failure_read_only(self): # Actually force the ``commit`` to fail (use ABORTED, but cannot # retry since read-only). - exc = _make_gax_error('ABORTED', 'Read-only did a bad.') + exc = _make_gapic_error(grpc.StatusCode.ABORTED, 'Read-only did a bad.') firestore_api = transaction._client._firestore_api firestore_api.commit.side_effect = exc - with self.assertRaises(errors.GaxError) as exc_info: - wrapped._maybe_commit(transaction) + with self.assertRaises(exceptions.Aborted) as exc_info: + wrapped._maybe_commit(transaction) + self.assertIs(exc_info.exception, exc) self.assertEqual(transaction._id, txn_id) @@ -511,10 +507,10 @@ def test__maybe_commit_failure_read_only(self): firestore_api.begin_transaction.assert_not_called() firestore_api.rollback.assert_not_called() firestore_api.commit.assert_called_once_with( - transaction._client._database_string, [], transaction=txn_id, - options=transaction._client._call_options) + transaction._client._database_string, [], transaction=txn_id) def test__maybe_commit_failure_can_retry(self): + import grpc wrapped = self._make_one(mock.sentinel.callable_) txn_id = b'failed-but-retry' @@ -524,7 +520,7 @@ def test__maybe_commit_failure_can_retry(self): wrapped.retry_id = txn_id # We won't call ``_pre_commit()``. # Actually force the ``commit`` to fail. - exc = _make_gax_error('ABORTED', 'Read-write did a bad.') + exc = _make_gapic_error(grpc.StatusCode.ABORTED, 'Read-write did a bad.') firestore_api = transaction._client._firestore_api firestore_api.commit.side_effect = exc @@ -539,11 +535,11 @@ def test__maybe_commit_failure_can_retry(self): firestore_api.begin_transaction.assert_not_called() firestore_api.rollback.assert_not_called() firestore_api.commit.assert_called_once_with( - transaction._client._database_string, [], transaction=txn_id, - options=transaction._client._call_options) + transaction._client._database_string, [], transaction=txn_id) def test__maybe_commit_failure_cannot_retry(self): - from google.gax import errors + import grpc + from google.api_core import exceptions wrapped = self._make_one(mock.sentinel.callable_) @@ -554,13 +550,14 @@ def test__maybe_commit_failure_cannot_retry(self): wrapped.retry_id = txn_id # We won't call ``_pre_commit()``. # Actually force the ``commit`` to fail. - exc = _make_gax_error('INTERNAL', 'Real bad thing') + exc = _make_gapic_error(grpc.StatusCode.INTERNAL, 'Real bad thing') firestore_api = transaction._client._firestore_api firestore_api.commit.side_effect = exc - with self.assertRaises(errors.GaxError) as exc_info: - wrapped._maybe_commit(transaction) - self.assertIs(exc_info.exception, exc) + with self.assertRaises(exceptions.InternalServerError): + wrapped._maybe_commit(transaction) + +# self.assertIs(exc_info.exception, exc) self.assertEqual(transaction._id, txn_id) self.assertEqual(wrapped.current_id, txn_id) @@ -570,8 +567,7 @@ def test__maybe_commit_failure_cannot_retry(self): firestore_api.begin_transaction.assert_not_called() firestore_api.rollback.assert_not_called() firestore_api.commit.assert_called_once_with( - transaction._client._database_string, [], transaction=txn_id, - options=transaction._client._call_options) + transaction._client._database_string, [], transaction=txn_id) def test___call__success_first_attempt(self): to_wrap = mock.Mock(return_value=mock.sentinel.result, spec=[]) @@ -590,14 +586,13 @@ def test___call__success_first_attempt(self): to_wrap.assert_called_once_with(transaction, 'a', b='c') firestore_api = transaction._client._firestore_api firestore_api.begin_transaction.assert_called_once_with( - transaction._client._database_string, options_=None, - options=transaction._client._call_options) + transaction._client._database_string, options_=None) firestore_api.rollback.assert_not_called() firestore_api.commit.assert_called_once_with( - transaction._client._database_string, [], transaction=txn_id, - options=transaction._client._call_options) + transaction._client._database_string, [], transaction=txn_id) def test___call__success_second_attempt(self): + import grpc from google.cloud.firestore_v1beta1.proto import common_pb2 from google.cloud.firestore_v1beta1.proto import firestore_pb2 from google.cloud.firestore_v1beta1.proto import write_pb2 @@ -609,7 +604,7 @@ def test___call__success_second_attempt(self): transaction = _make_transaction(txn_id) # Actually force the ``commit`` to fail on first / succeed on second. - exc = _make_gax_error('ABORTED', 'Contention junction.') + exc = _make_gapic_error(grpc.StatusCode.ABORTED, 'Contention junction.') firestore_api = transaction._client._firestore_api firestore_api.commit.side_effect = [ exc, @@ -640,22 +635,22 @@ def test___call__success_second_attempt(self): retry_transaction=txn_id, ), ) - call_options = transaction._client._call_options self.assertEqual( firestore_api.begin_transaction.mock_calls, [ - mock.call(db_str, options_=None, options=call_options), - mock.call(db_str, options_=options_, options=call_options), + mock.call(db_str, options_=None), + mock.call(db_str, options_=options_), ], ) firestore_api.rollback.assert_not_called() commit_call = mock.call( - db_str, [], transaction=txn_id, options=call_options) + db_str, [], transaction=txn_id) self.assertEqual( firestore_api.commit.mock_calls, [commit_call, commit_call]) def test___call__failure(self): + import grpc from google.cloud.firestore_v1beta1.transaction import ( _EXCEED_ATTEMPTS_TEMPLATE) @@ -666,7 +661,7 @@ def test___call__failure(self): transaction = _make_transaction(txn_id, max_attempts=1) # Actually force the ``commit`` to fail. - exc = _make_gax_error('ABORTED', 'Contention just once.') + exc = _make_gapic_error(grpc.StatusCode.ABORTED, 'Contention just once.') firestore_api = transaction._client._firestore_api firestore_api.commit.side_effect = exc @@ -684,14 +679,11 @@ def test___call__failure(self): # Verify mocks. to_wrap.assert_called_once_with(transaction, 'here', there=1.5) firestore_api.begin_transaction.assert_called_once_with( - transaction._client._database_string, options_=None, - options=transaction._client._call_options) + transaction._client._database_string, options_=None) firestore_api.rollback.assert_called_once_with( - transaction._client._database_string, txn_id, - options=transaction._client._call_options) + transaction._client._database_string, txn_id) firestore_api.commit.assert_called_once_with( - transaction._client._database_string, [], transaction=txn_id, - options=transaction._client._call_options) + transaction._client._database_string, [], transaction=txn_id) class Test_transactional(unittest.TestCase): @@ -710,191 +702,6 @@ def test_it(self): self.assertIs(wrapped.to_wrap, mock.sentinel.callable_) -class Test__commit_with_retry(unittest.TestCase): - - @staticmethod - def _call_fut(client, write_pbs, transaction_id): - from google.cloud.firestore_v1beta1.transaction import _commit_with_retry - - return _commit_with_retry(client, write_pbs, transaction_id) - - @mock.patch('google.cloud.firestore_v1beta1.transaction._sleep') - def test_success_first_attempt(self, _sleep): - from google.cloud.firestore_v1beta1.gapic import firestore_client - - # Create a minimal fake GAPIC with a dummy result. - firestore_api = mock.create_autospec( - firestore_client.FirestoreClient, instance=True) - - # Attach the fake GAPIC to a real client. - client = _make_client('summer') - client._firestore_api_internal = firestore_api - - # Call function and check result. - txn_id = b'cheeeeeez' - commit_response = self._call_fut( - client, mock.sentinel.write_pbs, txn_id) - self.assertIs(commit_response, firestore_api.commit.return_value) - - # Verify mocks used. - _sleep.assert_not_called() - firestore_api.commit.assert_called_once_with( - client._database_string, mock.sentinel.write_pbs, - transaction=txn_id, options=client._call_options) - - @mock.patch('google.cloud.firestore_v1beta1.transaction._sleep', - side_effect=[2.0, 4.0]) - def test_success_third_attempt(self, _sleep): - from google.cloud.firestore_v1beta1.gapic import firestore_client - - # Create a minimal fake GAPIC with a dummy result. - firestore_api = mock.create_autospec( - firestore_client.FirestoreClient, instance=True) - # Make sure the first two requests fail and the third succeeds. - firestore_api.commit.side_effect = [ - _make_gax_error('UNAVAILABLE', 'Server sleepy.'), - _make_gax_error('UNAVAILABLE', 'Server groggy.'), - mock.sentinel.commit_response, - ] - - # Attach the fake GAPIC to a real client. - client = _make_client('outside') - client._firestore_api_internal = firestore_api - - # Call function and check result. - txn_id = b'the-world\x00' - commit_response = self._call_fut( - client, mock.sentinel.write_pbs, txn_id) - self.assertIs(commit_response, mock.sentinel.commit_response) - - # Verify mocks used. - self.assertEqual(_sleep.call_count, 2) - _sleep.assert_any_call(1.0) - _sleep.assert_any_call(2.0) - # commit() called same way 3 times. - commit_call = mock.call( - client._database_string, mock.sentinel.write_pbs, - transaction=txn_id, options=client._call_options) - self.assertEqual( - firestore_api.commit.mock_calls, - [commit_call, commit_call, commit_call]) - - @mock.patch('google.cloud.firestore_v1beta1.transaction._sleep') - def test_failure_first_attempt(self, _sleep): - from google.gax import errors - from google.cloud.firestore_v1beta1.gapic import firestore_client - - # Create a minimal fake GAPIC with a dummy result. - firestore_api = mock.create_autospec( - firestore_client.FirestoreClient, instance=True) - # Make sure the first request fails with an un-retryable error. - exc =_make_gax_error('RESOURCE_EXHAUSTED', 'We ran out of fries.') - firestore_api.commit.side_effect = exc - - # Attach the fake GAPIC to a real client. - client = _make_client('peanut-butter') - client._firestore_api_internal = firestore_api - - # Call function and check result. - txn_id = b'\x08\x06\x07\x05\x03\x00\x09-jenny' - with self.assertRaises(errors.GaxError) as exc_info: - self._call_fut( - client, mock.sentinel.write_pbs, txn_id) - - self.assertIs(exc_info.exception, exc) - - # Verify mocks used. - _sleep.assert_not_called() - firestore_api.commit.assert_called_once_with( - client._database_string, mock.sentinel.write_pbs, - transaction=txn_id, options=client._call_options) - - @mock.patch('google.cloud.firestore_v1beta1.transaction._sleep', - return_value=2.0) - def test_failure_second_attempt(self, _sleep): - from google.gax import errors - from google.cloud.firestore_v1beta1.gapic import firestore_client - - # Create a minimal fake GAPIC with a dummy result. - firestore_api = mock.create_autospec( - firestore_client.FirestoreClient, instance=True) - # Make sure the first request fails retry-able and second - # fails non-retryable. - exc1 =_make_gax_error('UNAVAILABLE', 'Come back next time.') - exc2 =_make_gax_error('INTERNAL', 'Server on fritz.') - firestore_api.commit.side_effect = [exc1, exc2] - - # Attach the fake GAPIC to a real client. - client = _make_client('peanut-butter') - client._firestore_api_internal = firestore_api - - # Call function and check result. - txn_id = b'the-journey-when-and-where-well-go' - with self.assertRaises(errors.GaxError) as exc_info: - self._call_fut( - client, mock.sentinel.write_pbs, txn_id) - - self.assertIs(exc_info.exception, exc2) - - # Verify mocks used. - _sleep.assert_called_once_with(1.0) - # commit() called same way 2 times. - commit_call = mock.call( - client._database_string, mock.sentinel.write_pbs, - transaction=txn_id, options=client._call_options) - self.assertEqual( - firestore_api.commit.mock_calls, [commit_call, commit_call]) - - -class Test__sleep(unittest.TestCase): - - @staticmethod - def _call_fut(current_sleep, **kwargs): - from google.cloud.firestore_v1beta1.transaction import _sleep - - return _sleep(current_sleep, **kwargs) - - @mock.patch('random.uniform', return_value=5.5) - @mock.patch('time.sleep', return_value=None) - def test_defaults(self, sleep, uniform): - curr_sleep = 10.0 - self.assertLessEqual(uniform.return_value, curr_sleep) - - new_sleep = self._call_fut(curr_sleep) - self.assertEqual(new_sleep, 2.0 * curr_sleep) - - uniform.assert_called_once_with(0.0, curr_sleep) - sleep.assert_called_once_with(uniform.return_value) - - @mock.patch('random.uniform', return_value=10.5) - @mock.patch('time.sleep', return_value=None) - def test_explicit(self, sleep, uniform): - curr_sleep = 12.25 - self.assertLessEqual(uniform.return_value, curr_sleep) - - multiplier = 1.5 - new_sleep = self._call_fut( - curr_sleep, max_sleep=100.0, multiplier=multiplier) - self.assertEqual(new_sleep, multiplier * curr_sleep) - - uniform.assert_called_once_with(0.0, curr_sleep) - sleep.assert_called_once_with(uniform.return_value) - - @mock.patch('random.uniform', return_value=6.75) - @mock.patch('time.sleep', return_value=None) - def test_exceeds_max(self, sleep, uniform): - curr_sleep = 20.0 - self.assertLessEqual(uniform.return_value, curr_sleep) - - max_sleep = 38.5 - new_sleep = self._call_fut( - curr_sleep, max_sleep=max_sleep, multiplier=2.0) - self.assertEqual(new_sleep, max_sleep) - - uniform.assert_called_once_with(0.0, curr_sleep) - sleep.assert_called_once_with(uniform.return_value) - - def _make_credentials(): import google.auth.credentials @@ -939,20 +746,7 @@ def _make_transaction(txn_id, **txn_kwargs): return Transaction(client, **txn_kwargs) -def _make_rendezvous(status_code, details): - from grpc import _channel - from google.cloud import exceptions - - exc_state = _channel._RPCState((), None, None, status_code, details) - return exceptions.GrpcRendezvous(exc_state, None, None, None) - - -def _make_gax_error(err_name, details): - from google.gax import errors - import grpc +def _make_gapic_error(err_name, details): + from google.api_core import exceptions - # First, create low-level GrpcRendezvous exception. - status_code = getattr(grpc.StatusCode, err_name) - cause = _make_rendezvous(status_code, details) - # Then put it into a high-level GaxError. - return errors.GaxError('RPC failed', cause=cause) + return exceptions.from_grpc_status(err_name, details)