MCPcopy Create free account
hub / github.com/NativeScript/firebase / Transaction

Class Transaction

packages/firebase-firestore/index.android.ts:216–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216export class Transaction implements ITransaction {
217 _native: com.google.firebase.firestore.Transaction;
218
219 static fromNative(transaction: com.google.firebase.firestore.Transaction) {
220 if (transaction instanceof com.google.firebase.firestore.Transaction) {
221 const tran = new Transaction();
222 tran._native = transaction;
223 return tran;
224 }
225 return null;
226 }
227
228 delete<T extends DocumentData = DocumentData>(documentRef: DocumentReference): Transaction {
229 return Transaction.fromNative(this._native.delete(documentRef.native));
230 }
231
232 get<T extends DocumentData = DocumentData>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>> {
233 // TODO check error returned
234 return new Promise((resolve, reject) => {
235 try {
236 resolve(DocumentSnapshot.fromNative(this._native.get(documentRef.native)));
237 } catch (e) {
238 reject(e);
239 }
240 });
241 }
242
243 update<T extends DocumentData = DocumentData>(documentRef: DocumentReference<T>, data: Partial<{ [K in keyof T]: T[K] | FieldValue }>): Transaction;
244 update<T extends DocumentData = DocumentData, K extends keyof T = string>(documentRef: DocumentReference<T>, field: K | FieldPath, value: T[K], moreFieldsAndValues: any[]): Transaction;
245 update(documentRef: any, field: any, value?: any, moreFieldsAndValues?: any): Transaction {
246 let transaction;
247
248 if (arguments.length === 2) {
249 transaction = this.native.update(documentRef.native, serializeItems(field));
250 } else {
251 if (field instanceof FieldPath) {
252 transaction = this.native.update(documentRef.native, field.native, value?.native || value || null, moreFieldsAndValues?.map((value) => value?.native || value) ?? []);
253 } else {
254 transaction = this.native.update(documentRef.native, field.native, value?.native || value || null, moreFieldsAndValues?.map((value) => value?.native || value) ?? []);
255 }
256 }
257
258 return Transaction.fromNative(transaction);
259 }
260
261 set<T extends DocumentData = DocumentData>(documentRef: DocumentReference<T>, data: T, options?: SetOptions): Transaction {
262 let transaction;
263 if (options) {
264 if (typeof options?.merge === 'boolean') {
265 transaction = this.native.set(serializeItems(data), documentRef.native, com.google.firebase.firestore.SetOptions.merge());
266 } else if (options.mergeFields) {
267 if (Array.isArray(options.mergeFields)) {
268 if (typeof options.mergeFields[0] === 'string') {
269 transaction = this.native.set(serializeItems(data), documentRef.native, com.google.firebase.firestore.SetOptions.mergeFields(options.mergeFields as any));
270 } else {
271 const list = java.util.Arrays.asList(options.mergeFields.map((field) => field.native));
272 transaction = this.native.set(serializeItems(data), documentRef.native, com.google.firebase.firestore.SetOptions.mergeFieldPaths(list));
273 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…