node-opcua-client-dynamic-extension-object 2.97.0 → 2.98.1
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/convert_data_type_definition_to_structuretype_schema.d.ts +14 -14
- package/dist/convert_data_type_definition_to_structuretype_schema.js +410 -410
- package/dist/convert_structuretype_schema_to_structure_definition.d.ts +3 -3
- package/dist/convert_structuretype_schema_to_structure_definition.js +53 -53
- package/dist/extra_data_type_manager.d.ts +16 -16
- package/dist/extra_data_type_manager.js +78 -78
- package/dist/get_extension_object_constructor.d.ts +7 -7
- package/dist/get_extension_object_constructor.js +37 -37
- package/dist/get_extra_data_type_manager.d.ts +3 -3
- package/dist/get_extra_data_type_manager.js +51 -51
- package/dist/index.d.ts +13 -13
- package/dist/index.js +29 -29
- package/dist/populate_data_type_manager.d.ts +3 -3
- package/dist/populate_data_type_manager.js +88 -88
- package/dist/private/find_encodings.d.ts +4 -4
- package/dist/private/find_encodings.js +55 -55
- package/dist/private/populate_data_type_manager_103.d.ts +9 -9
- package/dist/private/populate_data_type_manager_103.js +639 -639
- package/dist/private/populate_data_type_manager_104.d.ts +9 -9
- package/dist/private/populate_data_type_manager_104.js +217 -217
- package/dist/promote_opaque_structure.d.ts +7 -7
- package/dist/promote_opaque_structure.js +46 -46
- package/dist/promote_opaque_structure_in_notification_data.d.ts +3 -3
- package/dist/promote_opaque_structure_in_notification_data.js +51 -51
- package/dist/resolve_dynamic_extension_object.d.ts +6 -6
- package/dist/resolve_dynamic_extension_object.js +177 -177
- package/package.json +22 -18
- package/test/test_convertStructureTypeSchemaToStructureDefinition.ts +0 -117
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DataTypeFactory } from "node-opcua-factory";
|
|
2
|
-
import { NodeId } from "node-opcua-nodeid";
|
|
3
|
-
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
4
|
-
import { ExtraDataTypeManager } from "../extra_data_type_manager";
|
|
5
|
-
import { CacheForFieldResolution } from "../convert_data_type_definition_to_structuretype_schema";
|
|
6
|
-
export declare function readDataTypeDefinitionAndBuildType(session: IBasicSession, dataTypeNodeId: NodeId, name: string, dataTypeFactory: DataTypeFactory, cache: {
|
|
7
|
-
[key: string]: CacheForFieldResolution;
|
|
8
|
-
}): Promise<void>;
|
|
9
|
-
export declare function populateDataTypeManager104(session: IBasicSession, dataTypeManager: ExtraDataTypeManager): Promise<void>;
|
|
1
|
+
import { DataTypeFactory } from "node-opcua-factory";
|
|
2
|
+
import { NodeId } from "node-opcua-nodeid";
|
|
3
|
+
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
4
|
+
import { ExtraDataTypeManager } from "../extra_data_type_manager";
|
|
5
|
+
import { CacheForFieldResolution } from "../convert_data_type_definition_to_structuretype_schema";
|
|
6
|
+
export declare function readDataTypeDefinitionAndBuildType(session: IBasicSession, dataTypeNodeId: NodeId, name: string, dataTypeFactory: DataTypeFactory, cache: {
|
|
7
|
+
[key: string]: CacheForFieldResolution;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function populateDataTypeManager104(session: IBasicSession, dataTypeManager: ExtraDataTypeManager): Promise<void>;
|
|
@@ -1,218 +1,218 @@
|
|
|
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.populateDataTypeManager104 = exports.readDataTypeDefinitionAndBuildType = void 0;
|
|
13
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
14
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
15
|
-
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
16
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
17
|
-
const node_opcua_pseudo_session_1 = require("node-opcua-pseudo-session");
|
|
18
|
-
const node_opcua_schemas_1 = require("node-opcua-schemas");
|
|
19
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
20
|
-
const node_opcua_types_1 = require("node-opcua-types");
|
|
21
|
-
const convert_data_type_definition_to_structuretype_schema_1 = require("../convert_data_type_definition_to_structuretype_schema");
|
|
22
|
-
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
23
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
24
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
25
|
-
function readDataTypeDefinitionAndBuildType(session, dataTypeNodeId, name, dataTypeFactory, cache) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
try {
|
|
28
|
-
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const [isAbstractDataValue, dataTypeDefinitionDataValue] = yield session.read([
|
|
32
|
-
{
|
|
33
|
-
attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract,
|
|
34
|
-
nodeId: dataTypeNodeId
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition,
|
|
38
|
-
nodeId: dataTypeNodeId
|
|
39
|
-
}
|
|
40
|
-
]);
|
|
41
|
-
/* istanbul ignore next */
|
|
42
|
-
if (isAbstractDataValue.statusCode.isNotGood()) {
|
|
43
|
-
throw new Error(" Cannot find dataType isAbstract ! with nodeId =" + dataTypeNodeId.toString());
|
|
44
|
-
}
|
|
45
|
-
const isAbstract = isAbstractDataValue.value.value;
|
|
46
|
-
let dataTypeDefinition = dataTypeDefinitionDataValue.value.value;
|
|
47
|
-
/* istanbul ignore next */
|
|
48
|
-
if (dataTypeDefinitionDataValue.statusCode.isNotGood()) {
|
|
49
|
-
// may be we are reading a 1.03 server
|
|
50
|
-
if (!isAbstract) {
|
|
51
|
-
warningLog(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString());
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// it is OK to not have dataTypeDefinition for Abstract type!
|
|
55
|
-
dataTypeDefinition = new node_opcua_types_1.StructureDefinition();
|
|
56
|
-
}
|
|
57
|
-
const schema = yield (0, convert_data_type_definition_to_structuretype_schema_1.convertDataTypeDefinitionToStructureTypeSchema)(session, dataTypeNodeId, name, dataTypeDefinition, dataTypeFactory, isAbstract, cache);
|
|
58
|
-
if (isAbstract) {
|
|
59
|
-
// cannot construct an abstract structure
|
|
60
|
-
dataTypeFactory.registerAbstractStructure(dataTypeNodeId, name, schema);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const Constructor = (0, node_opcua_schemas_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
errorLog("Error", err);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
exports.readDataTypeDefinitionAndBuildType = readDataTypeDefinitionAndBuildType;
|
|
72
|
-
class TaskMan {
|
|
73
|
-
constructor() {
|
|
74
|
-
this.taskList = [];
|
|
75
|
-
this._runningTask = false;
|
|
76
|
-
this._resolve = undefined;
|
|
77
|
-
}
|
|
78
|
-
flushTaskList() {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const firstTask = this.taskList.shift();
|
|
81
|
-
this._runningTask = true;
|
|
82
|
-
yield firstTask();
|
|
83
|
-
this._runningTask = false;
|
|
84
|
-
if (this.taskList.length > 0) {
|
|
85
|
-
setImmediate(() => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
yield this.flushTaskList();
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (this._resolve) {
|
|
91
|
-
const tmpResolve = this._resolve;
|
|
92
|
-
this._resolve = undefined;
|
|
93
|
-
tmpResolve();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
* a little async task queue that gets executed sequentially
|
|
101
|
-
* outside the main loop
|
|
102
|
-
*/
|
|
103
|
-
registerTask(taskFunc) {
|
|
104
|
-
this.taskList.push(taskFunc);
|
|
105
|
-
if (this.taskList.length === 1 && !this._runningTask) {
|
|
106
|
-
this.flushTaskList();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
waitForCompletion() {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
if (this._resolve !== undefined) {
|
|
112
|
-
throw new Error("already waiting");
|
|
113
|
-
}
|
|
114
|
-
yield new Promise((resolve) => {
|
|
115
|
-
this._resolve = resolve;
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function applyOnReferenceRecursively(session, nodeId, browseDescriptionTemplate, action) {
|
|
121
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
const taskMananager = new TaskMan();
|
|
123
|
-
let pendingNodesToBrowse = [];
|
|
124
|
-
function processBrowseResults(nodesToBrowse, browseResults) {
|
|
125
|
-
var _a;
|
|
126
|
-
for (let i = 0; i < browseResults.length; i++) {
|
|
127
|
-
const result = browseResults[i];
|
|
128
|
-
const nodeToBrowse = nodesToBrowse[i];
|
|
129
|
-
if (result.statusCode.equals(node_opcua_status_code_1.StatusCodes.BadNoContinuationPoints) ||
|
|
130
|
-
result.statusCode.equals(node_opcua_status_code_1.StatusCodes.BadContinuationPointInvalid)) {
|
|
131
|
-
// not enough continuation points .. we need to rebrowse
|
|
132
|
-
pendingNodesToBrowse.push(nodeToBrowse);
|
|
133
|
-
// taskMananager.registerTask(flushBrowse);
|
|
134
|
-
}
|
|
135
|
-
else if (result.statusCode.isGood()) {
|
|
136
|
-
for (const r of result.references || []) {
|
|
137
|
-
// also explore sub types
|
|
138
|
-
browseSubDataTypeRecursively(r.nodeId);
|
|
139
|
-
taskMananager.registerTask(() => __awaiter(this, void 0, void 0, function* () { return yield action(r); }));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
errorLog("Unexpected status code", i, (_a = new node_opcua_types_1.BrowseDescription(nodesToBrowse[i] || {})) === null || _a === void 0 ? void 0 : _a.toString(), result.statusCode.toString());
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function flushBrowse() {
|
|
148
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
if (pendingNodesToBrowse.length) {
|
|
150
|
-
const nodesToBrowse = pendingNodesToBrowse;
|
|
151
|
-
pendingNodesToBrowse = [];
|
|
152
|
-
taskMananager.registerTask(() => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
try {
|
|
154
|
-
// YY console.log(" reading ", nodesToBrowse.length);
|
|
155
|
-
const browseResults = yield (0, node_opcua_pseudo_session_1.browseAll)(session, nodesToBrowse);
|
|
156
|
-
processBrowseResults(nodesToBrowse, browseResults);
|
|
157
|
-
}
|
|
158
|
-
catch (err) {
|
|
159
|
-
errorLog("err", err.message);
|
|
160
|
-
errorLog(nodesToBrowse.toString());
|
|
161
|
-
}
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function browseSubDataTypeRecursively(nodeId) {
|
|
167
|
-
const nodeToBrowse = Object.assign(Object.assign({}, browseDescriptionTemplate), { nodeId });
|
|
168
|
-
pendingNodesToBrowse.push(nodeToBrowse);
|
|
169
|
-
taskMananager.registerTask(() => __awaiter(this, void 0, void 0, function* () { return flushBrowse(); }));
|
|
170
|
-
}
|
|
171
|
-
browseSubDataTypeRecursively(nodeId);
|
|
172
|
-
yield taskMananager.waitForCompletion();
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function populateDataTypeManager104(session, dataTypeManager) {
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
const cache = {};
|
|
178
|
-
function withDataType(r) {
|
|
179
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
const dataTypeNodeId = r.nodeId;
|
|
181
|
-
try {
|
|
182
|
-
if (dataTypeNodeId.namespace === 0) {
|
|
183
|
-
// already known I guess
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
let dataTypeFactory = dataTypeManager.getDataTypeFactory(dataTypeNodeId.namespace);
|
|
187
|
-
if (!dataTypeFactory) {
|
|
188
|
-
dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([]);
|
|
189
|
-
dataTypeManager.registerDataTypeFactory(dataTypeNodeId.namespace, dataTypeFactory);
|
|
190
|
-
// throw new Error("cannot find dataType Manager for namespace of " + dataTypeNodeId.toString());
|
|
191
|
-
}
|
|
192
|
-
// if not found already
|
|
193
|
-
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
194
|
-
// already known !
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
// extract it formally
|
|
198
|
-
debugLog(" DataType => ", r.browseName.toString(), dataTypeNodeId.toString());
|
|
199
|
-
yield readDataTypeDefinitionAndBuildType(session, dataTypeNodeId, r.browseName.name, dataTypeFactory, cache);
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
errorLog("err=", err);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const nodeToBrowse = {
|
|
207
|
-
nodeId: node_opcua_nodeid_1.NodeId.nullNodeId,
|
|
208
|
-
includeSubtypes: true,
|
|
209
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
210
|
-
nodeClassMask: 0xff,
|
|
211
|
-
referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
|
|
212
|
-
resultMask: 0xff
|
|
213
|
-
};
|
|
214
|
-
yield applyOnReferenceRecursively(session, (0, node_opcua_nodeid_1.resolveNodeId)("Structure"), nodeToBrowse, withDataType);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
exports.populateDataTypeManager104 = populateDataTypeManager104;
|
|
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.populateDataTypeManager104 = exports.readDataTypeDefinitionAndBuildType = void 0;
|
|
13
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
14
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
15
|
+
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
16
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
17
|
+
const node_opcua_pseudo_session_1 = require("node-opcua-pseudo-session");
|
|
18
|
+
const node_opcua_schemas_1 = require("node-opcua-schemas");
|
|
19
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
20
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
21
|
+
const convert_data_type_definition_to_structuretype_schema_1 = require("../convert_data_type_definition_to_structuretype_schema");
|
|
22
|
+
const errorLog = (0, node_opcua_debug_1.make_errorLog)(__filename);
|
|
23
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
24
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
25
|
+
function readDataTypeDefinitionAndBuildType(session, dataTypeNodeId, name, dataTypeFactory, cache) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const [isAbstractDataValue, dataTypeDefinitionDataValue] = yield session.read([
|
|
32
|
+
{
|
|
33
|
+
attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract,
|
|
34
|
+
nodeId: dataTypeNodeId
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition,
|
|
38
|
+
nodeId: dataTypeNodeId
|
|
39
|
+
}
|
|
40
|
+
]);
|
|
41
|
+
/* istanbul ignore next */
|
|
42
|
+
if (isAbstractDataValue.statusCode.isNotGood()) {
|
|
43
|
+
throw new Error(" Cannot find dataType isAbstract ! with nodeId =" + dataTypeNodeId.toString());
|
|
44
|
+
}
|
|
45
|
+
const isAbstract = isAbstractDataValue.value.value;
|
|
46
|
+
let dataTypeDefinition = dataTypeDefinitionDataValue.value.value;
|
|
47
|
+
/* istanbul ignore next */
|
|
48
|
+
if (dataTypeDefinitionDataValue.statusCode.isNotGood()) {
|
|
49
|
+
// may be we are reading a 1.03 server
|
|
50
|
+
if (!isAbstract) {
|
|
51
|
+
warningLog(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString());
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// it is OK to not have dataTypeDefinition for Abstract type!
|
|
55
|
+
dataTypeDefinition = new node_opcua_types_1.StructureDefinition();
|
|
56
|
+
}
|
|
57
|
+
const schema = yield (0, convert_data_type_definition_to_structuretype_schema_1.convertDataTypeDefinitionToStructureTypeSchema)(session, dataTypeNodeId, name, dataTypeDefinition, dataTypeFactory, isAbstract, cache);
|
|
58
|
+
if (isAbstract) {
|
|
59
|
+
// cannot construct an abstract structure
|
|
60
|
+
dataTypeFactory.registerAbstractStructure(dataTypeNodeId, name, schema);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const Constructor = (0, node_opcua_schemas_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
errorLog("Error", err);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.readDataTypeDefinitionAndBuildType = readDataTypeDefinitionAndBuildType;
|
|
72
|
+
class TaskMan {
|
|
73
|
+
constructor() {
|
|
74
|
+
this.taskList = [];
|
|
75
|
+
this._runningTask = false;
|
|
76
|
+
this._resolve = undefined;
|
|
77
|
+
}
|
|
78
|
+
flushTaskList() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const firstTask = this.taskList.shift();
|
|
81
|
+
this._runningTask = true;
|
|
82
|
+
yield firstTask();
|
|
83
|
+
this._runningTask = false;
|
|
84
|
+
if (this.taskList.length > 0) {
|
|
85
|
+
setImmediate(() => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield this.flushTaskList();
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
if (this._resolve) {
|
|
91
|
+
const tmpResolve = this._resolve;
|
|
92
|
+
this._resolve = undefined;
|
|
93
|
+
tmpResolve();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* a little async task queue that gets executed sequentially
|
|
101
|
+
* outside the main loop
|
|
102
|
+
*/
|
|
103
|
+
registerTask(taskFunc) {
|
|
104
|
+
this.taskList.push(taskFunc);
|
|
105
|
+
if (this.taskList.length === 1 && !this._runningTask) {
|
|
106
|
+
this.flushTaskList();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
waitForCompletion() {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
if (this._resolve !== undefined) {
|
|
112
|
+
throw new Error("already waiting");
|
|
113
|
+
}
|
|
114
|
+
yield new Promise((resolve) => {
|
|
115
|
+
this._resolve = resolve;
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function applyOnReferenceRecursively(session, nodeId, browseDescriptionTemplate, action) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const taskMananager = new TaskMan();
|
|
123
|
+
let pendingNodesToBrowse = [];
|
|
124
|
+
function processBrowseResults(nodesToBrowse, browseResults) {
|
|
125
|
+
var _a;
|
|
126
|
+
for (let i = 0; i < browseResults.length; i++) {
|
|
127
|
+
const result = browseResults[i];
|
|
128
|
+
const nodeToBrowse = nodesToBrowse[i];
|
|
129
|
+
if (result.statusCode.equals(node_opcua_status_code_1.StatusCodes.BadNoContinuationPoints) ||
|
|
130
|
+
result.statusCode.equals(node_opcua_status_code_1.StatusCodes.BadContinuationPointInvalid)) {
|
|
131
|
+
// not enough continuation points .. we need to rebrowse
|
|
132
|
+
pendingNodesToBrowse.push(nodeToBrowse);
|
|
133
|
+
// taskMananager.registerTask(flushBrowse);
|
|
134
|
+
}
|
|
135
|
+
else if (result.statusCode.isGood()) {
|
|
136
|
+
for (const r of result.references || []) {
|
|
137
|
+
// also explore sub types
|
|
138
|
+
browseSubDataTypeRecursively(r.nodeId);
|
|
139
|
+
taskMananager.registerTask(() => __awaiter(this, void 0, void 0, function* () { return yield action(r); }));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
errorLog("Unexpected status code", i, (_a = new node_opcua_types_1.BrowseDescription(nodesToBrowse[i] || {})) === null || _a === void 0 ? void 0 : _a.toString(), result.statusCode.toString());
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function flushBrowse() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
if (pendingNodesToBrowse.length) {
|
|
150
|
+
const nodesToBrowse = pendingNodesToBrowse;
|
|
151
|
+
pendingNodesToBrowse = [];
|
|
152
|
+
taskMananager.registerTask(() => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
try {
|
|
154
|
+
// YY console.log(" reading ", nodesToBrowse.length);
|
|
155
|
+
const browseResults = yield (0, node_opcua_pseudo_session_1.browseAll)(session, nodesToBrowse);
|
|
156
|
+
processBrowseResults(nodesToBrowse, browseResults);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
errorLog("err", err.message);
|
|
160
|
+
errorLog(nodesToBrowse.toString());
|
|
161
|
+
}
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function browseSubDataTypeRecursively(nodeId) {
|
|
167
|
+
const nodeToBrowse = Object.assign(Object.assign({}, browseDescriptionTemplate), { nodeId });
|
|
168
|
+
pendingNodesToBrowse.push(nodeToBrowse);
|
|
169
|
+
taskMananager.registerTask(() => __awaiter(this, void 0, void 0, function* () { return flushBrowse(); }));
|
|
170
|
+
}
|
|
171
|
+
browseSubDataTypeRecursively(nodeId);
|
|
172
|
+
yield taskMananager.waitForCompletion();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function populateDataTypeManager104(session, dataTypeManager) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
const cache = {};
|
|
178
|
+
function withDataType(r) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
const dataTypeNodeId = r.nodeId;
|
|
181
|
+
try {
|
|
182
|
+
if (dataTypeNodeId.namespace === 0) {
|
|
183
|
+
// already known I guess
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
let dataTypeFactory = dataTypeManager.getDataTypeFactory(dataTypeNodeId.namespace);
|
|
187
|
+
if (!dataTypeFactory) {
|
|
188
|
+
dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([]);
|
|
189
|
+
dataTypeManager.registerDataTypeFactory(dataTypeNodeId.namespace, dataTypeFactory);
|
|
190
|
+
// throw new Error("cannot find dataType Manager for namespace of " + dataTypeNodeId.toString());
|
|
191
|
+
}
|
|
192
|
+
// if not found already
|
|
193
|
+
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
|
|
194
|
+
// already known !
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// extract it formally
|
|
198
|
+
debugLog(" DataType => ", r.browseName.toString(), dataTypeNodeId.toString());
|
|
199
|
+
yield readDataTypeDefinitionAndBuildType(session, dataTypeNodeId, r.browseName.name, dataTypeFactory, cache);
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
errorLog("err=", err);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const nodeToBrowse = {
|
|
207
|
+
nodeId: node_opcua_nodeid_1.NodeId.nullNodeId,
|
|
208
|
+
includeSubtypes: true,
|
|
209
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
210
|
+
nodeClassMask: 0xff,
|
|
211
|
+
referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
|
|
212
|
+
resultMask: 0xff
|
|
213
|
+
};
|
|
214
|
+
yield applyOnReferenceRecursively(session, (0, node_opcua_nodeid_1.resolveNodeId)("Structure"), nodeToBrowse, withDataType);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
exports.populateDataTypeManager104 = populateDataTypeManager104;
|
|
218
218
|
//# sourceMappingURL=populate_data_type_manager_104.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
2
|
-
import { Variant } from "node-opcua-variant";
|
|
3
|
-
export interface PseudoDataValue {
|
|
4
|
-
value: Variant;
|
|
5
|
-
}
|
|
6
|
-
export declare function extractDataValueToPromote(dataValues: PseudoDataValue[]): PseudoDataValue[];
|
|
7
|
-
export declare function promoteOpaqueStructure(session: IBasicSession, dataValues: PseudoDataValue[]): Promise<void>;
|
|
1
|
+
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
2
|
+
import { Variant } from "node-opcua-variant";
|
|
3
|
+
export interface PseudoDataValue {
|
|
4
|
+
value: Variant;
|
|
5
|
+
}
|
|
6
|
+
export declare function extractDataValueToPromote(dataValues: PseudoDataValue[]): PseudoDataValue[];
|
|
7
|
+
export declare function promoteOpaqueStructure(session: IBasicSession, dataValues: PseudoDataValue[]): Promise<void>;
|
|
@@ -1,47 +1,47 @@
|
|
|
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.promoteOpaqueStructure = exports.extractDataValueToPromote = void 0;
|
|
13
|
-
const node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
14
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
15
|
-
//
|
|
16
|
-
const get_extra_data_type_manager_1 = require("./get_extra_data_type_manager");
|
|
17
|
-
const resolve_dynamic_extension_object_1 = require("./resolve_dynamic_extension_object");
|
|
18
|
-
;
|
|
19
|
-
function extractDataValueToPromote(dataValues) {
|
|
20
|
-
// count number of Opaque Structures
|
|
21
|
-
const dataValuesToFix = dataValues.filter((dataValue) => dataValue.value && dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject &&
|
|
22
|
-
((dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar
|
|
23
|
-
&& dataValue.value.value instanceof node_opcua_extension_object_1.OpaqueStructure)
|
|
24
|
-
||
|
|
25
|
-
(dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Scalar
|
|
26
|
-
&& dataValue.value.value && dataValue.value.value.length >= 0
|
|
27
|
-
&& dataValue.value.value[0] instanceof node_opcua_extension_object_1.OpaqueStructure)));
|
|
28
|
-
return dataValuesToFix;
|
|
29
|
-
}
|
|
30
|
-
exports.extractDataValueToPromote = extractDataValueToPromote;
|
|
31
|
-
function promoteOpaqueStructure(session, dataValues) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const dataValuesToFix = extractDataValueToPromote(dataValues);
|
|
34
|
-
if (dataValuesToFix.length === 0) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// construct dataTypeManager if not already present
|
|
38
|
-
const extraDataTypeManager = yield (0, get_extra_data_type_manager_1.getExtraDataTypeManager)(session);
|
|
39
|
-
const promises = dataValuesToFix.map((dataValue) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
return yield (0, resolve_dynamic_extension_object_1.resolveDynamicExtensionObject)(session, dataValue.value, extraDataTypeManager);
|
|
41
|
-
}));
|
|
42
|
-
// https://medium.com/swlh/dealing-with-multiple-promises-in-javascript-41d6c21f20ff
|
|
43
|
-
yield Promise.all(promises.map(p => p.catch(e => e)));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
exports.promoteOpaqueStructure = promoteOpaqueStructure;
|
|
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.promoteOpaqueStructure = exports.extractDataValueToPromote = void 0;
|
|
13
|
+
const node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
14
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
15
|
+
//
|
|
16
|
+
const get_extra_data_type_manager_1 = require("./get_extra_data_type_manager");
|
|
17
|
+
const resolve_dynamic_extension_object_1 = require("./resolve_dynamic_extension_object");
|
|
18
|
+
;
|
|
19
|
+
function extractDataValueToPromote(dataValues) {
|
|
20
|
+
// count number of Opaque Structures
|
|
21
|
+
const dataValuesToFix = dataValues.filter((dataValue) => dataValue.value && dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject &&
|
|
22
|
+
((dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar
|
|
23
|
+
&& dataValue.value.value instanceof node_opcua_extension_object_1.OpaqueStructure)
|
|
24
|
+
||
|
|
25
|
+
(dataValue.value.arrayType !== node_opcua_variant_1.VariantArrayType.Scalar
|
|
26
|
+
&& dataValue.value.value && dataValue.value.value.length >= 0
|
|
27
|
+
&& dataValue.value.value[0] instanceof node_opcua_extension_object_1.OpaqueStructure)));
|
|
28
|
+
return dataValuesToFix;
|
|
29
|
+
}
|
|
30
|
+
exports.extractDataValueToPromote = extractDataValueToPromote;
|
|
31
|
+
function promoteOpaqueStructure(session, dataValues) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const dataValuesToFix = extractDataValueToPromote(dataValues);
|
|
34
|
+
if (dataValuesToFix.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// construct dataTypeManager if not already present
|
|
38
|
+
const extraDataTypeManager = yield (0, get_extra_data_type_manager_1.getExtraDataTypeManager)(session);
|
|
39
|
+
const promises = dataValuesToFix.map((dataValue) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return yield (0, resolve_dynamic_extension_object_1.resolveDynamicExtensionObject)(session, dataValue.value, extraDataTypeManager);
|
|
41
|
+
}));
|
|
42
|
+
// https://medium.com/swlh/dealing-with-multiple-promises-in-javascript-41d6c21f20ff
|
|
43
|
+
yield Promise.all(promises.map(p => p.catch(e => e)));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.promoteOpaqueStructure = promoteOpaqueStructure;
|
|
47
47
|
//# sourceMappingURL=promote_opaque_structure.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NotificationData } from "node-opcua-types";
|
|
2
|
-
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
3
|
-
export declare function promoteOpaqueStructureInNotificationData(session: IBasicSession, notificationData: NotificationData[]): Promise<void>;
|
|
1
|
+
import { NotificationData } from "node-opcua-types";
|
|
2
|
+
import { IBasicSession } from "node-opcua-pseudo-session";
|
|
3
|
+
export declare function promoteOpaqueStructureInNotificationData(session: IBasicSession, notificationData: NotificationData[]): Promise<void>;
|