Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ClientSession.prototype.getArgumentDefinition = function (methodId, callback) {
assert(_.isFunction(callback));
assert(methodId instanceof NodeId);
const session = this;
const browseDescription = new browse_service.BrowseDescription({
nodeId: methodId,
referenceTypeId: resolveNodeId("HasProperty"),
browseDirection: BrowseDirection.Forward,
nodeClassMask: 0,// makeNodeClassMask("Variable"),
includeSubtypes: true,
resultMask: makeResultMask("BrowseName")
});
//Xx console.log("xxxx browseDescription", util.inspect(browseDescription, {colors: true, depth: 10}));
session.browse(browseDescription, function (err, browseResult) {
/* istanbul ignore next */
if (err) {
return callback(err);
}
browseResult.references = browseResult.references || [];
self.performMessageTransaction(request, function (err, response) {
let i, r;
if (err) {
return callback(err, response);
}
assert(response instanceof browse_service.BrowseResponse);
if (self.requestedMaxReferencesPerNode > 0) {
for (i = 0; i < response.results.length; i++) {
r = response.results[i];
/* istanbul ignore next */
if (r.references && r.references.length > self.requestedMaxReferencesPerNode) {
console.log("warning".yellow + " BrowseResponse : server didn't take into account our requestedMaxReferencesPerNode ");
console.log(" self.requestedMaxReferencesPerNode= " + self.requestedMaxReferencesPerNode);
console.log(" got " + r.references.length + "for " + nodesToBrowse[i].nodeId.toString());
console.log(" continuationPoint ", r.continuationPoint);
}
}
}
for (i = 0; i < response.results.length; i++) {
function __findBasicDataType(session, dataTypeId, callback) {
assert(dataTypeId instanceof NodeId);
if (dataTypeId.value <= 25) {
// we have a well-known DataType
const dataType = DataType.get(dataTypeId.value);
callback(null, dataType);
} else {
// let's browse for the SuperType of this object
const nodeToBrowse = new browse_service.BrowseDescription({
referenceTypeId: makeNodeId(ReferenceTypeIds.HasSubtype),
includeSubtypes: false,
browseDirection: BrowseDirection.Inverse,
nodeId: dataTypeId,
resultMask: resultMask
});
session.browse(nodeToBrowse, function (err, browseResult) {
if (err) return callback(err);
const baseDataType = browseResult.references[0].nodeId;
return __findBasicDataType(session, baseDataType, callback);
});
}
}
export function getArgumentDefinitionHelper(
session: IBasicSession,
methodId: MethodId,
callback: ResponseCallback
) {
const browseDescription = new BrowseDescription({
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeClassMask: 0, // makeNodeClassMask("Variable"),
nodeId: methodId,
referenceTypeId: resolveNodeId("HasProperty"),
resultMask: makeResultMask("BrowseName")
});
session.browse(browseDescription, (err: Error | null, browseResult?: BrowseResult) => {
/* istanbul ignore next */
if (err) {
return callback(err);
}
if (!browseResult) {
return callback(new Error("Invalid"));
export async function exploreDataTypeDefinition(
session: IBasicSession,
dataTypeDictionaryTypeNode: NodeId,
typeDictionary: TypeDictionary,
namespaces: string[]
) {
const nodeToBrowse = {
browseDirection: BrowseDirection.Forward,
includeSubtypes: false,
nodeClassMask: makeNodeClassMask("Variable"),
nodeId: dataTypeDictionaryTypeNode,
referenceTypeId: resolveNodeId("HasComponent"),
resultMask: makeResultMask("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
};
const result = await session.browse(nodeToBrowse);
const references = result.references || [];
/* istanbul ignore next */
if (references.length === 0) {
return;
}
// request the Definition of each nodes
const nodesToBrowse2 = references.map((ref: ReferenceDescription) => {
if (typeof nodeId === "string") {
const node = addressSpace.findNode(addressSpace.resolveNodeId(nodeId));
if (node) {
nodeId = node.nodeId;
}
}
const browseResult = {
statusCode: StatusCodes.Good,
continuationPoint: null,
references: null
};
if (browseDescription.browseDirection === BrowseDirection.Invalid) {
browseResult.statusCode = StatusCodes.BadBrowseDirectionInvalid;
return new BrowseResult(browseResult);
}
// check if referenceTypeId is correct
if (browseDescription.referenceTypeId instanceof NodeId) {
if (browseDescription.referenceTypeId.value === 0) {
browseDescription.referenceTypeId = null;
} else {
const rf = addressSpace.findNode(browseDescription.referenceTypeId);
if (!rf || !(rf instanceof ReferenceType)) {
browseResult.statusCode = StatusCodes.BadReferenceTypeIdInvalid;
return new BrowseResult(browseResult);
}
}
}
const obj = addressSpace.findNode(nodeId);
public browseSingleNode(
nodeId: NodeIdLike,
browseDescription: BrowseDescription,
context?: SessionContext
): BrowseResult {
const browseResult: BrowseResultOptions = {
continuationPoint: undefined,
references: null,
statusCode: StatusCodes.Good
};
if (!browseDescription || browseDescription.browseDirection === BrowseDirection.Invalid) {
browseResult.statusCode = StatusCodes.BadBrowseDirectionInvalid;
return new BrowseResult(browseResult);
}
browseDescription.browseDirection =
adjustBrowseDirection(browseDescription.browseDirection, BrowseDirection.Forward);
/* istanbul ignore next */
if (typeof nodeId === "number") {
throw new Error("Not Implemented");
}
if (typeof nodeId === "string") {
const node = this.findNode(this.resolveNodeId(nodeId));
if (node) {
nodeId = node.nodeId;
}
}
function coerceBrowseDescription(data) {
if (typeof data === "string" || data instanceof NodeId) {
return coerceBrowseDescription({
nodeId: data,
includeSubtypes: true,
browseDirection: BrowseDirection.Forward,
nodeClassMask: 0,
resultMask: 63,
referenceTypeId: "HierarchicalReferences"
});
} else {
data.nodeId = resolveNodeId(data.nodeId);
data.referenceTypeId = data.referenceTypeId ? resolveNodeId(data.referenceTypeId) : null;
return new browse_service.BrowseDescription(data);
}
}
const CallRequest = call_service.CallRequest;
const CallResponse = call_service.CallResponse;
const ReadRequest = read_service.ReadRequest;
const ReadResponse = read_service.ReadResponse;
const WriteRequest = write_service.WriteRequest;
const WriteResponse = write_service.WriteResponse;
const ReadValueId = read_service.ReadValueId;
const HistoryReadRequest = historizing_service.HistoryReadRequest;
const HistoryReadResponse = historizing_service.HistoryReadResponse;
const BrowseRequest = browse_service.BrowseRequest;
const BrowseResponse = browse_service.BrowseResponse;
const BrowseNextRequest = browse_service.BrowseNextRequest;
const BrowseNextResponse = browse_service.BrowseNextResponse;
const RegisterNodesRequest = register_node_service.RegisterNodesRequest;
const RegisterNodesResponse = register_node_service.RegisterNodesResponse;
const UnregisterNodesRequest = register_node_service.UnregisterNodesRequest;
const UnregisterNodesResponse = register_node_service.UnregisterNodesResponse;
const TranslateBrowsePathsToNodeIdsRequest = translate_service.TranslateBrowsePathsToNodeIdsRequest;
const TranslateBrowsePathsToNodeIdsResponse = translate_service.TranslateBrowsePathsToNodeIdsResponse;
const NodeId = require("node-opcua-nodeid").NodeId;
const DataValue = require("node-opcua-data-value").DataValue;
} else {
assert(reference.nodeId, obj.nodeId);
data = {
referenceTypeId: (resultMask & ResultMask.ReferenceType) ? referenceTypeId : null,
isForward: (resultMask &ResultMask.IsForward) ? isForward : false,
nodeId: obj.nodeId,
browseName: (resultMask & ResultMask.BrowseName) ? coerceQualifiedName(obj.browseName) : null,
displayName: (resultMask & ResultMask.DisplayName) ? coerceLocalizedText(obj.displayName[0]) : null,
nodeClass: (resultMask & ResultMask.NodeClass) ? obj.nodeClass : NodeClass.Unspecified,
typeDefinition: (resultMask & ResultMask.TypeDefinition) ? obj.typeDefinition : null
};
}
if (data.typeDefinition === null) {
data.typeDefinition = NodeId.nullNodeId;
}
const referenceDescription = new ReferenceDescription(data);
return referenceDescription;
}