Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
const r = node.findReferencesEx("HasSubtype", BrowseDirection.Inverse);
if (r && r.length) {
const subTypeOf = Reference.resolveReferenceNode(addressSpace, r[0])! as BaseNode;
assert(r.length === 1);
if (subTypeOf.nodeId.namespace === node.nodeId.namespace) {
// only output node if it is on the same namespace
if (!xw.visitedNode[_hash(subTypeOf)]) {
subTypeOf.dumpXML(xw);
}
}
}
}
} else {
const r = node.findReferencesEx("Aggregates", BrowseDirection.Forward);
for (const reference of r) {
const nodeChild = Reference.resolveReferenceNode(addressSpace, reference) as BaseNode;
assert(nodeChild instanceof BaseNode);
if (nodeChild.nodeId.namespace === node.nodeId.namespace) {
if (!xw.visitedNode[_hash(nodeChild)]) {
console.log(node.nodeId.toString(), " dumping child ", nodeChild.browseName.toString(), nodeChild.nodeId.toString());
nodeChild.dumpXML(xw);
}
}
}
}
}
AddressSpace.prototype.browseSingleNode = function (nodeId, browseDescription, session) {
const addressSpace = this;
// create default browseDescription
browseDescription = browseDescription || {};
browseDescription.browseDirection = browseDescription.browseDirection || BrowseDirection.Forward;
assert(browseDescription.browseDirection);
//xx console.log(util.inspect(browseDescription,{colors:true,depth:5}));
browseDescription = browseDescription || {};
if (typeof nodeId === "string") {
const node = addressSpace.findNode(addressSpace.resolveNodeId(nodeId));
if (node) {
nodeId = node.nodeId;
}
}
const browseResult = {
statusCode: StatusCodes.Good,
continuationPoint: null,
referenceTypeId: makeRefId("HasTypeDefinition"),
resultMask
},
// FromState
{
// BrowseDescription
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeId,
referenceTypeId: makeRefId("FromState"),
resultMask
},
// ToState
{
// BrowseDescription
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeId,
referenceTypeId: makeRefId("ToState"),
resultMask
},
// (for folders ) Organizes
{
// BrowseDescription
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeId,
referenceTypeId: makeRefId("Organizes"),
resultMask
}
];
session.browse(nodesToBrowse, (err: Error | null, browseResults?: BrowseResult[]) => {
BaseNode.prototype.findReferencesEx = function (strReference, browseDirection) {
browseDirection = browseDirection !== undefined ? browseDirection : BrowseDirection.Forward;
assert(_is_valid_BrowseDirection(browseDirection));
assert(browseDirection !== BrowseDirection.Both);
let referenceType = null;
if (typeof strReference === "string") {
//xx strReference = strReference.browseName.toString();
referenceType = this.addressSpace.findReferenceType(strReference);
if (!referenceType) {
throw new Error("Cannot resolve referenceType : " + strReference);
}
} else {
referenceType = strReference;
}
if (!referenceType) {
// note: when loading nodeset2.xml files, reference type may not exit yet
BaseNode.prototype._clone_children_references = function (newParent, optionalFilter, extraInfo) {
const self = this;
assert(newParent instanceof BaseNode);
// find all reference that derives from the Aggregates
const aggregatesRef = self.findReferencesEx("Aggregates", BrowseDirection.Forward);
_clone_collection_new(newParent, aggregatesRef, optionalFilter, extraInfo);
};
BaseNode.prototype._clone_non_hierarchical_references = function (newParent, optionalFilter, extraInfo) {
obj: any,
callback: ErrorCallback
) {
const session = proxyManager.session;
// 0 Object
// 1 Variable
// 2 Method
const nodeId = obj.nodeId;
const nodesToBrowse = [
// Components (except Methods)
{
// BrowseDescription
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeClassMask: makeNodeClassMask("Object | Variable"), // we don't want Method here
nodeId,
referenceTypeId: makeRefId("HasComponent"),
resultMask,
},
// Properties
{
// BrowseDescription
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
// nodeClassMask: makeNodeClassMask("Variable"),
nodeId,
referenceTypeId: makeRefId("HasProperty"),
resultMask
},
function _is_valid_BrowseDirection(browseDirection: any) {
return browseDirection === BrowseDirection.Forward ||
browseDirection === BrowseDirection.Inverse ||
browseDirection === BrowseDirection.Both
;
}
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);
}
}
function _is_valid_BrowseDirection(browseDirection) {
return browseDirection === BrowseDirection.Forward ||
browseDirection === BrowseDirection.Inverse ||
browseDirection === BrowseDirection.Both
;
}