node-opcua-factory 2.70.0 → 2.71.0

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