Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
let promise = updateFunction(transaction);
result = is.instanceof(promise, Promise) ?
promise :
Promise.reject(new Error(
'You must return a Promise in your transaction()-callback.'));
return result.catch(err => {
logger(
'Firestore.runTransaction', requestTag,
'Rolling back transaction after callback error:', err);
// Rollback the transaction and return the failed result.
return transaction.rollback().then(() => {
return result;
});
});
})
.then(() => {
results.forEach(doc => {
assert.ok(is.instanceof(doc, DocumentSnapshot));
assert.ok(doc.createTime.isEqual(new Firestore.Timestamp(1, 2)));
assert.ok(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4)));
assert.ok(doc.readTime.isEqual(new Firestore.Timestamp(5, 6)));
++count;
});
static validateFieldPath(fieldPath) {
if (!is.instanceof(fieldPath, FieldPath)) {
if (!is.string(fieldPath)) {
throw validate.customObjectError(fieldPath);
}
if (fieldPath.indexOf('..') >= 0) {
throw new Error(`Paths must not contain '..' in them.`);
}
if (fieldPath.startsWith('.') || fieldPath.endsWith('.')) {
throw new Error(`Paths must not start or end with '.'.`);
}
if (!FIELD_PATH_RE.test(fieldPath)) {
throw new Error(`Paths can't be empty and must not contain '*~/[]'.`);
}
}
append(relativePath) {
if (is.instanceof(relativePath, Path)) {
return this.construct(this.segments.concat(relativePath.segments));
}
return this.construct(this.segments.concat(this.split(relativePath)));
}
if (enc) {
encodedElements.push(enc);
}
}
return {
arrayValue: {
values: encodedElements,
},
};
}
if (is.nil(val)) {
return {
nullValue: "NULL_VALUE",
};
}
if (is.instanceof(val, Buffer) || is.instanceof(val, Uint8Array)) {
return {
bytesValue: val,
};
}
if (isPlainObject(val)) {
return {
mapValue: {
fields: encodeFirestoreValue(val),
},
};
}
throw new Error(
"Cannot encode " +
val +
"to a Firestore Value." +
" The emulator does not yet support Firestore document reference values or geo points."
isEqual(other) {
return (
this === other ||
(is.instanceof(other, this.constructor) && this.compareTo(other) === 0)
);
}
}