/
types.ts
254 lines (226 loc) · 7.46 KB
/
types.ts
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*!
* Copyright 2018 Google Inc. All Rights Reserved.
*
* 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 {CallOptions} from 'google-gax';
import {Duplex} from 'stream';
import {google} from '../protos/firestore_v1_proto_api';
import {FieldPath} from './path';
import {Timestamp} from './timestamp';
import api = google.firestore.v1;
/**
* A map in the format of the Proto API
*/
export interface ApiMapValue {
[k: string]: google.firestore.v1.IValue;
}
/**
* The subset of methods we use from FirestoreClient.
*
* We don't depend on the actual Gapic client to avoid loading the GAX stack at
* module initialization time.
*/
export interface GapicClient {
getProjectId(): Promise<string>;
beginTransaction(
request: api.IBeginTransactionRequest,
options?: CallOptions
): Promise<[api.IBeginTransactionResponse, unknown, unknown]>;
commit(
request: api.ICommitRequest,
options?: CallOptions
): Promise<[api.ICommitResponse, unknown, unknown]>;
rollback(
request: api.IRollbackRequest,
options?: CallOptions
): Promise<[google.protobuf.IEmpty, unknown, unknown]>;
batchGetDocuments(
request?: api.IBatchGetDocumentsRequest,
options?: CallOptions
): Duplex;
runQuery(request?: api.IRunQueryRequest, options?: CallOptions): Duplex;
listDocuments(
request: api.IListDocumentsRequest,
options?: CallOptions
): Promise<[api.IDocument[], unknown, unknown]>;
listCollectionIds(
request: api.IListCollectionIdsRequest,
options?: CallOptions
): Promise<[string[], unknown, unknown]>;
listen(options?: CallOptions): Duplex;
close(): Promise<void>;
}
/** Request/response methods used in the Firestore SDK. */
export type FirestoreUnaryMethod =
| 'listDocuments'
| 'listCollectionIds'
| 'rollback'
| 'beginTransaction'
| 'commit';
/** Streaming methods used in the Firestore SDK. */
export type FirestoreStreamingMethod =
| 'listen'
| 'runQuery'
| 'batchGetDocuments';
/** Type signature for the unary methods in the GAPIC layer. */
export type UnaryMethod<Req, Resp> = (
request: Req,
callOptions: CallOptions
) => Promise<[Resp, unknown, unknown]>;
// We don't have type information for the npm package
// `functional-red-black-tree`.
// tslint:disable-next-line:no-any
export type RBTree = any;
/**
* Settings used to directly configure a `Firestore` instance.
*/
export interface Settings {
/**
* The Firestore Project ID. Can be omitted in environments that support
* `Application Default Credentials` {@see https://cloud.google.com/docs/authentication}
*/
projectId?: string;
/** The host to connect to. */
host?: string;
/**
* Local file containing the Service Account credentials. Can be omitted
* in environments that support `Application Default Credentials`
* {@see https://cloud.google.com/docs/authentication}
*/
keyFilename?: string;
/**
* The 'client_email' and 'private_key' properties of the service account
* to use with your Firestore project. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}. If your credentials are stored in a JSON file, you
* can specify a `keyFilename` instead.
*/
credentials?: {client_email?: string; private_key?: string};
/** Whether to use SSL when connecting. */
ssl?: boolean;
/**
* The maximum number of idle GRPC channels to keep. A smaller number of idle
* channels reduces memory usage but increases request latency for clients
* with fluctuating request rates. If set to 0, shuts down all GRPC channels
* when the client becomes idle. Defaults to 1.
*/
maxIdleChannels?: number;
// tslint:disable-next-line:no-any
[key: string]: any; // Accept other properties, such as GRPC settings.
}
/**
* Document data (for use with `DocumentReference.set()`) consists of fields
* mapped to values.
*/
export interface DocumentData {
[field: string]: unknown;
}
/**
* Update data (for use with `DocumentReference.update()`) consists of field
* paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
* reference nested fields within the document.
*/
export interface UpdateData {
[fieldPath: string]: unknown;
}
/**
* Update data that has been resolved to a mapping of FieldPaths to values.
*/
export type UpdateMap = Map<FieldPath, unknown>;
/**
* The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc'
* (descending or ascending).
*/
export type OrderByDirection = 'desc' | 'asc';
/**
* Filter conditions in a `Query.where()` clause are specified using the
* strings '<', '<=', '==', '>=', '>','array-contains', 'in', and
* 'array-contains-any'.
*/
export type WhereFilterOp =
| '<'
| '<='
| '=='
| '>='
| '>'
| 'array-contains'
| 'in'
| 'array-contains-any';
/**
* An options object that configures conditional behavior of `update()` and
* `delete()` calls in `DocumentReference`, `WriteBatch`, and `Transaction`.
* Using Preconditions, these calls can be restricted to only apply to
* documents that match the specified restrictions.
*/
export interface Precondition {
/**
* If set, the last update time to enforce.
*/
readonly lastUpdateTime?: Timestamp;
}
/**
* An options object that configures the behavior of `set()` calls in
* `DocumentReference`, `WriteBatch` and `Transaction`. These calls can be
* configured to perform granular merges instead of overwriting the target
* documents in their entirety.
*/
export interface SetOptions {
/**
* Changes the behavior of a set() call to only replace the values specified
* in its data argument. Fields omitted from the set() call remain
* untouched.
*/
readonly merge?: boolean;
/**
* Changes the behavior of set() calls to only replace the specified field
* paths. Any field path that is not specified is ignored and remains
* untouched.
*
* It is an error to pass a SetOptions object to a set() call that is
* missing a value for any of the fields specified here.
*/
readonly mergeFields?: Array<string | FieldPath>;
}
/**
* An options object that can be used to configure the behavior of `getAll()`
* calls. By providing a `fieldMask`, these calls can be configured to only
* return a subset of fields.
*/
export interface ReadOptions {
/**
* Specifies the set of fields to return and reduces the amount of data
* transmitted by the backend.
*
* Adding a field mask does not filter results. Documents do not need to
* contain values for all the fields in the mask to be part of the result set.
*/
readonly fieldMask?: Array<string | FieldPath>;
}
/**
* Internal user data validation options.
* @private
*/
export interface ValidationOptions {
/** At what level field deletes are supported. */
allowDeletes: 'none' | 'root' | 'all';
/** Whether server transforms are supported. */
allowTransforms: boolean;
}
/**
* A Firestore Proto value in ProtoJs format.
* @private
*/
export interface ProtobufJsValue extends api.IValue {
valueType?: string;
}