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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/*
* Copyright 2017 Google
*
* 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 "Firestore/Protos/objc/google/firestore/v1beta1/Firestore.pbrpc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Firestore.pbobjc.h"
#import <ProtoRPC/ProtoRPC.h>
#import <RxLibrary/GRXWriter+Immediate.h>
#import "Firestore/Protos/objc/google/api/Annotations.pbobjc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Common.pbobjc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Document.pbobjc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Query.pbobjc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Write.pbobjc.h"
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/Empty.pbobjc.h>
#else
#import "Firestore/Protos/objc/google/protobuf/Empty.pbobjc.h"
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/Timestamp.pbobjc.h>
#else
#import "Firestore/Protos/objc/google/protobuf/Timestamp.pbobjc.h"
#endif
#import "Firestore/Protos/objc/google/rpc/Status.pbobjc.h"
@implementation GCFSFirestore
// Designated initializer
- (instancetype)initWithHost:(NSString *)host {
return (self = [super initWithHost:host packageName:@"google.firestore.v1beta1" serviceName:@"Firestore"]);
}
// Override superclass initializer to disallow different package and service names.
- (instancetype)initWithHost:(NSString *)host
packageName:(NSString *)packageName
serviceName:(NSString *)serviceName {
return [self initWithHost:host];
}
+ (instancetype)serviceWithHost:(NSString *)host {
return [[self alloc] initWithHost:host];
}
#pragma mark GetDocument(GetDocumentRequest) returns (Document)
/**
* Gets a single document.
*/
- (void)getDocumentWithRequest:(GCFSGetDocumentRequest *)request handler:(void(^)(GCFSDocument *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToGetDocumentWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Gets a single document.
*/
- (GRPCProtoCall *)RPCToGetDocumentWithRequest:(GCFSGetDocumentRequest *)request handler:(void(^)(GCFSDocument *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"GetDocument"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSDocument class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark ListDocuments(ListDocumentsRequest) returns (ListDocumentsResponse)
/**
* Lists documents.
*/
- (void)listDocumentsWithRequest:(GCFSListDocumentsRequest *)request handler:(void(^)(GCFSListDocumentsResponse *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToListDocumentsWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Lists documents.
*/
- (GRPCProtoCall *)RPCToListDocumentsWithRequest:(GCFSListDocumentsRequest *)request handler:(void(^)(GCFSListDocumentsResponse *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"ListDocuments"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSListDocumentsResponse class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark CreateDocument(CreateDocumentRequest) returns (Document)
/**
* Creates a new document.
*/
- (void)createDocumentWithRequest:(GCFSCreateDocumentRequest *)request handler:(void(^)(GCFSDocument *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToCreateDocumentWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Creates a new document.
*/
- (GRPCProtoCall *)RPCToCreateDocumentWithRequest:(GCFSCreateDocumentRequest *)request handler:(void(^)(GCFSDocument *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"CreateDocument"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSDocument class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark UpdateDocument(UpdateDocumentRequest) returns (Document)
/**
* Updates or inserts a document.
*/
- (void)updateDocumentWithRequest:(GCFSUpdateDocumentRequest *)request handler:(void(^)(GCFSDocument *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToUpdateDocumentWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Updates or inserts a document.
*/
- (GRPCProtoCall *)RPCToUpdateDocumentWithRequest:(GCFSUpdateDocumentRequest *)request handler:(void(^)(GCFSDocument *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"UpdateDocument"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSDocument class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark DeleteDocument(DeleteDocumentRequest) returns (Empty)
/**
* Deletes a document.
*/
- (void)deleteDocumentWithRequest:(GCFSDeleteDocumentRequest *)request handler:(void(^)(GPBEmpty *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToDeleteDocumentWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Deletes a document.
*/
- (GRPCProtoCall *)RPCToDeleteDocumentWithRequest:(GCFSDeleteDocumentRequest *)request handler:(void(^)(GPBEmpty *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"DeleteDocument"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GPBEmpty class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark BatchGetDocuments(BatchGetDocumentsRequest) returns (stream BatchGetDocumentsResponse)
/**
* Gets multiple documents.
*
* Documents returned by this method are not guaranteed to be returned in the
* same order that they were requested.
*/
- (void)batchGetDocumentsWithRequest:(GCFSBatchGetDocumentsRequest *)request eventHandler:(void(^)(BOOL done, GCFSBatchGetDocumentsResponse *_Nullable response, NSError *_Nullable error))eventHandler{
[[self RPCToBatchGetDocumentsWithRequest:request eventHandler:eventHandler] start];
}
// Returns a not-yet-started RPC object.
/**
* Gets multiple documents.
*
* Documents returned by this method are not guaranteed to be returned in the
* same order that they were requested.
*/
- (GRPCProtoCall *)RPCToBatchGetDocumentsWithRequest:(GCFSBatchGetDocumentsRequest *)request eventHandler:(void(^)(BOOL done, GCFSBatchGetDocumentsResponse *_Nullable response, NSError *_Nullable error))eventHandler{
return [self RPCToMethod:@"BatchGetDocuments"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSBatchGetDocumentsResponse class]
responsesWriteable:[GRXWriteable writeableWithEventHandler:eventHandler]];
}
#pragma mark BeginTransaction(BeginTransactionRequest) returns (BeginTransactionResponse)
/**
* Starts a new transaction.
*/
- (void)beginTransactionWithRequest:(GCFSBeginTransactionRequest *)request handler:(void(^)(GCFSBeginTransactionResponse *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToBeginTransactionWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Starts a new transaction.
*/
- (GRPCProtoCall *)RPCToBeginTransactionWithRequest:(GCFSBeginTransactionRequest *)request handler:(void(^)(GCFSBeginTransactionResponse *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"BeginTransaction"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSBeginTransactionResponse class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark Commit(CommitRequest) returns (CommitResponse)
/**
* Commits a transaction, while optionally updating documents.
*/
- (void)commitWithRequest:(GCFSCommitRequest *)request handler:(void(^)(GCFSCommitResponse *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToCommitWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Commits a transaction, while optionally updating documents.
*/
- (GRPCProtoCall *)RPCToCommitWithRequest:(GCFSCommitRequest *)request handler:(void(^)(GCFSCommitResponse *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"Commit"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSCommitResponse class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark Rollback(RollbackRequest) returns (Empty)
/**
* Rolls back a transaction.
*/
- (void)rollbackWithRequest:(GCFSRollbackRequest *)request handler:(void(^)(GPBEmpty *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToRollbackWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Rolls back a transaction.
*/
- (GRPCProtoCall *)RPCToRollbackWithRequest:(GCFSRollbackRequest *)request handler:(void(^)(GPBEmpty *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"Rollback"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GPBEmpty class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
#pragma mark RunQuery(RunQueryRequest) returns (stream RunQueryResponse)
/**
* Runs a query.
*/
- (void)runQueryWithRequest:(GCFSRunQueryRequest *)request eventHandler:(void(^)(BOOL done, GCFSRunQueryResponse *_Nullable response, NSError *_Nullable error))eventHandler{
[[self RPCToRunQueryWithRequest:request eventHandler:eventHandler] start];
}
// Returns a not-yet-started RPC object.
/**
* Runs a query.
*/
- (GRPCProtoCall *)RPCToRunQueryWithRequest:(GCFSRunQueryRequest *)request eventHandler:(void(^)(BOOL done, GCFSRunQueryResponse *_Nullable response, NSError *_Nullable error))eventHandler{
return [self RPCToMethod:@"RunQuery"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSRunQueryResponse class]
responsesWriteable:[GRXWriteable writeableWithEventHandler:eventHandler]];
}
#pragma mark Write(stream WriteRequest) returns (stream WriteResponse)
/**
* Streams batches of document updates and deletes, in order.
*/
- (void)writeWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, GCFSWriteResponse *_Nullable response, NSError *_Nullable error))eventHandler{
[[self RPCToWriteWithRequestsWriter:requestWriter eventHandler:eventHandler] start];
}
// Returns a not-yet-started RPC object.
/**
* Streams batches of document updates and deletes, in order.
*/
- (GRPCProtoCall *)RPCToWriteWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, GCFSWriteResponse *_Nullable response, NSError *_Nullable error))eventHandler{
return [self RPCToMethod:@"Write"
requestsWriter:requestWriter
responseClass:[GCFSWriteResponse class]
responsesWriteable:[GRXWriteable writeableWithEventHandler:eventHandler]];
}
#pragma mark Listen(stream ListenRequest) returns (stream ListenResponse)
/**
* Listens to changes.
*/
- (void)listenWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, GCFSListenResponse *_Nullable response, NSError *_Nullable error))eventHandler{
[[self RPCToListenWithRequestsWriter:requestWriter eventHandler:eventHandler] start];
}
// Returns a not-yet-started RPC object.
/**
* Listens to changes.
*/
- (GRPCProtoCall *)RPCToListenWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, GCFSListenResponse *_Nullable response, NSError *_Nullable error))eventHandler{
return [self RPCToMethod:@"Listen"
requestsWriter:requestWriter
responseClass:[GCFSListenResponse class]
responsesWriteable:[GRXWriteable writeableWithEventHandler:eventHandler]];
}
#pragma mark ListCollectionIds(ListCollectionIdsRequest) returns (ListCollectionIdsResponse)
/**
* Lists all the collection IDs underneath a document.
*/
- (void)listCollectionIdsWithRequest:(GCFSListCollectionIdsRequest *)request handler:(void(^)(GCFSListCollectionIdsResponse *_Nullable response, NSError *_Nullable error))handler{
[[self RPCToListCollectionIdsWithRequest:request handler:handler] start];
}
// Returns a not-yet-started RPC object.
/**
* Lists all the collection IDs underneath a document.
*/
- (GRPCProtoCall *)RPCToListCollectionIdsWithRequest:(GCFSListCollectionIdsRequest *)request handler:(void(^)(GCFSListCollectionIdsResponse *_Nullable response, NSError *_Nullable error))handler{
return [self RPCToMethod:@"ListCollectionIds"
requestsWriter:[GRXWriter writerWithValue:request]
responseClass:[GCFSListCollectionIdsResponse class]
responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]];
}
@end
|