| 1274 | } |
| 1275 | |
| 1276 | export class WriteBatch implements IWriteBatch { |
| 1277 | _native: com.google.firebase.firestore.WriteBatch; |
| 1278 | |
| 1279 | static fromNative(batch: com.google.firebase.firestore.WriteBatch) { |
| 1280 | if (batch instanceof com.google.firebase.firestore.WriteBatch) { |
| 1281 | const b = new WriteBatch(); |
| 1282 | b._native = batch; |
| 1283 | return b; |
| 1284 | } |
| 1285 | return null; |
| 1286 | } |
| 1287 | |
| 1288 | commit(): Promise<void> { |
| 1289 | return new Promise((resolve, reject) => { |
| 1290 | org.nativescript.firebase.firestore.FirebaseFirestore.WriteBatch.commit( |
| 1291 | this.native, |
| 1292 | new org.nativescript.firebase.firestore.FirebaseFirestore.Callback<java.lang.Void>({ |
| 1293 | onSuccess(param0) { |
| 1294 | resolve(); |
| 1295 | }, |
| 1296 | onError(error) { |
| 1297 | reject(FirebaseError.fromNative(error)); |
| 1298 | }, |
| 1299 | }) |
| 1300 | ); |
| 1301 | }); |
| 1302 | } |
| 1303 | |
| 1304 | delete(documentRef: DocumentReference) { |
| 1305 | return WriteBatch.fromNative(this.native.delete(documentRef.native)); |
| 1306 | } |
| 1307 | |
| 1308 | set(documentRef: DocumentReference, data: DocumentData, options?: SetOptions): WriteBatch { |
| 1309 | if (options) { |
| 1310 | if (typeof options?.merge === 'boolean') { |
| 1311 | const opts = com.google.firebase.firestore.SetOptions.merge(); |
| 1312 | return WriteBatch.fromNative(this.native.set(documentRef.native, serializeItems(data), opts)); |
| 1313 | } |
| 1314 | |
| 1315 | if (options.mergeFields) { |
| 1316 | if (Array.isArray(options.mergeFields)) { |
| 1317 | if (typeof options.mergeFields[0] === 'string') { |
| 1318 | return WriteBatch.fromNative(this.native.set(documentRef.native, serializeItems(data), com.google.firebase.firestore.SetOptions.mergeFields(options.mergeFields as any))); |
| 1319 | } |
| 1320 | |
| 1321 | const list = java.util.Arrays.asList(options.mergeFields.map((field) => field.native)); |
| 1322 | return WriteBatch.fromNative(this.native.set(documentRef.native, serializeItems(data), com.google.firebase.firestore.SetOptions.mergeFields(list))); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | return null; |
| 1327 | } else { |
| 1328 | return WriteBatch.fromNative(this.native.set(documentRef.native, serializeItems(data))); |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | get native() { |
| 1333 | return this._native; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…