Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function extractRange(dataValue: DataValue, indexRange: NumericalRange): DataValue {
const variant = dataValue.value;
if (indexRange && canRange(dataValue)) {
if (!indexRange.isValid()) {
return new DataValue({ statusCode: StatusCodes.BadIndexRangeInvalid });
}
// let's extract an array of elements corresponding to the indexRange
const result = indexRange.extract_values(variant.value, variant.dimensions);
dataValue = _clone_with_array_replacement(dataValue, result);
} else {
// clone the whole data Value
dataValue = dataValue.clone();
}
return dataValue;
}
write_func.call(this, dataValue, indexRange, (
err: Error | null,
statusCode1: StatusCode,
correctedDataValue: DataValue) => {
if (!err) {
correctedDataValue = correctedDataValue || dataValue;
assert(correctedDataValue instanceof DataValue);
// xx assert(correctedDataValue.serverTimestamp);
if (indexRange && !indexRange.isEmpty()) {
if (!indexRange.isValid()) {
return callback!(null, StatusCodes.BadIndexRangeInvalid);
}
const newArr = correctedDataValue.value.value;
// check that source data is an array
if (correctedDataValue.value.arrayType !== VariantArrayType.Array) {
return callback!(null, StatusCodes.BadTypeMismatch);
}
// check that destination data is also an array
assert(check_valid_array(this._dataValue.value.dataType, this._dataValue.value.value));
const destArr = this._dataValue.value.value;
const result = indexRange.set_values(destArr, newArr);
if (result.statusCode.isNot(StatusCodes.Good)) {
return callback!(null, result.statusCode);
}
low_index = 0;
high_index = arrayToAlter.length - 1;
break;
case NumericRangeType.SingleValue:
low_index = self.value;
high_index = self.value;
break;
case NumericRangeType.ArrayRange:
low_index = self.value[0];
high_index = self.value[1];
break;
case NumericRangeType.MatrixRange:
// for the time being MatrixRange is not supported
return { array: arrayToAlter, statusCode: StatusCodes.BadIndexRangeNoData };
default:
return { array: [], statusCode: StatusCodes.BadIndexRangeInvalid };
}
if (high_index >= arrayToAlter.length || low_index >= arrayToAlter.length) {
return { array: [], statusCode: StatusCodes.BadIndexRangeNoData };
}
if ((this.type !== NumericRangeType.Empty) && newValues.length !== (high_index - low_index + 1)) {
return { array: [], statusCode: StatusCodes.BadIndexRangeInvalid };
}
const insertInPlace = (_.isArray(arrayToAlter)
? insertInPlaceStandardArray
: (arrayToAlter instanceof Buffer ? insertInPlaceBuffer : insertInPlaceTypedArray));
return {
array: insertInPlace(arrayToAlter, low_index, high_index, newValues),
statusCode: StatusCodes.Good
};
}
const node = addressSpace.findNode(itemToMonitor.nodeId);
if (!node) {
return handle_error(StatusCodes.BadNodeIdUnknown);
}
if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
// AttributeIds.Value is only valid for monitoring value of UAVariables.
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (itemToMonitor.attributeId === AttributeIds.INVALID) {
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (!itemToMonitor.indexRange.isValid()) {
return handle_error(StatusCodes.BadIndexRangeInvalid);
}
// check dataEncoding applies only on Values
if (itemToMonitor.dataEncoding.name && itemToMonitor.attributeId !== AttributeIds.Value) {
return handle_error(StatusCodes.BadDataEncodingInvalid);
}
// check dataEncoding
if (!isValidDataEncoding(itemToMonitor.dataEncoding)) {
return handle_error(StatusCodes.BadDataEncodingUnsupported);
}
// check that item can be read by current user session
// filter
const requestedParameters = monitoredItemCreateRequest.requestedParameters;
return handle_error(StatusCodes.BadNodeIdUnknown);
}
if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
// AttributeIds.Value is only valid for monitoring value of UAVariables.
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (itemToMonitor.attributeId === AttributeIds.INVALID) {
return handle_error(StatusCodes.BadAttributeIdInvalid);
}
if (!itemToMonitor.indexRange.isValid()) {
return handle_error(StatusCodes.BadIndexRangeInvalid);
}
// check dataEncoding applies only on Values
if (itemToMonitor.dataEncoding.name && itemToMonitor.attributeId !== AttributeIds.Value) {
return handle_error(StatusCodes.BadDataEncodingInvalid);
}
// check dataEncoding
if (!isValidDataEncoding(itemToMonitor.dataEncoding)) {
return handle_error(StatusCodes.BadDataEncodingUnsupported);
}
// check that item can be read by current user session
// filter
const requestedParameters = monitoredItemCreateRequest.requestedParameters;
self._timestamped_set_func(dataValue, indexRange, function (err, statusCode, correctedDataValue) {
if (!err) {
correctedDataValue = correctedDataValue || dataValue;
assert(correctedDataValue instanceof DataValue);
//xx assert(correctedDataValue.serverTimestamp);
if (indexRange && !indexRange.isEmpty()) {
if (!indexRange.isValid()) {
return callback(null, StatusCodes.BadIndexRangeInvalid);
}
const newArr = correctedDataValue.value.value;
// check that source data is an array
if (correctedDataValue.value.arrayType !== VariantArrayType.Array) {
return callback(null, StatusCodes.BadTypeMismatch);
}
// check that destination data is also an array
assert(check_valid_array(self._dataValue.value.dataType, self._dataValue.value.value));
const destArr = self._dataValue.value.value;
const result = indexRange.set_values(destArr, newArr);
if (result.statusCode.isNot(StatusCodes.Good)) {
return callback(null, result.statusCode);
}