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