Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let indexRange: NumericRange | null = null;
let callback: StatusCodeCallBack;
if (args.length === 1) {
indexRange = new NumericRange();
callback = args[0];
} else if (args.length === 2) {
indexRange = args[0];
callback = args[1];
} else {
throw new Error("Invalid Number of args");
}
assert(_.isFunction(callback));
assert(dataValue instanceof DataValue);
// index range could be string
indexRange = NumericRange.coerce(indexRange);
// test write permission
if (!this.isWritable(context)) {
return callback!(null, StatusCodes.BadNotWritable);
}
if (!this.isUserWritable(context)) {
return callback!(null, StatusCodes.BadUserAccessDenied);
}
// adjust special case
const variant = adjustVariant.call(this, dataValue.value);
const statusCode = this.checkVariantCompatibility(variant);
if (statusCode.isNot(StatusCodes.Good)) {
return callback!(null, statusCode);
}
if (context.currentTime && !dataValue.serverTimestamp) {
dataValue.serverTimestamp = context.currentTime;
dataValue.serverPicoseconds = 0;
}
assert(context instanceof SessionContext);
// adjust arguments if optional indexRange Parameter is not given
if (!_.isFunction(callback) && _.isFunction(indexRange)) {
callback = indexRange;
indexRange = new NumericRange();
}
assert(_.isFunction(callback));
assert(dataValue instanceof DataValue);
indexRange = NumericRange.coerce(indexRange);
// test write permission
if (!self.isWritable(context)) {
return callback(null, StatusCodes.BadNotWritable);
}
if (!self.isUserWritable(context)) {
return callback(null, StatusCodes.BadUserAccessDenied);
}
// adjust special case
const variant = adjustVariant(self, dataValue.value);
const statusCode = self.isValueInRange(variant);
if (statusCode.isNot(StatusCodes.Good)) {
return callback(null, statusCode);
}