/
bundle.py
185 lines (137 loc) · 5.6 KB
/
bundle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# -*- coding: utf-8 -*-
# Copyright 2020 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
#
# 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.
#
import proto # type: ignore
from google.cloud.firestore_v1.types import document as gfv_document
from google.cloud.firestore_v1.types import query
from google.protobuf import timestamp_pb2 as timestamp # type: ignore
__protobuf__ = proto.module(
package="google.firestore.bundle",
manifest={
"BundledQuery",
"NamedQuery",
"BundledDocumentMetadata",
"BundleMetadata",
"BundleElement",
},
)
class BundledQuery(proto.Message):
r"""Encodes a query saved in the bundle.
Attributes:
parent (str):
The parent resource name.
structured_query (google.firestore.v1.query_pb2.StructuredQuery):
A structured query.
limit_type (google.cloud.bundle.types.BundledQuery.LimitType):
"""
class LimitType(proto.Enum):
r"""If the query is a limit query, should the limit be applied to
the beginning or the end of results.
"""
FIRST = 0
LAST = 1
parent = proto.Field(proto.STRING, number=1)
structured_query = proto.Field(
proto.MESSAGE, number=2, oneof="query_type", message=query.StructuredQuery,
)
limit_type = proto.Field(proto.ENUM, number=3, enum=LimitType,)
class NamedQuery(proto.Message):
r"""A Query associated with a name, created as part of the bundle
file, and can be read by client SDKs once the bundle containing
them is loaded.
Attributes:
name (str):
Name of the query, such that client can use
the name to load this query from bundle, and
resume from when the query results are
materialized into this bundle.
bundled_query (google.cloud.bundle.types.BundledQuery):
The query saved in the bundle.
read_time (google.protobuf.timestamp_pb2.Timestamp):
The read time of the query, when it is used
to build the bundle. This is useful to resume
the query from the bundle, once it is loaded by
client SDKs.
"""
name = proto.Field(proto.STRING, number=1)
bundled_query = proto.Field(proto.MESSAGE, number=2, message="BundledQuery",)
read_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,)
class BundledDocumentMetadata(proto.Message):
r"""Metadata describing a Firestore document saved in the bundle.
Attributes:
name (str):
The document key of a bundled document.
read_time (google.protobuf.timestamp_pb2.Timestamp):
The snapshot version of the document data
bundled.
exists (bool):
Whether the document exists.
queries (Sequence[str]):
The names of the queries in this bundle that
this document matches to.
"""
name = proto.Field(proto.STRING, number=1)
read_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,)
exists = proto.Field(proto.BOOL, number=3)
queries = proto.RepeatedField(proto.STRING, number=4)
class BundleMetadata(proto.Message):
r"""Metadata describing the bundle file/stream.
Attributes:
id (str):
The ID of the bundle.
create_time (google.protobuf.timestamp_pb2.Timestamp):
Time at which the documents snapshot is taken
for this bundle.
version (int):
The schema version of the bundle.
total_documents (int):
The number of documents in the bundle.
total_bytes (int):
The size of the bundle in bytes, excluding this
``BundleMetadata``.
"""
id = proto.Field(proto.STRING, number=1)
create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,)
version = proto.Field(proto.UINT32, number=3)
total_documents = proto.Field(proto.UINT32, number=4)
total_bytes = proto.Field(proto.UINT64, number=5)
class BundleElement(proto.Message):
r"""A Firestore bundle is a length-prefixed stream of JSON
representations of ``BundleElement``. Only one ``BundleMetadata`` is
expected, and it should be the first element. The named queries
follow after ``metadata``. Every ``document_metadata`` is
immediately followed by a ``document``.
Attributes:
metadata (google.cloud.bundle.types.BundleMetadata):
named_query (google.cloud.bundle.types.NamedQuery):
document_metadata (google.cloud.bundle.types.BundledDocumentMetadata):
document (google.firestore.v1.document_pb2.Document):
"""
metadata = proto.Field(
proto.MESSAGE, number=1, oneof="element_type", message="BundleMetadata",
)
named_query = proto.Field(
proto.MESSAGE, number=2, oneof="element_type", message="NamedQuery",
)
document_metadata = proto.Field(
proto.MESSAGE,
number=3,
oneof="element_type",
message="BundledDocumentMetadata",
)
document = proto.Field(
proto.MESSAGE, number=4, oneof="element_type", message=gfv_document.Document,
)
__all__ = tuple(sorted(__protobuf__.manifest))