node-opcua-convert-nodeset-to-javascript 2.76.1 → 2.76.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.
@@ -1,290 +1,290 @@
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.getValueRank = exports.getChildrenOrFolderElements = exports._convertNodeIdToDataTypeAsync = exports.getTypeDefinition = exports.getTypeDefOrBaseType = exports.getSubtypeNodeId = exports.getSubtypeNodeIdIfAny = exports.extractBasicDataType = exports.isEnumeration = exports.isExtensionObject = exports.getModellingRule = exports.getFolderElements = exports.getChildren = exports.getNodeClass = exports.getDescription = exports.getIsAbstract = exports.getDataTypeNodeId = exports.getBrowseName = exports.getDefinition = void 0;
13
- const node_opcua_data_model_1 = require("node-opcua-data-model");
14
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
- const node_opcua_constants_1 = require("node-opcua-constants");
16
- const node_opcua_types_1 = require("node-opcua-types");
17
- const node_opcua_variant_1 = require("node-opcua-variant");
18
- const node_opcua_status_code_1 = require("node-opcua-status-code");
19
- function getDefinition(session, nodeId) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition });
22
- return dataValue.value.value || null;
23
- });
24
- }
25
- exports.getDefinition = getDefinition;
26
- function getBrowseName(session, nodeId) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.BrowseName });
29
- return dataValue.value.value;
30
- });
31
- }
32
- exports.getBrowseName = getBrowseName;
33
- function getDataTypeNodeId(session, nodeId) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.DataType });
36
- return dataValue.value.value || null;
37
- });
38
- }
39
- exports.getDataTypeNodeId = getDataTypeNodeId;
40
- function getIsAbstract(session, nodeId) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract });
43
- return dataValue.value.value;
44
- });
45
- }
46
- exports.getIsAbstract = getIsAbstract;
47
- function getDescription(session, nodeId) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.Description });
50
- return dataValue.value.value;
51
- });
52
- }
53
- exports.getDescription = getDescription;
54
- function getNodeClass(session, nodeId) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.NodeClass });
57
- return dataValue.value.value;
58
- });
59
- }
60
- exports.getNodeClass = getNodeClass;
61
- function getChildren(session, nodeId) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const browseResult = yield session.browse({
64
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
65
- includeSubtypes: true,
66
- nodeClassMask: node_opcua_data_model_1.NodeClassMask.Method | node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClass.Variable,
67
- nodeId,
68
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasChild"),
69
- resultMask: 0xffff
70
- });
71
- return browseResult.references || [];
72
- });
73
- }
74
- exports.getChildren = getChildren;
75
- function getFolderElements(session, nodeId) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const browseResult = yield session.browse({
78
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
79
- includeSubtypes: true,
80
- nodeClassMask: node_opcua_data_model_1.NodeClassMask.Method | node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClass.Variable,
81
- nodeId,
82
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("Organizes"),
83
- resultMask: 0xffff
84
- });
85
- return browseResult.references || [];
86
- });
87
- }
88
- exports.getFolderElements = getFolderElements;
89
- function getModellingRule(session, nodeId) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- const browseResult = yield session.browse({
92
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
93
- includeSubtypes: true,
94
- nodeClassMask: node_opcua_data_model_1.NodeClassMask.Method | node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClass.Variable,
95
- nodeId,
96
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasModellingRule"),
97
- resultMask: 0xffff
98
- });
99
- if (!browseResult.references || browseResult.references.length === 0) {
100
- return null;
101
- /*
102
- console.log(nodeId.toString());
103
- const browseName = await getBrowseName(session, nodeId);
104
- throw new Error("No modelling rule for " + nodeId.toString() + " " + browseName.toString());
105
- */
106
- }
107
- return browseResult.references[0].browseName.name;
108
- });
109
- }
110
- exports.getModellingRule = getModellingRule;
111
- function isExtensionObject(session, nodeId) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- if (nodeId.namespace === 0 && nodeId.value === node_opcua_constants_1.DataTypeIds.Structure) {
114
- return true;
115
- }
116
- if (nodeId.namespace === 0 && nodeId.value <= node_opcua_constants_1.DataTypeIds.DiagnosticInfo) {
117
- return false;
118
- }
119
- const r = yield getSubtypeNodeIdIfAny(session, nodeId);
120
- return yield isExtensionObject(session, r.nodeId);
121
- });
122
- }
123
- exports.isExtensionObject = isExtensionObject;
124
- function isEnumeration(session, nodeId) {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- if (nodeId.namespace === 0 && nodeId.value === node_opcua_constants_1.DataTypeIds.Enumeration) {
127
- return true;
128
- }
129
- if (nodeId.namespace === 0 && nodeId.value <= node_opcua_constants_1.DataTypeIds.DiagnosticInfo) {
130
- return false;
131
- }
132
- const r = yield getSubtypeNodeIdIfAny(session, nodeId);
133
- return yield isEnumeration(session, r.nodeId);
134
- });
135
- }
136
- exports.isEnumeration = isEnumeration;
137
- function extractBasicDataType(session, dataTypeNodeId) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value <= 25) {
140
- return dataTypeNodeId.value;
141
- }
142
- const r = yield getSubtypeNodeIdIfAny(session, dataTypeNodeId);
143
- return yield extractBasicDataType(session, r.nodeId);
144
- });
145
- }
146
- exports.extractBasicDataType = extractBasicDataType;
147
- function getSubtypeNodeIdIfAny(session, nodeId) {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- if (nodeId.isEmpty()) {
150
- return null;
151
- }
152
- const browseResult = yield session.browse({
153
- browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
154
- includeSubtypes: true,
155
- nodeClassMask: 0,
156
- nodeId,
157
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
158
- resultMask: 0xffff
159
- });
160
- if (!browseResult.references || browseResult.references.length === 0) {
161
- return null;
162
- }
163
- return browseResult.references[0];
164
- });
165
- }
166
- exports.getSubtypeNodeIdIfAny = getSubtypeNodeIdIfAny;
167
- function getSubtypeNodeId(session, nodeId) {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- const r = yield getSubtypeNodeIdIfAny(session, nodeId);
170
- if (!r) {
171
- throw new Error("No Subtype");
172
- }
173
- return r;
174
- });
175
- }
176
- exports.getSubtypeNodeId = getSubtypeNodeId;
177
- function getTypeDefOrBaseType(session, nodeId) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- let browseResult = yield session.browse({
180
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
181
- includeSubtypes: true,
182
- nodeClassMask: 0,
183
- nodeId,
184
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasTypeDefinition"),
185
- resultMask: 0xffff
186
- });
187
- if (!browseResult.references || browseResult.references.length === 0) {
188
- browseResult = yield session.browse({
189
- browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
190
- includeSubtypes: true,
191
- nodeClassMask: 0,
192
- nodeId,
193
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
194
- resultMask: 0xffff
195
- });
196
- }
197
- if (!browseResult.references || browseResult.references.length === 0) {
198
- // console.log("cannot find type definition / subtype for " + nodeId.toString());
199
- return new node_opcua_types_1.ReferenceDescription({});
200
- }
201
- return browseResult.references[0];
202
- });
203
- }
204
- exports.getTypeDefOrBaseType = getTypeDefOrBaseType;
205
- function getTypeDefinition(session, nodeId) {
206
- return __awaiter(this, void 0, void 0, function* () {
207
- const browseResult = yield session.browse({
208
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
209
- includeSubtypes: true,
210
- nodeClassMask: 0,
211
- nodeId,
212
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasTypeDefinition"),
213
- resultMask: 0xffff
214
- });
215
- if (!browseResult.references || browseResult.references.length === 0) {
216
- console.log(nodeId.toString());
217
- throw new Error("No subtype");
218
- }
219
- return browseResult.references[0];
220
- });
221
- }
222
- exports.getTypeDefinition = getTypeDefinition;
223
- function readBrowseName(session, nodeId) {
224
- return __awaiter(this, void 0, void 0, function* () {
225
- const nodeToRead = {
226
- attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
227
- nodeId
228
- };
229
- const dataValue = yield session.read(nodeToRead);
230
- // istanbul ignore next
231
- if (dataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
232
- // throw new Error("Error " + dataValue.statusCode.toString() + " " + nodeId.toString());
233
- // console.log("Error " + dataValue.statusCode.toString() + " " + nodeId.toString());
234
- return new node_opcua_data_model_1.QualifiedName({ name: "", namespaceIndex: 0 });
235
- }
236
- const dataTypeName = dataValue.value.value;
237
- return dataTypeName;
238
- });
239
- }
240
- // see also client-proxy
241
- function _convertNodeIdToDataTypeAsync(session, dataTypeId) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- const dataTypeName = yield readBrowseName(session, dataTypeId);
244
- let dataType;
245
- if (dataTypeId.namespace === 0 && dataTypeId.value === node_opcua_constants_1.DataTypeIds.Enumeration) {
246
- return { dataType: node_opcua_variant_1.DataType.Int32, enumerationId: dataTypeId };
247
- }
248
- if (dataTypeId.namespace === 0 && node_opcua_variant_1.DataType[dataTypeId.value]) {
249
- dataType = dataTypeId.value;
250
- return { dataType };
251
- }
252
- /// example => Duration (i=290) => Double (i=11)
253
- // read subTypeOf
254
- const nodeToBrowse = {
255
- browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
256
- nodeId: dataTypeId,
257
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
258
- resultMask: 0xff
259
- };
260
- // tslint:disable:no-shadowed-variable
261
- const browseResult = yield session.browse(nodeToBrowse);
262
- const references = browseResult.references;
263
- if (!references || references.length !== 1) {
264
- throw new Error("cannot find SuperType of " + dataTypeName.toString());
265
- }
266
- const nodeId = references[0].nodeId;
267
- const info = yield _convertNodeIdToDataTypeAsync(session, nodeId);
268
- if (info.enumerationId) {
269
- return Object.assign(Object.assign({}, info), { enumerationId: dataTypeId, enumerationType: dataTypeName.name });
270
- }
271
- return info;
272
- });
273
- }
274
- exports._convertNodeIdToDataTypeAsync = _convertNodeIdToDataTypeAsync;
275
- function getChildrenOrFolderElements(session, nodeId) {
276
- return __awaiter(this, void 0, void 0, function* () {
277
- const c1 = yield getChildren(session, nodeId);
278
- const c2 = yield getFolderElements(session, nodeId);
279
- return [].concat(c1, c2);
280
- });
281
- }
282
- exports.getChildrenOrFolderElements = getChildrenOrFolderElements;
283
- function getValueRank(session, nodeId) {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- const valueRankDataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.ValueRank });
286
- return valueRankDataValue.value.value;
287
- });
288
- }
289
- exports.getValueRank = getValueRank;
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.getValueRank = exports.getChildrenOrFolderElements = exports._convertNodeIdToDataTypeAsync = exports.getTypeDefinition = exports.getTypeDefOrBaseType = exports.getSubtypeNodeId = exports.getSubtypeNodeIdIfAny = exports.extractBasicDataType = exports.isEnumeration = exports.isExtensionObject = exports.getModellingRule = exports.getFolderElements = exports.getChildren = exports.getNodeClass = exports.getDescription = exports.getIsAbstract = exports.getDataTypeNodeId = exports.getBrowseName = exports.getDefinition = void 0;
13
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
14
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
+ const node_opcua_constants_1 = require("node-opcua-constants");
16
+ const node_opcua_types_1 = require("node-opcua-types");
17
+ const node_opcua_variant_1 = require("node-opcua-variant");
18
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
19
+ function getDefinition(session, nodeId) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition });
22
+ return dataValue.value.value || null;
23
+ });
24
+ }
25
+ exports.getDefinition = getDefinition;
26
+ function getBrowseName(session, nodeId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.BrowseName });
29
+ return dataValue.value.value;
30
+ });
31
+ }
32
+ exports.getBrowseName = getBrowseName;
33
+ function getDataTypeNodeId(session, nodeId) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.DataType });
36
+ return dataValue.value.value || null;
37
+ });
38
+ }
39
+ exports.getDataTypeNodeId = getDataTypeNodeId;
40
+ function getIsAbstract(session, nodeId) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract });
43
+ return dataValue.value.value;
44
+ });
45
+ }
46
+ exports.getIsAbstract = getIsAbstract;
47
+ function getDescription(session, nodeId) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.Description });
50
+ return dataValue.value.value;
51
+ });
52
+ }
53
+ exports.getDescription = getDescription;
54
+ function getNodeClass(session, nodeId) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const dataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.NodeClass });
57
+ return dataValue.value.value;
58
+ });
59
+ }
60
+ exports.getNodeClass = getNodeClass;
61
+ function getChildren(session, nodeId) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const browseResult = yield session.browse({
64
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
65
+ includeSubtypes: true,
66
+ nodeClassMask: node_opcua_data_model_1.NodeClassMask.Method | node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClass.Variable,
67
+ nodeId,
68
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasChild"),
69
+ resultMask: 0xffff
70
+ });
71
+ return browseResult.references || [];
72
+ });
73
+ }
74
+ exports.getChildren = getChildren;
75
+ function getFolderElements(session, nodeId) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const browseResult = yield session.browse({
78
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
79
+ includeSubtypes: true,
80
+ nodeClassMask: node_opcua_data_model_1.NodeClassMask.Method | node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClass.Variable,
81
+ nodeId,
82
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("Organizes"),
83
+ resultMask: 0xffff
84
+ });
85
+ return browseResult.references || [];
86
+ });
87
+ }
88
+ exports.getFolderElements = getFolderElements;
89
+ function getModellingRule(session, nodeId) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const browseResult = yield session.browse({
92
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
93
+ includeSubtypes: true,
94
+ nodeClassMask: node_opcua_data_model_1.NodeClassMask.Method | node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClass.Variable,
95
+ nodeId,
96
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasModellingRule"),
97
+ resultMask: 0xffff
98
+ });
99
+ if (!browseResult.references || browseResult.references.length === 0) {
100
+ return null;
101
+ /*
102
+ console.log(nodeId.toString());
103
+ const browseName = await getBrowseName(session, nodeId);
104
+ throw new Error("No modelling rule for " + nodeId.toString() + " " + browseName.toString());
105
+ */
106
+ }
107
+ return browseResult.references[0].browseName.name;
108
+ });
109
+ }
110
+ exports.getModellingRule = getModellingRule;
111
+ function isExtensionObject(session, nodeId) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ if (nodeId.namespace === 0 && nodeId.value === node_opcua_constants_1.DataTypeIds.Structure) {
114
+ return true;
115
+ }
116
+ if (nodeId.namespace === 0 && nodeId.value <= node_opcua_constants_1.DataTypeIds.DiagnosticInfo) {
117
+ return false;
118
+ }
119
+ const r = yield getSubtypeNodeIdIfAny(session, nodeId);
120
+ return yield isExtensionObject(session, r.nodeId);
121
+ });
122
+ }
123
+ exports.isExtensionObject = isExtensionObject;
124
+ function isEnumeration(session, nodeId) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ if (nodeId.namespace === 0 && nodeId.value === node_opcua_constants_1.DataTypeIds.Enumeration) {
127
+ return true;
128
+ }
129
+ if (nodeId.namespace === 0 && nodeId.value <= node_opcua_constants_1.DataTypeIds.DiagnosticInfo) {
130
+ return false;
131
+ }
132
+ const r = yield getSubtypeNodeIdIfAny(session, nodeId);
133
+ return yield isEnumeration(session, r.nodeId);
134
+ });
135
+ }
136
+ exports.isEnumeration = isEnumeration;
137
+ function extractBasicDataType(session, dataTypeNodeId) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ if (dataTypeNodeId.namespace === 0 && dataTypeNodeId.value <= 25) {
140
+ return dataTypeNodeId.value;
141
+ }
142
+ const r = yield getSubtypeNodeIdIfAny(session, dataTypeNodeId);
143
+ return yield extractBasicDataType(session, r.nodeId);
144
+ });
145
+ }
146
+ exports.extractBasicDataType = extractBasicDataType;
147
+ function getSubtypeNodeIdIfAny(session, nodeId) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ if (nodeId.isEmpty()) {
150
+ return null;
151
+ }
152
+ const browseResult = yield session.browse({
153
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
154
+ includeSubtypes: true,
155
+ nodeClassMask: 0,
156
+ nodeId,
157
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
158
+ resultMask: 0xffff
159
+ });
160
+ if (!browseResult.references || browseResult.references.length === 0) {
161
+ return null;
162
+ }
163
+ return browseResult.references[0];
164
+ });
165
+ }
166
+ exports.getSubtypeNodeIdIfAny = getSubtypeNodeIdIfAny;
167
+ function getSubtypeNodeId(session, nodeId) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ const r = yield getSubtypeNodeIdIfAny(session, nodeId);
170
+ if (!r) {
171
+ throw new Error("No Subtype");
172
+ }
173
+ return r;
174
+ });
175
+ }
176
+ exports.getSubtypeNodeId = getSubtypeNodeId;
177
+ function getTypeDefOrBaseType(session, nodeId) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ let browseResult = yield session.browse({
180
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
181
+ includeSubtypes: true,
182
+ nodeClassMask: 0,
183
+ nodeId,
184
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasTypeDefinition"),
185
+ resultMask: 0xffff
186
+ });
187
+ if (!browseResult.references || browseResult.references.length === 0) {
188
+ browseResult = yield session.browse({
189
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
190
+ includeSubtypes: true,
191
+ nodeClassMask: 0,
192
+ nodeId,
193
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
194
+ resultMask: 0xffff
195
+ });
196
+ }
197
+ if (!browseResult.references || browseResult.references.length === 0) {
198
+ // console.log("cannot find type definition / subtype for " + nodeId.toString());
199
+ return new node_opcua_types_1.ReferenceDescription({});
200
+ }
201
+ return browseResult.references[0];
202
+ });
203
+ }
204
+ exports.getTypeDefOrBaseType = getTypeDefOrBaseType;
205
+ function getTypeDefinition(session, nodeId) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ const browseResult = yield session.browse({
208
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
209
+ includeSubtypes: true,
210
+ nodeClassMask: 0,
211
+ nodeId,
212
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasTypeDefinition"),
213
+ resultMask: 0xffff
214
+ });
215
+ if (!browseResult.references || browseResult.references.length === 0) {
216
+ console.log(nodeId.toString());
217
+ throw new Error("No subtype");
218
+ }
219
+ return browseResult.references[0];
220
+ });
221
+ }
222
+ exports.getTypeDefinition = getTypeDefinition;
223
+ function readBrowseName(session, nodeId) {
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ const nodeToRead = {
226
+ attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
227
+ nodeId
228
+ };
229
+ const dataValue = yield session.read(nodeToRead);
230
+ // istanbul ignore next
231
+ if (dataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
232
+ // throw new Error("Error " + dataValue.statusCode.toString() + " " + nodeId.toString());
233
+ // console.log("Error " + dataValue.statusCode.toString() + " " + nodeId.toString());
234
+ return new node_opcua_data_model_1.QualifiedName({ name: "", namespaceIndex: 0 });
235
+ }
236
+ const dataTypeName = dataValue.value.value;
237
+ return dataTypeName;
238
+ });
239
+ }
240
+ // see also client-proxy
241
+ function _convertNodeIdToDataTypeAsync(session, dataTypeId) {
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ const dataTypeName = yield readBrowseName(session, dataTypeId);
244
+ let dataType;
245
+ if (dataTypeId.namespace === 0 && dataTypeId.value === node_opcua_constants_1.DataTypeIds.Enumeration) {
246
+ return { dataType: node_opcua_variant_1.DataType.Int32, enumerationId: dataTypeId };
247
+ }
248
+ if (dataTypeId.namespace === 0 && node_opcua_variant_1.DataType[dataTypeId.value]) {
249
+ dataType = dataTypeId.value;
250
+ return { dataType };
251
+ }
252
+ /// example => Duration (i=290) => Double (i=11)
253
+ // read subTypeOf
254
+ const nodeToBrowse = {
255
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
256
+ nodeId: dataTypeId,
257
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
258
+ resultMask: 0xff
259
+ };
260
+ // tslint:disable:no-shadowed-variable
261
+ const browseResult = yield session.browse(nodeToBrowse);
262
+ const references = browseResult.references;
263
+ if (!references || references.length !== 1) {
264
+ throw new Error("cannot find SuperType of " + dataTypeName.toString());
265
+ }
266
+ const nodeId = references[0].nodeId;
267
+ const info = yield _convertNodeIdToDataTypeAsync(session, nodeId);
268
+ if (info.enumerationId) {
269
+ return Object.assign(Object.assign({}, info), { enumerationId: dataTypeId, enumerationType: dataTypeName.name });
270
+ }
271
+ return info;
272
+ });
273
+ }
274
+ exports._convertNodeIdToDataTypeAsync = _convertNodeIdToDataTypeAsync;
275
+ function getChildrenOrFolderElements(session, nodeId) {
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ const c1 = yield getChildren(session, nodeId);
278
+ const c2 = yield getFolderElements(session, nodeId);
279
+ return [].concat(c1, c2);
280
+ });
281
+ }
282
+ exports.getChildrenOrFolderElements = getChildrenOrFolderElements;
283
+ function getValueRank(session, nodeId) {
284
+ return __awaiter(this, void 0, void 0, function* () {
285
+ const valueRankDataValue = yield session.read({ nodeId, attributeId: node_opcua_data_model_1.AttributeIds.ValueRank });
286
+ return valueRankDataValue.value.value;
287
+ });
288
+ }
289
+ exports.getValueRank = getValueRank;
290
290
  //# sourceMappingURL=utils.js.map
@@ -1,4 +1,4 @@
1
- export * from "./index";
2
- export * from "./options";
3
- export * from "./private/cache";
4
- export * from "./private/utils";
1
+ export * from "./index";
2
+ export * from "./options";
3
+ export * from "./private/cache";
4
+ export * from "./private/utils";
@@ -1,21 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./index"), exports);
18
- __exportStar(require("./options"), exports);
19
- __exportStar(require("./private/cache"), exports);
20
- __exportStar(require("./private/utils"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./index"), exports);
18
+ __exportStar(require("./options"), exports);
19
+ __exportStar(require("./private/cache"), exports);
20
+ __exportStar(require("./private/utils"), exports);
21
21
  //# sourceMappingURL=private-stuff.js.map