node-opcua-factory 2.76.0 → 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.
- package/dist/base_ua_object.d.ts +53 -53
- package/dist/base_ua_object.js +535 -535
- package/dist/basic_type.d.ts +40 -40
- package/dist/basic_type.js +118 -118
- package/dist/builtin_types.d.ts +46 -46
- package/dist/builtin_types.js +283 -283
- package/dist/builtin_types_special.d.ts +5 -5
- package/dist/builtin_types_special.js +45 -45
- package/dist/constructor_type.d.ts +15 -0
- package/dist/constructor_type.js +3 -0
- package/dist/constructor_type.js.map +1 -0
- package/dist/datatype_factory.d.ts +36 -36
- package/dist/datatype_factory.js +307 -307
- package/dist/encode_decode.d.ts +9 -9
- package/dist/encode_decode.js +39 -39
- package/dist/enumerations.d.ts +32 -32
- package/dist/enumerations.js +77 -77
- package/dist/factories_baseobject.d.ts +56 -0
- package/dist/factories_baseobject.js +535 -0
- package/dist/factories_baseobject.js.map +1 -0
- package/dist/factories_basic_type.d.ts +40 -0
- package/dist/factories_basic_type.js +136 -0
- package/dist/factories_basic_type.js.map +1 -0
- package/dist/factories_builtin_types.d.ts +32 -0
- package/dist/factories_builtin_types.js +262 -0
- package/dist/factories_builtin_types.js.map +1 -0
- package/dist/factories_builtin_types_special.d.ts +5 -0
- package/dist/factories_builtin_types_special.js +46 -0
- package/dist/factories_builtin_types_special.js.map +1 -0
- package/dist/factories_enumerations.d.ts +31 -0
- package/dist/factories_enumerations.js +78 -0
- package/dist/factories_enumerations.js.map +1 -0
- package/dist/factories_factories.d.ts +17 -0
- package/dist/factories_factories.js +54 -0
- package/dist/factories_factories.js.map +1 -0
- package/dist/factories_id_generator.d.ts +3 -0
- package/dist/factories_id_generator.js +22 -0
- package/dist/factories_id_generator.js.map +1 -0
- package/dist/factories_schema_helpers.d.ts +27 -0
- package/dist/factories_schema_helpers.js +122 -0
- package/dist/factories_schema_helpers.js.map +1 -0
- package/dist/factories_structuredTypeSchema.d.ts +45 -0
- package/dist/factories_structuredTypeSchema.js +277 -0
- package/dist/factories_structuredTypeSchema.js.map +1 -0
- package/dist/get_built_in_type.js +1 -1
- package/dist/get_standard_data_type_factory.d.ts +12 -12
- package/dist/get_standard_data_type_factory.js +34 -34
- package/dist/get_structured_type_schema.d.ts +4 -4
- package/dist/get_structured_type_schema.js +12 -12
- package/dist/id_generator.d.ts +3 -3
- package/dist/id_generator.js +21 -21
- package/dist/index.d.ts +18 -18
- package/dist/index.js +34 -34
- package/dist/nodeid_type.d.ts +13 -13
- package/dist/nodeid_type.js +18 -18
- package/dist/parameters.d.ts +3 -3
- package/dist/parameters.js +6 -6
- package/dist/register_class_definition.d.ts +3 -3
- package/dist/register_class_definition.js +8 -8
- package/dist/schema_helpers.d.ts +24 -24
- package/dist/schema_helpers.js +99 -99
- package/dist/structured_type_schema.d.ts +44 -44
- package/dist/structured_type_schema.js +278 -278
- package/dist/types.d.ts +151 -151
- package/dist/types.js +9 -9
- package/package.json +9 -9
package/dist/datatype_factory.js
CHANGED
|
@@ -1,308 +1,308 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataTypeFactory = exports._findFieldSchema = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-factory
|
|
6
|
-
*/
|
|
7
|
-
const util = require("util");
|
|
8
|
-
const chalk = require("chalk");
|
|
9
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
10
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
11
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
12
|
-
const builtin_types_1 = require("./builtin_types");
|
|
13
|
-
const enumerations_1 = require("./enumerations");
|
|
14
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
15
|
-
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
16
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
17
|
-
function _findFieldSchema(typeDictionary, field, value) {
|
|
18
|
-
const fieldType = field.fieldType;
|
|
19
|
-
if (field.allowSubType && field.category === "complex") {
|
|
20
|
-
const fieldTypeConstructor = value ? value.constructor : field.fieldTypeConstructor;
|
|
21
|
-
const _newFieldSchema = fieldTypeConstructor.schema;
|
|
22
|
-
return _newFieldSchema;
|
|
23
|
-
}
|
|
24
|
-
const fieldTypeConstructor = field.fieldTypeConstructor || typeDictionary.getStructureTypeConstructor(fieldType);
|
|
25
|
-
return field.schema || fieldTypeConstructor.schema;
|
|
26
|
-
}
|
|
27
|
-
exports._findFieldSchema = _findFieldSchema;
|
|
28
|
-
class DataTypeFactory {
|
|
29
|
-
constructor(baseDataFactories) {
|
|
30
|
-
this.imports = [];
|
|
31
|
-
this._structureTypeConstructorByNameMap = new Map();
|
|
32
|
-
this._structureTypeConstructorByDataTypeMap = new Map();
|
|
33
|
-
this._structureTypeConstructorByEncodingNodeIdMap = new Map();
|
|
34
|
-
this._enumerations = new Map();
|
|
35
|
-
this.defaultByteOrder = "LittleEndian";
|
|
36
|
-
this.targetNamespace = "";
|
|
37
|
-
this.baseDataFactories = baseDataFactories;
|
|
38
|
-
}
|
|
39
|
-
repairBaseDataFactories(baseDataFactories) {
|
|
40
|
-
this.baseDataFactories = baseDataFactories;
|
|
41
|
-
}
|
|
42
|
-
hasBuiltInType(name) {
|
|
43
|
-
return (0, builtin_types_1.hasBuiltInType)(name);
|
|
44
|
-
}
|
|
45
|
-
getBuiltInType(name) {
|
|
46
|
-
return (0, builtin_types_1.getBuiltInType)(name);
|
|
47
|
-
}
|
|
48
|
-
getBuiltInTypeByDataType(nodeId) {
|
|
49
|
-
return (0, builtin_types_1.getBuiltInType)(node_opcua_constants_1.DataTypeIds[nodeId.value]);
|
|
50
|
-
}
|
|
51
|
-
// -----------------------------
|
|
52
|
-
// EnumerationDefinitionSchema
|
|
53
|
-
registerEnumeration(enumeration) {
|
|
54
|
-
(0, node_opcua_assert_1.assert)(!this._enumerations.has(enumeration.name), "enumeration already registered");
|
|
55
|
-
this._enumerations.set(enumeration.name, enumeration);
|
|
56
|
-
}
|
|
57
|
-
hasEnumeration(enumName) {
|
|
58
|
-
if (this._enumerations.has(enumName)) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
for (const factory of this.baseDataFactories) {
|
|
62
|
-
const e = factory.hasEnumeration(enumName);
|
|
63
|
-
if (e) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if ((0, enumerations_1.hasBuiltInEnumeration)(enumName)) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
getEnumeration(enumName) {
|
|
73
|
-
if (this._enumerations.has(enumName)) {
|
|
74
|
-
return this._enumerations.get(enumName) || null;
|
|
75
|
-
}
|
|
76
|
-
for (const factory of this.baseDataFactories) {
|
|
77
|
-
const hasEnum = factory.hasEnumeration(enumName);
|
|
78
|
-
if (hasEnum) {
|
|
79
|
-
const e = factory.getEnumeration(enumName);
|
|
80
|
-
return e;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const ee = (0, enumerations_1.getBuiltInEnumeration)(enumName);
|
|
84
|
-
return ee;
|
|
85
|
-
}
|
|
86
|
-
// ----------------------------
|
|
87
|
-
findConstructorForDataType(dataTypeNodeId) {
|
|
88
|
-
const constructor = this.getConstructorForDataType(dataTypeNodeId);
|
|
89
|
-
if (constructor) {
|
|
90
|
-
return constructor;
|
|
91
|
-
}
|
|
92
|
-
this.getConstructorForDataType(dataTypeNodeId);
|
|
93
|
-
throw new Error("Cannot find StructureType constructor for dataType " + dataTypeNodeId.toString());
|
|
94
|
-
}
|
|
95
|
-
getConstructorForDataType(dataTypeNodeId) {
|
|
96
|
-
const constructor = this._structureTypeConstructorByDataTypeMap.get(dataTypeNodeId.toString());
|
|
97
|
-
if (constructor) {
|
|
98
|
-
return constructor;
|
|
99
|
-
}
|
|
100
|
-
for (const factory of this.baseDataFactories) {
|
|
101
|
-
const constructor2 = factory.getConstructorForDataType(dataTypeNodeId);
|
|
102
|
-
if (constructor2) {
|
|
103
|
-
return constructor2;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
// ----------------------------------------------------------------------------------------------------
|
|
109
|
-
// Access by typeName
|
|
110
|
-
// ----------------------------------------------------------------------------------------------------
|
|
111
|
-
structuredTypesNames() {
|
|
112
|
-
return this._structureTypeConstructorByNameMap.keys();
|
|
113
|
-
}
|
|
114
|
-
getStructureTypeConstructor(typeName) {
|
|
115
|
-
const constructor = this._structureTypeConstructorByNameMap.get(typeName);
|
|
116
|
-
if (constructor) {
|
|
117
|
-
return constructor;
|
|
118
|
-
}
|
|
119
|
-
for (const factory of this.baseDataFactories) {
|
|
120
|
-
if (!factory.hasStructuredType(typeName)) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const constructor2 = factory.getStructureTypeConstructor(typeName);
|
|
124
|
-
if (constructor2) {
|
|
125
|
-
return constructor2;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// istanbul ignore next
|
|
129
|
-
if (doDebug) {
|
|
130
|
-
console.log([...this.structuredTypesNames()].join(" "));
|
|
131
|
-
}
|
|
132
|
-
// istanbul ignore next
|
|
133
|
-
throw new Error("Cannot find StructureType constructor for " + typeName + " - it may be abstract, or it could be a basic type");
|
|
134
|
-
}
|
|
135
|
-
hasStructuredType(typeName) {
|
|
136
|
-
if (this._structureTypeConstructorByNameMap.has(typeName)) {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
for (const factory of this.baseDataFactories) {
|
|
140
|
-
if (factory.hasStructuredType(typeName)) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
getStructuredTypeSchema(typeName) {
|
|
147
|
-
const constructor = this.getStructureTypeConstructor(typeName);
|
|
148
|
-
return constructor.schema;
|
|
149
|
-
}
|
|
150
|
-
// istanbul ignore next
|
|
151
|
-
dump() {
|
|
152
|
-
console.log(" dumping registered factories");
|
|
153
|
-
console.log(" Factory ", [...this.structuredTypesNames()].sort().forEach((e) => e));
|
|
154
|
-
console.log(" done");
|
|
155
|
-
}
|
|
156
|
-
registerClassDefinition(dataTypeNodeId, className, classConstructor) {
|
|
157
|
-
this._registerFactory(dataTypeNodeId, className, classConstructor);
|
|
158
|
-
if (classConstructor.encodingDefaultBinary && classConstructor.encodingDefaultBinary.value !== 0) {
|
|
159
|
-
this.associateWithBinaryEncoding(className, classConstructor.encodingDefaultBinary);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
// for instance in DI FetchResultDataType should be abstract but is not
|
|
163
|
-
debugLog("warning ", dataTypeNodeId.toString(), "name=", className, " do not have binary encoding");
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// ----------------------------------------------------------------------------------------------------
|
|
167
|
-
// Access by binaryEncodingNodeId
|
|
168
|
-
// ----------------------------------------------------------------------------------------------------
|
|
169
|
-
getConstructor(binaryEncodingNodeId) {
|
|
170
|
-
const expandedNodeIdKey = makeExpandedNodeIdKey(binaryEncodingNodeId);
|
|
171
|
-
const constructor = this._structureTypeConstructorByEncodingNodeIdMap.get(expandedNodeIdKey);
|
|
172
|
-
if (constructor) {
|
|
173
|
-
return constructor;
|
|
174
|
-
}
|
|
175
|
-
for (const factory of this.baseDataFactories) {
|
|
176
|
-
const constructor2 = factory.getConstructor(binaryEncodingNodeId);
|
|
177
|
-
if (constructor2) {
|
|
178
|
-
return constructor2;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
debugLog(chalk.red("#getConstructor : cannot find constructor for expandedId "), binaryEncodingNodeId.toString());
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
hasConstructor(binaryEncodingNodeId) {
|
|
185
|
-
if (!binaryEncodingNodeId) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
/* istanbul ignore next */
|
|
189
|
-
if (!verifyExpandedNodeId(binaryEncodingNodeId)) {
|
|
190
|
-
console.log("Invalid expandedNodeId");
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
const expandedNodeIdKey = makeExpandedNodeIdKey(binaryEncodingNodeId);
|
|
194
|
-
const constructor = this._structureTypeConstructorByEncodingNodeIdMap.get(expandedNodeIdKey);
|
|
195
|
-
if (constructor) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
for (const factory of this.baseDataFactories) {
|
|
199
|
-
const constructor2 = factory.getConstructor(binaryEncodingNodeId);
|
|
200
|
-
if (constructor2) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
constructObject(binaryEncodingNodeId) {
|
|
207
|
-
if (!verifyExpandedNodeId(binaryEncodingNodeId)) {
|
|
208
|
-
throw new Error(" constructObject : invalid expandedNodeId provided " + binaryEncodingNodeId.toString());
|
|
209
|
-
}
|
|
210
|
-
const constructor = this.getConstructor(binaryEncodingNodeId);
|
|
211
|
-
if (!constructor) {
|
|
212
|
-
debugLog("Cannot find constructor for " + binaryEncodingNodeId.toString());
|
|
213
|
-
throw new Error("Cannot find constructor for " + binaryEncodingNodeId.toString());
|
|
214
|
-
}
|
|
215
|
-
return new constructor();
|
|
216
|
-
}
|
|
217
|
-
associateWithBinaryEncoding(className, expandedNodeId) {
|
|
218
|
-
const classConstructor = this.getStructureTypeConstructor(className);
|
|
219
|
-
if (doDebug) {
|
|
220
|
-
debugLog(" associateWithBinaryEncoding ", className, expandedNodeId.toString());
|
|
221
|
-
}
|
|
222
|
-
/* istanbul ignore next */
|
|
223
|
-
if (!verifyExpandedNodeId(expandedNodeId)) {
|
|
224
|
-
throw new Error("Invalid expandedNodeId " + expandedNodeId.toString() + " className = " + className);
|
|
225
|
-
}
|
|
226
|
-
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
|
|
227
|
-
/* istanbul ignore next */
|
|
228
|
-
if (this._structureTypeConstructorByEncodingNodeIdMap.has(expandedNodeIdKey)) {
|
|
229
|
-
throw new Error(" Class " +
|
|
230
|
-
className +
|
|
231
|
-
" with ID " +
|
|
232
|
-
expandedNodeId +
|
|
233
|
-
" already in constructorMap for " +
|
|
234
|
-
this._structureTypeConstructorByEncodingNodeIdMap.get(expandedNodeIdKey).name);
|
|
235
|
-
}
|
|
236
|
-
this._structureTypeConstructorByEncodingNodeIdMap.set(expandedNodeIdKey, classConstructor);
|
|
237
|
-
}
|
|
238
|
-
toString() {
|
|
239
|
-
const l = [];
|
|
240
|
-
function write(...args) {
|
|
241
|
-
l.push(util.format.apply(util.format, args));
|
|
242
|
-
}
|
|
243
|
-
dumpDataFactory(this, write);
|
|
244
|
-
return l.join("\n");
|
|
245
|
-
}
|
|
246
|
-
_registerFactory(dataTypeNodeId, typeName, constructor) {
|
|
247
|
-
/* istanbul ignore next */
|
|
248
|
-
if (this._structureTypeConstructorByNameMap.has(typeName)) {
|
|
249
|
-
warningLog(this.getStructureTypeConstructor(typeName));
|
|
250
|
-
warningLog("target namespace = `" + this.targetNamespace + "`");
|
|
251
|
-
warningLog(" registerFactory : " + typeName + " already registered. dataTypeNodeId=", dataTypeNodeId.toString());
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
debugLog("registering typeName ", typeName, dataTypeNodeId.toString());
|
|
255
|
-
this._structureTypeConstructorByNameMap.set(typeName, constructor);
|
|
256
|
-
if (dataTypeNodeId.value !== 0) {
|
|
257
|
-
this._structureTypeConstructorByDataTypeMap.set(dataTypeNodeId.toString(), constructor);
|
|
258
|
-
}
|
|
259
|
-
Object.defineProperty(constructor.schema, "$$factory", {
|
|
260
|
-
enumerable: false,
|
|
261
|
-
value: this,
|
|
262
|
-
writable: false
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
exports.DataTypeFactory = DataTypeFactory;
|
|
267
|
-
function dumpSchema(schema, write) {
|
|
268
|
-
write("name ", schema.name);
|
|
269
|
-
write("dataType ", schema.dataTypeNodeId.toString());
|
|
270
|
-
write("binaryEncoding ", schema.encodingDefaultBinary.toString());
|
|
271
|
-
for (const f of schema.fields) {
|
|
272
|
-
write(" ", f.name.padEnd(30, " "), f.isArray ? true : false, f.fieldType);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function dumpDataFactory(dataFactory, write) {
|
|
276
|
-
for (const structureTypeName of dataFactory.structuredTypesNames()) {
|
|
277
|
-
const schema = dataFactory.getStructuredTypeSchema(structureTypeName);
|
|
278
|
-
write("structureTypeName =", structureTypeName);
|
|
279
|
-
if (!dataFactory.getConstructorForDataType(schema.dataTypeNodeId)) {
|
|
280
|
-
write(" ( No constructor for " + schema.name + " " + schema.dataTypeNodeId.toString());
|
|
281
|
-
}
|
|
282
|
-
if (!schema.encodingDefaultBinary) {
|
|
283
|
-
write(" (Schema has no encoding defaultBinary )");
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
if (dataFactory.hasConstructor(schema.encodingDefaultBinary)) {
|
|
287
|
-
console.log("schema", schema.name);
|
|
288
|
-
console.log("schema", schema.dataTypeNodeId.toString());
|
|
289
|
-
console.log("schema", schema.encodingDefaultBinary ? schema.encodingDefaultBinary.toString() : " ");
|
|
290
|
-
console.log("schema", schema.encodingDefaultXml ? schema.encodingDefaultXml.toString() : " ");
|
|
291
|
-
// return;
|
|
292
|
-
// throw new Error("Not in Binary Encoding Map!!!!! " + schema.encodingDefaultBinary);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
dumpSchema(schema, write);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
function verifyExpandedNodeId(expandedNodeId) {
|
|
299
|
-
/* istanbul ignore next */
|
|
300
|
-
if (expandedNodeId.value instanceof Buffer) {
|
|
301
|
-
throw new Error("getConstructor not implemented for opaque nodeid");
|
|
302
|
-
}
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
function makeExpandedNodeIdKey(expandedNodeId) {
|
|
306
|
-
return expandedNodeId.toString();
|
|
307
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataTypeFactory = exports._findFieldSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-factory
|
|
6
|
+
*/
|
|
7
|
+
const util = require("util");
|
|
8
|
+
const chalk = require("chalk");
|
|
9
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
10
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
11
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
12
|
+
const builtin_types_1 = require("./builtin_types");
|
|
13
|
+
const enumerations_1 = require("./enumerations");
|
|
14
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
15
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
16
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
17
|
+
function _findFieldSchema(typeDictionary, field, value) {
|
|
18
|
+
const fieldType = field.fieldType;
|
|
19
|
+
if (field.allowSubType && field.category === "complex") {
|
|
20
|
+
const fieldTypeConstructor = value ? value.constructor : field.fieldTypeConstructor;
|
|
21
|
+
const _newFieldSchema = fieldTypeConstructor.schema;
|
|
22
|
+
return _newFieldSchema;
|
|
23
|
+
}
|
|
24
|
+
const fieldTypeConstructor = field.fieldTypeConstructor || typeDictionary.getStructureTypeConstructor(fieldType);
|
|
25
|
+
return field.schema || fieldTypeConstructor.schema;
|
|
26
|
+
}
|
|
27
|
+
exports._findFieldSchema = _findFieldSchema;
|
|
28
|
+
class DataTypeFactory {
|
|
29
|
+
constructor(baseDataFactories) {
|
|
30
|
+
this.imports = [];
|
|
31
|
+
this._structureTypeConstructorByNameMap = new Map();
|
|
32
|
+
this._structureTypeConstructorByDataTypeMap = new Map();
|
|
33
|
+
this._structureTypeConstructorByEncodingNodeIdMap = new Map();
|
|
34
|
+
this._enumerations = new Map();
|
|
35
|
+
this.defaultByteOrder = "LittleEndian";
|
|
36
|
+
this.targetNamespace = "";
|
|
37
|
+
this.baseDataFactories = baseDataFactories;
|
|
38
|
+
}
|
|
39
|
+
repairBaseDataFactories(baseDataFactories) {
|
|
40
|
+
this.baseDataFactories = baseDataFactories;
|
|
41
|
+
}
|
|
42
|
+
hasBuiltInType(name) {
|
|
43
|
+
return (0, builtin_types_1.hasBuiltInType)(name);
|
|
44
|
+
}
|
|
45
|
+
getBuiltInType(name) {
|
|
46
|
+
return (0, builtin_types_1.getBuiltInType)(name);
|
|
47
|
+
}
|
|
48
|
+
getBuiltInTypeByDataType(nodeId) {
|
|
49
|
+
return (0, builtin_types_1.getBuiltInType)(node_opcua_constants_1.DataTypeIds[nodeId.value]);
|
|
50
|
+
}
|
|
51
|
+
// -----------------------------
|
|
52
|
+
// EnumerationDefinitionSchema
|
|
53
|
+
registerEnumeration(enumeration) {
|
|
54
|
+
(0, node_opcua_assert_1.assert)(!this._enumerations.has(enumeration.name), "enumeration already registered");
|
|
55
|
+
this._enumerations.set(enumeration.name, enumeration);
|
|
56
|
+
}
|
|
57
|
+
hasEnumeration(enumName) {
|
|
58
|
+
if (this._enumerations.has(enumName)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
for (const factory of this.baseDataFactories) {
|
|
62
|
+
const e = factory.hasEnumeration(enumName);
|
|
63
|
+
if (e) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if ((0, enumerations_1.hasBuiltInEnumeration)(enumName)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
getEnumeration(enumName) {
|
|
73
|
+
if (this._enumerations.has(enumName)) {
|
|
74
|
+
return this._enumerations.get(enumName) || null;
|
|
75
|
+
}
|
|
76
|
+
for (const factory of this.baseDataFactories) {
|
|
77
|
+
const hasEnum = factory.hasEnumeration(enumName);
|
|
78
|
+
if (hasEnum) {
|
|
79
|
+
const e = factory.getEnumeration(enumName);
|
|
80
|
+
return e;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const ee = (0, enumerations_1.getBuiltInEnumeration)(enumName);
|
|
84
|
+
return ee;
|
|
85
|
+
}
|
|
86
|
+
// ----------------------------
|
|
87
|
+
findConstructorForDataType(dataTypeNodeId) {
|
|
88
|
+
const constructor = this.getConstructorForDataType(dataTypeNodeId);
|
|
89
|
+
if (constructor) {
|
|
90
|
+
return constructor;
|
|
91
|
+
}
|
|
92
|
+
this.getConstructorForDataType(dataTypeNodeId);
|
|
93
|
+
throw new Error("Cannot find StructureType constructor for dataType " + dataTypeNodeId.toString());
|
|
94
|
+
}
|
|
95
|
+
getConstructorForDataType(dataTypeNodeId) {
|
|
96
|
+
const constructor = this._structureTypeConstructorByDataTypeMap.get(dataTypeNodeId.toString());
|
|
97
|
+
if (constructor) {
|
|
98
|
+
return constructor;
|
|
99
|
+
}
|
|
100
|
+
for (const factory of this.baseDataFactories) {
|
|
101
|
+
const constructor2 = factory.getConstructorForDataType(dataTypeNodeId);
|
|
102
|
+
if (constructor2) {
|
|
103
|
+
return constructor2;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
// ----------------------------------------------------------------------------------------------------
|
|
109
|
+
// Access by typeName
|
|
110
|
+
// ----------------------------------------------------------------------------------------------------
|
|
111
|
+
structuredTypesNames() {
|
|
112
|
+
return this._structureTypeConstructorByNameMap.keys();
|
|
113
|
+
}
|
|
114
|
+
getStructureTypeConstructor(typeName) {
|
|
115
|
+
const constructor = this._structureTypeConstructorByNameMap.get(typeName);
|
|
116
|
+
if (constructor) {
|
|
117
|
+
return constructor;
|
|
118
|
+
}
|
|
119
|
+
for (const factory of this.baseDataFactories) {
|
|
120
|
+
if (!factory.hasStructuredType(typeName)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const constructor2 = factory.getStructureTypeConstructor(typeName);
|
|
124
|
+
if (constructor2) {
|
|
125
|
+
return constructor2;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// istanbul ignore next
|
|
129
|
+
if (doDebug) {
|
|
130
|
+
console.log([...this.structuredTypesNames()].join(" "));
|
|
131
|
+
}
|
|
132
|
+
// istanbul ignore next
|
|
133
|
+
throw new Error("Cannot find StructureType constructor for " + typeName + " - it may be abstract, or it could be a basic type");
|
|
134
|
+
}
|
|
135
|
+
hasStructuredType(typeName) {
|
|
136
|
+
if (this._structureTypeConstructorByNameMap.has(typeName)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
for (const factory of this.baseDataFactories) {
|
|
140
|
+
if (factory.hasStructuredType(typeName)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
getStructuredTypeSchema(typeName) {
|
|
147
|
+
const constructor = this.getStructureTypeConstructor(typeName);
|
|
148
|
+
return constructor.schema;
|
|
149
|
+
}
|
|
150
|
+
// istanbul ignore next
|
|
151
|
+
dump() {
|
|
152
|
+
console.log(" dumping registered factories");
|
|
153
|
+
console.log(" Factory ", [...this.structuredTypesNames()].sort().forEach((e) => e));
|
|
154
|
+
console.log(" done");
|
|
155
|
+
}
|
|
156
|
+
registerClassDefinition(dataTypeNodeId, className, classConstructor) {
|
|
157
|
+
this._registerFactory(dataTypeNodeId, className, classConstructor);
|
|
158
|
+
if (classConstructor.encodingDefaultBinary && classConstructor.encodingDefaultBinary.value !== 0) {
|
|
159
|
+
this.associateWithBinaryEncoding(className, classConstructor.encodingDefaultBinary);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// for instance in DI FetchResultDataType should be abstract but is not
|
|
163
|
+
debugLog("warning ", dataTypeNodeId.toString(), "name=", className, " do not have binary encoding");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// ----------------------------------------------------------------------------------------------------
|
|
167
|
+
// Access by binaryEncodingNodeId
|
|
168
|
+
// ----------------------------------------------------------------------------------------------------
|
|
169
|
+
getConstructor(binaryEncodingNodeId) {
|
|
170
|
+
const expandedNodeIdKey = makeExpandedNodeIdKey(binaryEncodingNodeId);
|
|
171
|
+
const constructor = this._structureTypeConstructorByEncodingNodeIdMap.get(expandedNodeIdKey);
|
|
172
|
+
if (constructor) {
|
|
173
|
+
return constructor;
|
|
174
|
+
}
|
|
175
|
+
for (const factory of this.baseDataFactories) {
|
|
176
|
+
const constructor2 = factory.getConstructor(binaryEncodingNodeId);
|
|
177
|
+
if (constructor2) {
|
|
178
|
+
return constructor2;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
debugLog(chalk.red("#getConstructor : cannot find constructor for expandedId "), binaryEncodingNodeId.toString());
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
hasConstructor(binaryEncodingNodeId) {
|
|
185
|
+
if (!binaryEncodingNodeId) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/* istanbul ignore next */
|
|
189
|
+
if (!verifyExpandedNodeId(binaryEncodingNodeId)) {
|
|
190
|
+
console.log("Invalid expandedNodeId");
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const expandedNodeIdKey = makeExpandedNodeIdKey(binaryEncodingNodeId);
|
|
194
|
+
const constructor = this._structureTypeConstructorByEncodingNodeIdMap.get(expandedNodeIdKey);
|
|
195
|
+
if (constructor) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
for (const factory of this.baseDataFactories) {
|
|
199
|
+
const constructor2 = factory.getConstructor(binaryEncodingNodeId);
|
|
200
|
+
if (constructor2) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
constructObject(binaryEncodingNodeId) {
|
|
207
|
+
if (!verifyExpandedNodeId(binaryEncodingNodeId)) {
|
|
208
|
+
throw new Error(" constructObject : invalid expandedNodeId provided " + binaryEncodingNodeId.toString());
|
|
209
|
+
}
|
|
210
|
+
const constructor = this.getConstructor(binaryEncodingNodeId);
|
|
211
|
+
if (!constructor) {
|
|
212
|
+
debugLog("Cannot find constructor for " + binaryEncodingNodeId.toString());
|
|
213
|
+
throw new Error("Cannot find constructor for " + binaryEncodingNodeId.toString());
|
|
214
|
+
}
|
|
215
|
+
return new constructor();
|
|
216
|
+
}
|
|
217
|
+
associateWithBinaryEncoding(className, expandedNodeId) {
|
|
218
|
+
const classConstructor = this.getStructureTypeConstructor(className);
|
|
219
|
+
if (doDebug) {
|
|
220
|
+
debugLog(" associateWithBinaryEncoding ", className, expandedNodeId.toString());
|
|
221
|
+
}
|
|
222
|
+
/* istanbul ignore next */
|
|
223
|
+
if (!verifyExpandedNodeId(expandedNodeId)) {
|
|
224
|
+
throw new Error("Invalid expandedNodeId " + expandedNodeId.toString() + " className = " + className);
|
|
225
|
+
}
|
|
226
|
+
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
|
|
227
|
+
/* istanbul ignore next */
|
|
228
|
+
if (this._structureTypeConstructorByEncodingNodeIdMap.has(expandedNodeIdKey)) {
|
|
229
|
+
throw new Error(" Class " +
|
|
230
|
+
className +
|
|
231
|
+
" with ID " +
|
|
232
|
+
expandedNodeId +
|
|
233
|
+
" already in constructorMap for " +
|
|
234
|
+
this._structureTypeConstructorByEncodingNodeIdMap.get(expandedNodeIdKey).name);
|
|
235
|
+
}
|
|
236
|
+
this._structureTypeConstructorByEncodingNodeIdMap.set(expandedNodeIdKey, classConstructor);
|
|
237
|
+
}
|
|
238
|
+
toString() {
|
|
239
|
+
const l = [];
|
|
240
|
+
function write(...args) {
|
|
241
|
+
l.push(util.format.apply(util.format, args));
|
|
242
|
+
}
|
|
243
|
+
dumpDataFactory(this, write);
|
|
244
|
+
return l.join("\n");
|
|
245
|
+
}
|
|
246
|
+
_registerFactory(dataTypeNodeId, typeName, constructor) {
|
|
247
|
+
/* istanbul ignore next */
|
|
248
|
+
if (this._structureTypeConstructorByNameMap.has(typeName)) {
|
|
249
|
+
warningLog(this.getStructureTypeConstructor(typeName));
|
|
250
|
+
warningLog("target namespace = `" + this.targetNamespace + "`");
|
|
251
|
+
warningLog(" registerFactory : " + typeName + " already registered. dataTypeNodeId=", dataTypeNodeId.toString());
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
debugLog("registering typeName ", typeName, dataTypeNodeId.toString());
|
|
255
|
+
this._structureTypeConstructorByNameMap.set(typeName, constructor);
|
|
256
|
+
if (dataTypeNodeId.value !== 0) {
|
|
257
|
+
this._structureTypeConstructorByDataTypeMap.set(dataTypeNodeId.toString(), constructor);
|
|
258
|
+
}
|
|
259
|
+
Object.defineProperty(constructor.schema, "$$factory", {
|
|
260
|
+
enumerable: false,
|
|
261
|
+
value: this,
|
|
262
|
+
writable: false
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.DataTypeFactory = DataTypeFactory;
|
|
267
|
+
function dumpSchema(schema, write) {
|
|
268
|
+
write("name ", schema.name);
|
|
269
|
+
write("dataType ", schema.dataTypeNodeId.toString());
|
|
270
|
+
write("binaryEncoding ", schema.encodingDefaultBinary.toString());
|
|
271
|
+
for (const f of schema.fields) {
|
|
272
|
+
write(" ", f.name.padEnd(30, " "), f.isArray ? true : false, f.fieldType);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function dumpDataFactory(dataFactory, write) {
|
|
276
|
+
for (const structureTypeName of dataFactory.structuredTypesNames()) {
|
|
277
|
+
const schema = dataFactory.getStructuredTypeSchema(structureTypeName);
|
|
278
|
+
write("structureTypeName =", structureTypeName);
|
|
279
|
+
if (!dataFactory.getConstructorForDataType(schema.dataTypeNodeId)) {
|
|
280
|
+
write(" ( No constructor for " + schema.name + " " + schema.dataTypeNodeId.toString());
|
|
281
|
+
}
|
|
282
|
+
if (!schema.encodingDefaultBinary) {
|
|
283
|
+
write(" (Schema has no encoding defaultBinary )");
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
if (dataFactory.hasConstructor(schema.encodingDefaultBinary)) {
|
|
287
|
+
console.log("schema", schema.name);
|
|
288
|
+
console.log("schema", schema.dataTypeNodeId.toString());
|
|
289
|
+
console.log("schema", schema.encodingDefaultBinary ? schema.encodingDefaultBinary.toString() : " ");
|
|
290
|
+
console.log("schema", schema.encodingDefaultXml ? schema.encodingDefaultXml.toString() : " ");
|
|
291
|
+
// return;
|
|
292
|
+
// throw new Error("Not in Binary Encoding Map!!!!! " + schema.encodingDefaultBinary);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
dumpSchema(schema, write);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function verifyExpandedNodeId(expandedNodeId) {
|
|
299
|
+
/* istanbul ignore next */
|
|
300
|
+
if (expandedNodeId.value instanceof Buffer) {
|
|
301
|
+
throw new Error("getConstructor not implemented for opaque nodeid");
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
function makeExpandedNodeIdKey(expandedNodeId) {
|
|
306
|
+
return expandedNodeId.toString();
|
|
307
|
+
}
|
|
308
308
|
//# sourceMappingURL=datatype_factory.js.map
|
package/dist/encode_decode.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { OutputBinaryStream, BinaryStream } from "node-opcua-binary-stream";
|
|
2
|
-
export declare function defaultEncode(value: any, stream: OutputBinaryStream): void;
|
|
3
|
-
export declare function defaultDecode(stream: BinaryStream): any;
|
|
4
|
-
export declare function defaultGuidValue(): any;
|
|
5
|
-
export declare function toJSONGuid(value: any): any;
|
|
6
|
-
export declare function encodeAny(value: any, stream: OutputBinaryStream): void;
|
|
7
|
-
export declare function decodeAny(stream: BinaryStream): void;
|
|
8
|
-
export declare function encodeNull(value: any, stream: OutputBinaryStream): void;
|
|
9
|
-
export declare function decodeNull(stream: BinaryStream): any;
|
|
1
|
+
import { OutputBinaryStream, BinaryStream } from "node-opcua-binary-stream";
|
|
2
|
+
export declare function defaultEncode(value: any, stream: OutputBinaryStream): void;
|
|
3
|
+
export declare function defaultDecode(stream: BinaryStream): any;
|
|
4
|
+
export declare function defaultGuidValue(): any;
|
|
5
|
+
export declare function toJSONGuid(value: any): any;
|
|
6
|
+
export declare function encodeAny(value: any, stream: OutputBinaryStream): void;
|
|
7
|
+
export declare function decodeAny(stream: BinaryStream): void;
|
|
8
|
+
export declare function encodeNull(value: any, stream: OutputBinaryStream): void;
|
|
9
|
+
export declare function decodeNull(stream: BinaryStream): any;
|