opcua-webapi-ts 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/utils/UaDataTypeDictionary.js +3 -1
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +3 -1
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +3 -1
- package/dist/cjs/client/utils/UaVariableTypeDictionary.js +84 -0
- package/dist/cjs/client/utils/index.js +1 -0
- package/dist/cjs/common/types/UaExpandedNodeId.js +15 -4
- package/dist/client/utils/UaDataTypeDictionary.js +3 -1
- package/dist/client/utils/UaObjectTypeDictionary.js +3 -1
- package/dist/client/utils/UaReferenceTypeDictionary.js +3 -1
- package/dist/client/utils/UaVariableTypeDictionary.d.ts +12 -0
- package/dist/client/utils/UaVariableTypeDictionary.js +84 -0
- package/dist/client/utils/index.d.ts +1 -0
- package/dist/client/utils/index.js +1 -0
- package/dist/common/types/UaExpandedNodeId.js +15 -4
- package/package.json +1 -1
|
@@ -61,9 +61,11 @@ class UaDataTypeDictionary {
|
|
|
61
61
|
// Build parent-child relationship
|
|
62
62
|
for (let item of results) {
|
|
63
63
|
let parentType = this._dataTypes.get(item.nodeId.toString());
|
|
64
|
+
if (!parentType)
|
|
65
|
+
continue;
|
|
64
66
|
for (let reference of item.references) {
|
|
65
67
|
let dataType = this._dataTypes.get(reference.nodeId.toString());
|
|
66
|
-
if (dataType
|
|
68
|
+
if (dataType)
|
|
67
69
|
dataType.setParentType(parentType);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -59,9 +59,11 @@ class UaObjectTypeDictionary {
|
|
|
59
59
|
// Build parent-child relationship
|
|
60
60
|
for (let item of results) {
|
|
61
61
|
let parentType = this._objectTypes.get(item.nodeId.toString());
|
|
62
|
+
if (!parentType)
|
|
63
|
+
continue;
|
|
62
64
|
for (let reference of item.references) {
|
|
63
65
|
let objectType = this._objectTypes.get(reference.nodeId.toString());
|
|
64
|
-
if (objectType
|
|
66
|
+
if (objectType)
|
|
65
67
|
objectType.setParentType(parentType);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -59,9 +59,11 @@ class UaReferenceTypeDictionary {
|
|
|
59
59
|
// Build parent-child relationship
|
|
60
60
|
for (let item of results) {
|
|
61
61
|
let parentType = this._referenceTypes.get(item.nodeId.toString());
|
|
62
|
+
if (!parentType)
|
|
63
|
+
continue;
|
|
62
64
|
for (let reference of item.references) {
|
|
63
65
|
let referenceType = this._referenceTypes.get(reference.nodeId.toString());
|
|
64
|
-
if (referenceType
|
|
66
|
+
if (referenceType)
|
|
65
67
|
referenceType.setParentType(parentType);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UaVariableTypeDictionary = void 0;
|
|
13
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
|
+
const common_1 = require("../../common");
|
|
15
|
+
const UaNodeBrowser_1 = require("./UaNodeBrowser");
|
|
16
|
+
const UaNodeReader_1 = require("./UaNodeReader");
|
|
17
|
+
class UaVariableTypeDictionary {
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this._client = client;
|
|
20
|
+
this._variables = new Map;
|
|
21
|
+
let baseVariableTypeId = new common_1.UaNodeId(common_1.VariableTypeIds.BaseVariableType);
|
|
22
|
+
this._variables.set(baseVariableTypeId.toString(), new common_1.UaVariableType(baseVariableTypeId, "BaseVariableType", new common_1.UaLocalizedText("BaseVariableType"), true, common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType), -2));
|
|
23
|
+
}
|
|
24
|
+
read() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let browser = new UaNodeBrowser_1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.VariableTypeIds.BaseVariableType)]);
|
|
27
|
+
yield this._read(browser);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getVariableType(nodeId) {
|
|
31
|
+
let dataType = this._variables.get(nodeId.toString());
|
|
32
|
+
return (dataType) ? dataType : null;
|
|
33
|
+
}
|
|
34
|
+
getVariableTypes() {
|
|
35
|
+
return [...this._variables.values()];
|
|
36
|
+
}
|
|
37
|
+
_read(browser) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
// Browse child type
|
|
40
|
+
yield browser.browse();
|
|
41
|
+
let results = browser.results();
|
|
42
|
+
let referencesToRead = [];
|
|
43
|
+
for (let item of results) {
|
|
44
|
+
for (let reference of item.references)
|
|
45
|
+
referencesToRead.push(reference);
|
|
46
|
+
}
|
|
47
|
+
if (0 == referencesToRead.length)
|
|
48
|
+
return;
|
|
49
|
+
// Read child type
|
|
50
|
+
let nodeIdsToBrowse = [];
|
|
51
|
+
let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, true, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, true, true, true, true);
|
|
52
|
+
let nodes = yield nodeReader.readByReferences(referencesToRead);
|
|
53
|
+
for (let node of nodes) {
|
|
54
|
+
if (opcua_webapi_1.NodeClass.VariableType != node.nodeClass)
|
|
55
|
+
continue;
|
|
56
|
+
nodeIdsToBrowse.push(node.nodeId);
|
|
57
|
+
this._variables.set(node.nodeId.toString(), node);
|
|
58
|
+
}
|
|
59
|
+
// Build parent-child relationship
|
|
60
|
+
for (let item of results) {
|
|
61
|
+
let parentType = this._variables.get(item.nodeId.toString());
|
|
62
|
+
if (!parentType)
|
|
63
|
+
continue;
|
|
64
|
+
for (let reference of item.references) {
|
|
65
|
+
let variableType = this._variables.get(reference.nodeId.toString());
|
|
66
|
+
if (variableType)
|
|
67
|
+
variableType.setParentType(parentType);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (0 == nodeIdsToBrowse.length)
|
|
71
|
+
return;
|
|
72
|
+
yield this.__delay(20);
|
|
73
|
+
// Continue to browse and read child type
|
|
74
|
+
let childBrowser = new UaNodeBrowser_1.UaTypeBrowser(this._client, nodeIdsToBrowse);
|
|
75
|
+
yield this._read(childBrowser);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
__delay(ms) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.UaVariableTypeDictionary = UaVariableTypeDictionary;
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./UaDataTypeDictionary"), exports);
|
|
18
18
|
__exportStar(require("./UaObjectTypeDictionary"), exports);
|
|
19
19
|
__exportStar(require("./UaReferenceTypeDictionary"), exports);
|
|
20
|
+
__exportStar(require("./UaVariableTypeDictionary"), exports);
|
|
20
21
|
__exportStar(require("./UaNodeBrowser"), exports);
|
|
21
22
|
__exportStar(require("./UaNodeReader"), exports);
|
|
22
23
|
__exportStar(require("./UaModelling"), exports);
|
|
@@ -41,17 +41,28 @@ class UaExpandedNodeId {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
toString() {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
let str = this._nodeId.toString();
|
|
45
|
+
if (this._serverIndex) {
|
|
46
|
+
str = "svr=" + this._serverIndex + ";" + str;
|
|
47
|
+
}
|
|
48
|
+
return str;
|
|
46
49
|
}
|
|
47
50
|
static from(nodeId) {
|
|
48
51
|
return new UaExpandedNodeId(nodeId);
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
exports.UaExpandedNodeId = UaExpandedNodeId;
|
|
55
|
+
const regexSvr = /^svr=([0-9]+);/;
|
|
52
56
|
function parseUaExpandedNodeId(value) {
|
|
53
|
-
let
|
|
54
|
-
|
|
57
|
+
let serverIndex = 0;
|
|
58
|
+
let nodeIdStr = value;
|
|
59
|
+
let matches = regexSvr.exec(value);
|
|
60
|
+
if (matches !== null) {
|
|
61
|
+
serverIndex = parseInt(matches[1], 10);
|
|
62
|
+
nodeIdStr = value.substring(matches[0].length);
|
|
63
|
+
}
|
|
64
|
+
let nodeId = (0, _1.parseUaNodeId)(nodeIdStr);
|
|
65
|
+
return new UaExpandedNodeId(nodeId, null, serverIndex);
|
|
55
66
|
}
|
|
56
67
|
function parseUaExpandedNodeIdOrNull(value) {
|
|
57
68
|
if (!value)
|
|
@@ -61,9 +61,11 @@ class UaDataTypeDictionary {
|
|
|
61
61
|
// Build parent-child relationship
|
|
62
62
|
for (let item of results) {
|
|
63
63
|
let parentType = this._dataTypes.get(item.nodeId.toString());
|
|
64
|
+
if (!parentType)
|
|
65
|
+
continue;
|
|
64
66
|
for (let reference of item.references) {
|
|
65
67
|
let dataType = this._dataTypes.get(reference.nodeId.toString());
|
|
66
|
-
if (dataType
|
|
68
|
+
if (dataType)
|
|
67
69
|
dataType.setParentType(parentType);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -59,9 +59,11 @@ class UaObjectTypeDictionary {
|
|
|
59
59
|
// Build parent-child relationship
|
|
60
60
|
for (let item of results) {
|
|
61
61
|
let parentType = this._objectTypes.get(item.nodeId.toString());
|
|
62
|
+
if (!parentType)
|
|
63
|
+
continue;
|
|
62
64
|
for (let reference of item.references) {
|
|
63
65
|
let objectType = this._objectTypes.get(reference.nodeId.toString());
|
|
64
|
-
if (objectType
|
|
66
|
+
if (objectType)
|
|
65
67
|
objectType.setParentType(parentType);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -59,9 +59,11 @@ class UaReferenceTypeDictionary {
|
|
|
59
59
|
// Build parent-child relationship
|
|
60
60
|
for (let item of results) {
|
|
61
61
|
let parentType = this._referenceTypes.get(item.nodeId.toString());
|
|
62
|
+
if (!parentType)
|
|
63
|
+
continue;
|
|
62
64
|
for (let reference of item.references) {
|
|
63
65
|
let referenceType = this._referenceTypes.get(reference.nodeId.toString());
|
|
64
|
-
if (referenceType
|
|
66
|
+
if (referenceType)
|
|
65
67
|
referenceType.setParentType(parentType);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UaNodeId, UaVariableType } from "../../common";
|
|
2
|
+
import { UaWebClient } from "../UaWebClient";
|
|
3
|
+
export declare class UaVariableTypeDictionary {
|
|
4
|
+
private _client;
|
|
5
|
+
private _variables;
|
|
6
|
+
constructor(client: UaWebClient);
|
|
7
|
+
read(): Promise<void>;
|
|
8
|
+
getVariableType(nodeId: UaNodeId): UaVariableType | null;
|
|
9
|
+
getVariableTypes(): Array<UaVariableType>;
|
|
10
|
+
private _read;
|
|
11
|
+
private __delay;
|
|
12
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UaVariableTypeDictionary = void 0;
|
|
13
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
|
+
const common_1 = require("../../common");
|
|
15
|
+
const UaNodeBrowser_1 = require("./UaNodeBrowser");
|
|
16
|
+
const UaNodeReader_1 = require("./UaNodeReader");
|
|
17
|
+
class UaVariableTypeDictionary {
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this._client = client;
|
|
20
|
+
this._variables = new Map;
|
|
21
|
+
let baseVariableTypeId = new common_1.UaNodeId(common_1.VariableTypeIds.BaseVariableType);
|
|
22
|
+
this._variables.set(baseVariableTypeId.toString(), new common_1.UaVariableType(baseVariableTypeId, "BaseVariableType", new common_1.UaLocalizedText("BaseVariableType"), true, common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType), -2));
|
|
23
|
+
}
|
|
24
|
+
read() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let browser = new UaNodeBrowser_1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.VariableTypeIds.BaseVariableType)]);
|
|
27
|
+
yield this._read(browser);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getVariableType(nodeId) {
|
|
31
|
+
let dataType = this._variables.get(nodeId.toString());
|
|
32
|
+
return (dataType) ? dataType : null;
|
|
33
|
+
}
|
|
34
|
+
getVariableTypes() {
|
|
35
|
+
return [...this._variables.values()];
|
|
36
|
+
}
|
|
37
|
+
_read(browser) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
// Browse child type
|
|
40
|
+
yield browser.browse();
|
|
41
|
+
let results = browser.results();
|
|
42
|
+
let referencesToRead = [];
|
|
43
|
+
for (let item of results) {
|
|
44
|
+
for (let reference of item.references)
|
|
45
|
+
referencesToRead.push(reference);
|
|
46
|
+
}
|
|
47
|
+
if (0 == referencesToRead.length)
|
|
48
|
+
return;
|
|
49
|
+
// Read child type
|
|
50
|
+
let nodeIdsToBrowse = [];
|
|
51
|
+
let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, true, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, true, true, true, true);
|
|
52
|
+
let nodes = yield nodeReader.readByReferences(referencesToRead);
|
|
53
|
+
for (let node of nodes) {
|
|
54
|
+
if (opcua_webapi_1.NodeClass.VariableType != node.nodeClass)
|
|
55
|
+
continue;
|
|
56
|
+
nodeIdsToBrowse.push(node.nodeId);
|
|
57
|
+
this._variables.set(node.nodeId.toString(), node);
|
|
58
|
+
}
|
|
59
|
+
// Build parent-child relationship
|
|
60
|
+
for (let item of results) {
|
|
61
|
+
let parentType = this._variables.get(item.nodeId.toString());
|
|
62
|
+
if (!parentType)
|
|
63
|
+
continue;
|
|
64
|
+
for (let reference of item.references) {
|
|
65
|
+
let variableType = this._variables.get(reference.nodeId.toString());
|
|
66
|
+
if (variableType)
|
|
67
|
+
variableType.setParentType(parentType);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (0 == nodeIdsToBrowse.length)
|
|
71
|
+
return;
|
|
72
|
+
yield this.__delay(20);
|
|
73
|
+
// Continue to browse and read child type
|
|
74
|
+
let childBrowser = new UaNodeBrowser_1.UaTypeBrowser(this._client, nodeIdsToBrowse);
|
|
75
|
+
yield this._read(childBrowser);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
__delay(ms) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.UaVariableTypeDictionary = UaVariableTypeDictionary;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./UaDataTypeDictionary";
|
|
2
2
|
export * from "./UaObjectTypeDictionary";
|
|
3
3
|
export * from "./UaReferenceTypeDictionary";
|
|
4
|
+
export * from "./UaVariableTypeDictionary";
|
|
4
5
|
export * from "./UaNodeBrowser";
|
|
5
6
|
export * from "./UaNodeReader";
|
|
6
7
|
export * from "./UaModelling";
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./UaDataTypeDictionary"), exports);
|
|
18
18
|
__exportStar(require("./UaObjectTypeDictionary"), exports);
|
|
19
19
|
__exportStar(require("./UaReferenceTypeDictionary"), exports);
|
|
20
|
+
__exportStar(require("./UaVariableTypeDictionary"), exports);
|
|
20
21
|
__exportStar(require("./UaNodeBrowser"), exports);
|
|
21
22
|
__exportStar(require("./UaNodeReader"), exports);
|
|
22
23
|
__exportStar(require("./UaModelling"), exports);
|
|
@@ -41,17 +41,28 @@ class UaExpandedNodeId {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
toString() {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
let str = this._nodeId.toString();
|
|
45
|
+
if (this._serverIndex) {
|
|
46
|
+
str = "svr=" + this._serverIndex + ";" + str;
|
|
47
|
+
}
|
|
48
|
+
return str;
|
|
46
49
|
}
|
|
47
50
|
static from(nodeId) {
|
|
48
51
|
return new UaExpandedNodeId(nodeId);
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
exports.UaExpandedNodeId = UaExpandedNodeId;
|
|
55
|
+
const regexSvr = /^svr=([0-9]+);/;
|
|
52
56
|
function parseUaExpandedNodeId(value) {
|
|
53
|
-
let
|
|
54
|
-
|
|
57
|
+
let serverIndex = 0;
|
|
58
|
+
let nodeIdStr = value;
|
|
59
|
+
let matches = regexSvr.exec(value);
|
|
60
|
+
if (matches !== null) {
|
|
61
|
+
serverIndex = parseInt(matches[1], 10);
|
|
62
|
+
nodeIdStr = value.substring(matches[0].length);
|
|
63
|
+
}
|
|
64
|
+
let nodeId = (0, _1.parseUaNodeId)(nodeIdStr);
|
|
65
|
+
return new UaExpandedNodeId(nodeId, null, serverIndex);
|
|
55
66
|
}
|
|
56
67
|
function parseUaExpandedNodeIdOrNull(value) {
|
|
57
68
|
if (!value)
|