| 1137 | } |
| 1138 | |
| 1139 | export class WriteBatch implements IWriteBatch { |
| 1140 | _native: FIRWriteBatch; |
| 1141 | |
| 1142 | static fromNative(batch: FIRWriteBatch) { |
| 1143 | if (batch instanceof FIRWriteBatch) { |
| 1144 | const b = new WriteBatch(); |
| 1145 | b._native = batch; |
| 1146 | return b; |
| 1147 | } |
| 1148 | return null; |
| 1149 | } |
| 1150 | |
| 1151 | commit(): Promise<void> { |
| 1152 | return new Promise((resolve, reject) => { |
| 1153 | this.native.commitWithCompletion((error) => { |
| 1154 | if (error) { |
| 1155 | reject(FirebaseError.fromNative(error)); |
| 1156 | } else { |
| 1157 | resolve(); |
| 1158 | } |
| 1159 | }); |
| 1160 | }); |
| 1161 | } |
| 1162 | |
| 1163 | delete(documentRef: DocumentReference): WriteBatch { |
| 1164 | return WriteBatch.fromNative(this.native.deleteDocument(documentRef.native)); |
| 1165 | } |
| 1166 | |
| 1167 | set(documentRef: DocumentReference, data: DocumentData, options?: SetOptions): WriteBatch { |
| 1168 | if (options) { |
| 1169 | if (typeof options?.merge === 'boolean') { |
| 1170 | return WriteBatch.fromNative(this.native.setDataForDocumentMerge(serializeItems(data), documentRef.native, options.merge)); |
| 1171 | } |
| 1172 | |
| 1173 | if (options.mergeFields) { |
| 1174 | if (Array.isArray(options.mergeFields)) { |
| 1175 | if (typeof options.mergeFields[0] === 'string') { |
| 1176 | return WriteBatch.fromNative(this.native.setDataForDocumentMergeFields(serializeItems(data), documentRef.native, options.mergeFields)); |
| 1177 | } |
| 1178 | |
| 1179 | return WriteBatch.fromNative( |
| 1180 | this.native.setDataForDocumentMergeFields( |
| 1181 | serializeItems(data), |
| 1182 | documentRef.native, |
| 1183 | options.mergeFields.map((field) => field.native) |
| 1184 | ) |
| 1185 | ); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | return null; |
| 1190 | } else { |
| 1191 | return WriteBatch.fromNative(this.native.setDataForDocument(serializeItems(data), documentRef.native)); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | update<T extends DocumentData = DocumentData>(documentRef: DocumentReference<T>, data: Partial<{ [K in keyof T]: T[K] | FieldValue }>): WriteBatch; |
| 1196 | update<T extends DocumentData = DocumentData, K extends keyof T = string>(documentRef: DocumentReference<T>, field: K | FieldPath, value: FieldValue | T[K], moreFieldAndValues: any[]): WriteBatch; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…