node-opcua-schemas 2.71.0 → 2.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,595 +1,595 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDynamicObjectConstructor = exports.DynamicExtensionObject = exports.getOrCreateConstructor = void 0;
4
- /**
5
- * @module node-opcua-schemas
6
- */
7
- const node_opcua_assert_1 = require("node-opcua-assert");
8
- const node_opcua_debug_1 = require("node-opcua-debug");
9
- const node_opcua_extension_object_1 = require("node-opcua-extension-object");
10
- const node_opcua_factory_1 = require("node-opcua-factory");
11
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
12
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
13
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
14
- function getOrCreateConstructor(dataTypeName, dataTypeFactory, encodingDefaultBinary, encodingDefaultXml) {
15
- if (dataTypeFactory.hasStructuredType(dataTypeName)) {
16
- return dataTypeFactory.getStructureTypeConstructor(dataTypeName);
17
- }
18
- const schema = dataTypeFactory.getStructuredTypeSchema(dataTypeName);
19
- // istanbul ignore next
20
- if (!schema) {
21
- throw new Error("Unknown type in dictionary " + dataTypeName);
22
- }
23
- const constructor = createDynamicObjectConstructor(schema, dataTypeFactory);
24
- if (!constructor) {
25
- return constructor;
26
- }
27
- // istanbul ignore next
28
- if (!dataTypeFactory.hasStructuredType(dataTypeName)) {
29
- dataTypeFactory.registerClassDefinition(schema.id, dataTypeName, constructor);
30
- return constructor;
31
- // hrow new Error("constructor should now be registered - " + fieldType);
32
- }
33
- if (encodingDefaultBinary && encodingDefaultBinary.value !== 0) {
34
- schema.encodingDefaultBinary = encodingDefaultBinary;
35
- schema.encodingDefaultXml = encodingDefaultXml;
36
- constructor.encodingDefaultBinary = encodingDefaultBinary;
37
- constructor.encodingDefaultXml = encodingDefaultXml;
38
- dataTypeFactory.associateWithBinaryEncoding(dataTypeName, encodingDefaultBinary);
39
- }
40
- return constructor;
41
- }
42
- exports.getOrCreateConstructor = getOrCreateConstructor;
43
- function encodeArrayOrElement(field, obj, stream, encodeFunc) {
44
- if (field.isArray) {
45
- const array = obj[field.name];
46
- if (!array) {
47
- stream.writeUInt32(0xffffffff);
48
- }
49
- else {
50
- stream.writeUInt32(array.length);
51
- for (const e of array) {
52
- if (encodeFunc) {
53
- encodeFunc(e, stream);
54
- }
55
- else {
56
- e.encode(stream);
57
- }
58
- }
59
- }
60
- }
61
- else {
62
- if (encodeFunc) {
63
- encodeFunc(obj[field.name], stream);
64
- }
65
- else {
66
- if (!obj[field.name].encode) {
67
- // tslint:disable:no-console
68
- console.log(obj.schema.fields, field);
69
- throw new Error("encodeArrayOrElement: object field " + field.name + " has no encode method and encodeFunc is missing");
70
- }
71
- obj[field.name].encode(stream);
72
- }
73
- }
74
- }
75
- function decodeArrayOrElement(factory, field, obj, stream, decodeFunc) {
76
- if (field.isArray) {
77
- const array = [];
78
- const nbElements = stream.readUInt32();
79
- if (nbElements === 0xffffffff) {
80
- obj[field.name] = null;
81
- }
82
- else {
83
- for (let i = 0; i < nbElements; i++) {
84
- if (decodeFunc) {
85
- array.push(decodeFunc(stream));
86
- }
87
- else {
88
- // construct an instance
89
- const constructor = factory.getStructureTypeConstructor(field.fieldType);
90
- const element = new constructor({});
91
- element.decode(stream);
92
- array.push(element);
93
- }
94
- }
95
- obj[field.name] = array;
96
- }
97
- }
98
- else {
99
- if (decodeFunc) {
100
- obj[field.name] = decodeFunc(stream);
101
- }
102
- else {
103
- if (!obj[field.name]) {
104
- const constructor = factory.getStructureTypeConstructor(field.fieldType);
105
- obj[field.name] = new constructor({});
106
- }
107
- obj[field.name].decode(stream);
108
- }
109
- }
110
- }
111
- function initializeField(field, thisAny, options, schema, factory) {
112
- const name = field.name;
113
- switch (field.category) {
114
- case node_opcua_factory_1.FieldCategory.complex: {
115
- const constructor = factory.getStructureTypeConstructor(field.fieldType);
116
- // getOrCreateConstructor(field.fieldType, factory) || BaseUAObject;
117
- if (field.isArray) {
118
- const arr = options[name] || [];
119
- if (!arr.map) {
120
- console.log("Error", options);
121
- }
122
- thisAny[name] = arr.map((x) => (constructor ? new constructor(x) : null));
123
- }
124
- else {
125
- thisAny[name] = constructor ? new constructor(options[name]) : null;
126
- }
127
- // xx processStructuredType(fieldSchema);
128
- break;
129
- }
130
- case node_opcua_factory_1.FieldCategory.enumeration:
131
- case node_opcua_factory_1.FieldCategory.basic:
132
- if (field.isArray) {
133
- thisAny[name] = (0, node_opcua_factory_1.initialize_field_array)(field, options[name]);
134
- }
135
- else {
136
- thisAny[name] = (0, node_opcua_factory_1.initialize_field)(field, options[name]);
137
- }
138
- break;
139
- }
140
- }
141
- /**
142
- * @private
143
- * @param thisAny
144
- * @param options
145
- * @param schema
146
- * @param factory
147
- */
148
- function initializeFields(thisAny, options, schema, factory) {
149
- // initialize base class first
150
- if (schema._baseSchema && schema._baseSchema.fields.length) {
151
- initializeFields(thisAny, options, schema._baseSchema, factory);
152
- }
153
- // finding fields that are in options but not in schema!
154
- for (const field of schema.fields) {
155
- const name = field.name;
156
- // dealing with optional fields
157
- if (field.switchBit !== undefined && options[field.name] === undefined) {
158
- thisAny[name] = undefined;
159
- continue;
160
- }
161
- initializeField(field, thisAny, options, schema, factory);
162
- }
163
- }
164
- function hasOptionalFieldsF(schema) {
165
- if (schema.bitFields && schema.bitFields.length > 0) {
166
- return true;
167
- }
168
- return schema._baseSchema ? hasOptionalFieldsF(schema._baseSchema) : false;
169
- }
170
- function _internal_encodeFields(thisAny, schema, stream) {
171
- // encodeFields base class first
172
- if (schema._baseSchema && schema._baseSchema.fields.length) {
173
- _internal_encodeFields(thisAny, schema._baseSchema, stream);
174
- }
175
- for (const field of schema.fields) {
176
- // ignore
177
- if (field.switchBit !== undefined && thisAny[field.name] === undefined) {
178
- continue;
179
- }
180
- switch (field.category) {
181
- case node_opcua_factory_1.FieldCategory.complex:
182
- encodeArrayOrElement(field, thisAny, stream);
183
- break;
184
- case node_opcua_factory_1.FieldCategory.enumeration:
185
- case node_opcua_factory_1.FieldCategory.basic:
186
- encodeArrayOrElement(field, thisAny, stream, field.schema.encode);
187
- break;
188
- default:
189
- /* istanbul ignore next*/
190
- throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
191
- }
192
- }
193
- }
194
- function makeBitField(thisAny, schema, bo) {
195
- const data = schema._baseSchema ? makeBitField(thisAny, schema._baseSchema, bo) : bo;
196
- let { bitField, allOptional } = data;
197
- const { offset } = data;
198
- let nbOptionalFields = 0;
199
- for (const field of schema.fields) {
200
- if (field.switchBit === undefined) {
201
- allOptional = false;
202
- continue;
203
- }
204
- nbOptionalFields += 1;
205
- if (thisAny[field.name] === undefined) {
206
- continue;
207
- }
208
- // tslint:disable-next-line:no-bitwise
209
- bitField |= 1 << (field.switchBit + offset);
210
- }
211
- return { bitField, offset: nbOptionalFields + offset, allOptional };
212
- }
213
- function encodeFields(thisAny, schema, stream) {
214
- const hasOptionalFields = hasOptionalFieldsF(schema);
215
- // ============ Deal with switchBits
216
- if (hasOptionalFields) {
217
- const { bitField, allOptional } = makeBitField(thisAny, schema, { bitField: 0, offset: 0, allOptional: true });
218
- if (!(bitField === 0 && allOptional)) {
219
- stream.writeUInt32(bitField);
220
- }
221
- }
222
- _internal_encodeFields(thisAny, schema, stream);
223
- }
224
- function internal_decodeFields(thisAny, bitField, hasOptionalFields, schema, stream, factory) {
225
- // encodeFields base class first
226
- if (schema._baseSchema && schema._baseSchema.fields.length) {
227
- internal_decodeFields(thisAny, bitField, hasOptionalFields, schema._baseSchema, stream, factory);
228
- }
229
- for (const field of schema.fields) {
230
- // ignore fields that have a switch bit when bit is not set
231
- if (hasOptionalFields && field.switchBit !== undefined) {
232
- // tslint:disable-next-line:no-bitwise
233
- if ((bitField & (1 << field.switchBit)) === 0) {
234
- thisAny[field.name] = undefined;
235
- continue;
236
- }
237
- else {
238
- if (field.category === node_opcua_factory_1.FieldCategory.complex && thisAny[field.name] === undefined) {
239
- // need to create empty structure for deserialisation
240
- initializeField(field, thisAny, {}, schema, factory);
241
- }
242
- }
243
- }
244
- switch (field.category) {
245
- case node_opcua_factory_1.FieldCategory.complex:
246
- decodeArrayOrElement(factory, field, thisAny, stream);
247
- break;
248
- case node_opcua_factory_1.FieldCategory.enumeration:
249
- case node_opcua_factory_1.FieldCategory.basic:
250
- decodeArrayOrElement(factory, field, thisAny, stream, field.schema.decode);
251
- break;
252
- default:
253
- /* istanbul ignore next*/
254
- throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
255
- }
256
- }
257
- }
258
- function decodeFields(thisAny, schema, stream, factory) {
259
- // ============ Deal with switchBits
260
- const hasOptionalFields = hasOptionalFieldsF(schema);
261
- let bitField = 0;
262
- if (hasOptionalFields && stream.buffer.length - stream.length > 0) {
263
- bitField = stream.readUInt32();
264
- }
265
- internal_decodeFields(thisAny, bitField, hasOptionalFields, schema, stream, factory);
266
- }
267
- function ___fieldToJson(field, value) {
268
- switch (field.category) {
269
- case node_opcua_factory_1.FieldCategory.complex:
270
- return value ? value === null || value === void 0 ? void 0 : value.toJSON() : null;
271
- case node_opcua_factory_1.FieldCategory.enumeration:
272
- case node_opcua_factory_1.FieldCategory.basic:
273
- return value instanceof Date ? new Date(value.getTime()) : (value === null || value === void 0 ? void 0 : value.toJSON) ? value === null || value === void 0 ? void 0 : value.toJSON() : value;
274
- default:
275
- /* istanbul ignore next*/
276
- throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
277
- }
278
- }
279
- function fieldToJSON(field, value) {
280
- if (field.isArray) {
281
- if (value) {
282
- return value.map(___fieldToJson.bind(null, field));
283
- }
284
- }
285
- else {
286
- return ___fieldToJson(field, value);
287
- }
288
- }
289
- function encodeToJson(thisAny, schema, pojo) {
290
- if (schema._baseSchema && schema._baseSchema.fields.length) {
291
- encodeToJson(thisAny, schema._baseSchema, pojo);
292
- }
293
- for (const field of schema.fields) {
294
- const value = thisAny[field.name];
295
- if (value === undefined) {
296
- continue;
297
- }
298
- pojo[field.name] = fieldToJSON(field, value);
299
- }
300
- }
301
- const _private = new WeakMap();
302
- class DynamicExtensionObject extends node_opcua_extension_object_1.ExtensionObject {
303
- constructor(options, schema, factory) {
304
- (0, node_opcua_assert_1.assert)(schema, "expecting a schema here ");
305
- (0, node_opcua_assert_1.assert)(factory, "expecting a typeDic");
306
- super(options);
307
- options = options || {};
308
- _private.set(this, { schema, factory });
309
- (0, node_opcua_factory_1.check_options_correctness_against_schema)(this, this.schema, options);
310
- initializeFields(this, options, this.schema, factory);
311
- }
312
- encode(stream) {
313
- super.encode(stream);
314
- encodeFields(this, this.schema, stream);
315
- }
316
- decode(stream) {
317
- super.decode(stream);
318
- decodeFields(this, this.schema, stream, _private.get(this).factory);
319
- }
320
- get schema() {
321
- const r = _private.get(this);
322
- return r.schema;
323
- }
324
- toJSON() {
325
- const pojo = {};
326
- encodeToJson(this, this.schema, pojo);
327
- return pojo;
328
- }
329
- }
330
- exports.DynamicExtensionObject = DynamicExtensionObject;
331
- DynamicExtensionObject.schema = node_opcua_extension_object_1.ExtensionObject.schema;
332
- DynamicExtensionObject.possibleFields = [];
333
- // tslint:disable-next-line:max-classes-per-file
334
- class UnionBaseClass extends node_opcua_factory_1.BaseUAObject {
335
- // eslint-disable-next-line max-statements
336
- constructor(options, schema, factory) {
337
- super();
338
- (0, node_opcua_assert_1.assert)(schema, "expecting a schema here ");
339
- (0, node_opcua_assert_1.assert)(factory, "expecting a typeDic");
340
- options = options || {};
341
- _private.set(this, { schema });
342
- (0, node_opcua_factory_1.check_options_correctness_against_schema)(this, this.schema, options);
343
- let uniqueFieldHasBeenFound = false;
344
- let switchFieldName = "";
345
- // finding fields that are in options but not in schema!
346
- for (const field of this.schema.fields) {
347
- const name = field.name;
348
- if (field.switchValue === undefined) {
349
- // this is the switch value field
350
- switchFieldName = field.name;
351
- continue;
352
- }
353
- (0, node_opcua_assert_1.assert)(switchFieldName.length > 0, "It seems that there is no switch field in union schema");
354
- (0, node_opcua_assert_1.assert)(field.switchValue !== undefined, "union schema must only have one switched value field");
355
- // dealing with optional fields
356
- /* istanbul ignore next */
357
- if (uniqueFieldHasBeenFound && options[field.name] !== undefined) {
358
- // let try to be helpful for the developper by providing some hint
359
- debugLog(this.schema);
360
- throw new Error("union must have only one choice in " +
361
- JSON.stringify(options) +
362
- "\n found while investigating " +
363
- field.name +
364
- "\n switchFieldName = " +
365
- switchFieldName);
366
- }
367
- if (options[switchFieldName] !== undefined) {
368
- // then options[switchFieldName] must equal
369
- if (options[switchFieldName] !== field.switchValue) {
370
- continue;
371
- }
372
- }
373
- else {
374
- // the is no switchFieldName , in this case the i
375
- if (options[name] === undefined) {
376
- continue;
377
- }
378
- }
379
- uniqueFieldHasBeenFound = true;
380
- this[switchFieldName] = field.switchValue;
381
- switch (field.category) {
382
- case node_opcua_factory_1.FieldCategory.complex: {
383
- const constuctor = factory.getStructureTypeConstructor(field.fieldType);
384
- // getOrCreateConstructor(field.fieldType, factory) || BaseUAObject;
385
- if (field.isArray) {
386
- this[name] = (options[name] || []).map((x) => (constuctor ? new constuctor(x) : null));
387
- }
388
- else {
389
- this[name] = constuctor ? new constuctor(options[name]) : null;
390
- }
391
- // xx processStructuredType(fieldSchema);
392
- break;
393
- }
394
- case node_opcua_factory_1.FieldCategory.enumeration:
395
- case node_opcua_factory_1.FieldCategory.basic:
396
- if (field.isArray) {
397
- this[name] = (0, node_opcua_factory_1.initialize_field_array)(field, options[name]);
398
- }
399
- else {
400
- this[name] = (0, node_opcua_factory_1.initialize_field)(field, options[name]);
401
- }
402
- break;
403
- }
404
- }
405
- if (!uniqueFieldHasBeenFound) {
406
- if (Object.keys(options).length === 0) {
407
- this[switchFieldName] = 0x00;
408
- return;
409
- }
410
- const r = schema.fields
411
- .filter((f) => f.switchValue !== undefined)
412
- .map((f) => f.name)
413
- .join(" , ");
414
- // it is possible also that the switchfield value do not correspond to a valid field
415
- const foundFieldForSwitchValue = schema.fields.findIndex((f) => f.switchValue !== undefined && f.switchValue === options[switchFieldName]);
416
- if (foundFieldForSwitchValue) {
417
- // throw new Error(this.schema.name + ": cannot find field with value "
418
- // + options[switchFieldName]);
419
- }
420
- else {
421
- console.log(this.schema);
422
- throw new Error(this.schema.name + ": At least one of [ " + r + " ] must be specified in " + JSON.stringify(options));
423
- }
424
- }
425
- }
426
- encode(stream) {
427
- const switchFieldName = this.schema.fields[0].name;
428
- const switchValue = this[switchFieldName];
429
- if (typeof switchValue !== "number") {
430
- throw new Error("Invalid switchValue " + switchFieldName + " value = " + switchValue);
431
- }
432
- stream.writeUInt32(switchValue);
433
- for (const field of this.schema.fields) {
434
- if (field.switchValue === undefined || field.switchValue !== switchValue) {
435
- continue;
436
- }
437
- switch (field.category) {
438
- case node_opcua_factory_1.FieldCategory.complex:
439
- encodeArrayOrElement(field, this, stream);
440
- break;
441
- case node_opcua_factory_1.FieldCategory.enumeration:
442
- case node_opcua_factory_1.FieldCategory.basic:
443
- encodeArrayOrElement(field, this, stream, field.schema.encode);
444
- break;
445
- default:
446
- /* istanbul ignore next*/
447
- throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
448
- }
449
- break;
450
- }
451
- }
452
- decode(stream) {
453
- const factory = this.schema.$$factory;
454
- const switchValue = stream.readUInt32();
455
- const switchFieldName = this.schema.fields[0].name;
456
- this[switchFieldName] = switchValue;
457
- for (const field of this.schema.fields) {
458
- if (field.switchValue === undefined || field.switchValue !== switchValue) {
459
- continue;
460
- }
461
- switch (field.category) {
462
- case node_opcua_factory_1.FieldCategory.complex:
463
- decodeArrayOrElement(factory, field, this, stream);
464
- break;
465
- case node_opcua_factory_1.FieldCategory.enumeration:
466
- case node_opcua_factory_1.FieldCategory.basic:
467
- decodeArrayOrElement(factory, field, this, stream, field.schema.decode);
468
- break;
469
- default:
470
- /* istanbul ignore next*/
471
- throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
472
- }
473
- break;
474
- }
475
- }
476
- get schema() {
477
- return _private.get(this).schema;
478
- }
479
- toString() {
480
- return super.toString();
481
- }
482
- toJSON() {
483
- const pojo = {};
484
- const switchFieldName = this.schema.fields[0].name;
485
- const switchValue = this[switchFieldName];
486
- if (typeof switchValue !== "number") {
487
- throw new Error("Invalid switchValue " + switchValue);
488
- }
489
- pojo[switchFieldName] = switchValue;
490
- for (const field of this.schema.fields) {
491
- if (field.switchValue === undefined || field.switchValue !== switchValue) {
492
- continue;
493
- }
494
- const value = this[field.name];
495
- if (value === undefined) {
496
- continue;
497
- }
498
- pojo[field.name] = fieldToJSON(field, value);
499
- break;
500
- }
501
- return pojo;
502
- }
503
- }
504
- function _createDynamicUnionConstructor(schema, factory) {
505
- const possibleFields = schema.fields.map((x) => x.name);
506
- // tslint:disable-next-line:max-classes-per-file
507
- class UNION extends UnionBaseClass {
508
- constructor(options) {
509
- super(options, schema, factory);
510
- (0, node_opcua_assert_1.assert)(this.schema === schema);
511
- }
512
- }
513
- UNION.possibleFields = possibleFields;
514
- UNION.schema = schema;
515
- // to do : may be remove DataType suffix here ?
516
- Object.defineProperty(UNION, "name", { value: schema.name });
517
- return UNION;
518
- }
519
- function createDynamicObjectConstructor(schema, dataTypeFactory) {
520
- var _a;
521
- const schemaPriv = schema;
522
- if (schemaPriv.$Constructor) {
523
- return schemaPriv.$Constructor;
524
- }
525
- const dataTypeNodeId = schemaPriv.id;
526
- if (schema.baseType === "Union") {
527
- const UNIONConstructor = _createDynamicUnionConstructor(schema, dataTypeFactory);
528
- schemaPriv.$Constructor = UNIONConstructor;
529
- dataTypeFactory.registerClassDefinition(dataTypeNodeId, schema.name, UNIONConstructor);
530
- return UNIONConstructor;
531
- }
532
- let possibleFields = schema.fields.map((x) => x.name);
533
- let BaseClass = DynamicExtensionObject;
534
- if (schema.baseType !== "ExtensionObject" &&
535
- schema.baseType !== "OptionSet" &&
536
- schema.baseType !== "DataTypeDescription" &&
537
- schema.baseType !== "DataTypeDefinition" &&
538
- schema.baseType !== "EnumValueType" &&
539
- schema.baseType !== "Structure") {
540
- try {
541
- const baseSchema = dataTypeFactory.getStructuredTypeSchema(schema.baseType);
542
- schema._baseSchema = baseSchema;
543
- if (((_a = baseSchema.encodingDefaultBinary) === null || _a === void 0 ? void 0 : _a.value) === 0) {
544
- // is abstract
545
- }
546
- else {
547
- BaseClass = getOrCreateConstructor(schema.baseType, dataTypeFactory);
548
- if (!BaseClass) {
549
- throw new Error("Cannot find base class : " + schema.baseType);
550
- }
551
- if (BaseClass.possibleFields) {
552
- possibleFields = BaseClass.possibleFields.concat(possibleFields);
553
- }
554
- schema._baseSchema = BaseClass.schema;
555
- }
556
- }
557
- catch (err) {
558
- // xx console.log("createDynamicObjectConstructor err= ", err.message);
559
- }
560
- }
561
- // tslint:disable-next-line:max-classes-per-file
562
- class EXTENSION extends BaseClass {
563
- constructor(options, schema2, factory2) {
564
- super(options, schema2 ? schema2 : schema, factory2 ? factory2 : dataTypeFactory);
565
- }
566
- static get schema() {
567
- return schema;
568
- }
569
- toString() {
570
- return super.toString();
571
- }
572
- toJSON() {
573
- const pojo = {};
574
- encodeToJson(this, this.schema, pojo);
575
- return pojo;
576
- }
577
- encode(stream) {
578
- super.encode(stream);
579
- }
580
- decode(stream) {
581
- super.decode(stream);
582
- }
583
- }
584
- EXTENSION.encodingDefaultXml = new node_opcua_nodeid_1.ExpandedNodeId(node_opcua_nodeid_1.NodeIdType.NUMERIC, 0, 0);
585
- EXTENSION.encodingDefaultBinary = new node_opcua_nodeid_1.ExpandedNodeId(node_opcua_nodeid_1.NodeIdType.NUMERIC, 0, 0);
586
- EXTENSION.possibleFields = possibleFields;
587
- // to do : may be remove DataType suffix here ?
588
- Object.defineProperty(EXTENSION, "name", { value: schema.name });
589
- schemaPriv.$Constructor = EXTENSION;
590
- EXTENSION.encodingDefaultBinary = schema.encodingDefaultBinary;
591
- dataTypeFactory.registerClassDefinition(dataTypeNodeId, schema.name, EXTENSION);
592
- return EXTENSION;
593
- }
594
- exports.createDynamicObjectConstructor = createDynamicObjectConstructor;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDynamicObjectConstructor = exports.DynamicExtensionObject = exports.getOrCreateConstructor = void 0;
4
+ /**
5
+ * @module node-opcua-schemas
6
+ */
7
+ const node_opcua_assert_1 = require("node-opcua-assert");
8
+ const node_opcua_debug_1 = require("node-opcua-debug");
9
+ const node_opcua_extension_object_1 = require("node-opcua-extension-object");
10
+ const node_opcua_factory_1 = require("node-opcua-factory");
11
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
12
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
13
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
14
+ function getOrCreateConstructor(dataTypeName, dataTypeFactory, encodingDefaultBinary, encodingDefaultXml) {
15
+ if (dataTypeFactory.hasStructuredType(dataTypeName)) {
16
+ return dataTypeFactory.getStructureTypeConstructor(dataTypeName);
17
+ }
18
+ const schema = dataTypeFactory.getStructuredTypeSchema(dataTypeName);
19
+ // istanbul ignore next
20
+ if (!schema) {
21
+ throw new Error("Unknown type in dictionary " + dataTypeName);
22
+ }
23
+ const constructor = createDynamicObjectConstructor(schema, dataTypeFactory);
24
+ if (!constructor) {
25
+ return constructor;
26
+ }
27
+ // istanbul ignore next
28
+ if (!dataTypeFactory.hasStructuredType(dataTypeName)) {
29
+ dataTypeFactory.registerClassDefinition(schema.id, dataTypeName, constructor);
30
+ return constructor;
31
+ // hrow new Error("constructor should now be registered - " + fieldType);
32
+ }
33
+ if (encodingDefaultBinary && encodingDefaultBinary.value !== 0) {
34
+ schema.encodingDefaultBinary = encodingDefaultBinary;
35
+ schema.encodingDefaultXml = encodingDefaultXml;
36
+ constructor.encodingDefaultBinary = encodingDefaultBinary;
37
+ constructor.encodingDefaultXml = encodingDefaultXml;
38
+ dataTypeFactory.associateWithBinaryEncoding(dataTypeName, encodingDefaultBinary);
39
+ }
40
+ return constructor;
41
+ }
42
+ exports.getOrCreateConstructor = getOrCreateConstructor;
43
+ function encodeArrayOrElement(field, obj, stream, encodeFunc) {
44
+ if (field.isArray) {
45
+ const array = obj[field.name];
46
+ if (!array) {
47
+ stream.writeUInt32(0xffffffff);
48
+ }
49
+ else {
50
+ stream.writeUInt32(array.length);
51
+ for (const e of array) {
52
+ if (encodeFunc) {
53
+ encodeFunc(e, stream);
54
+ }
55
+ else {
56
+ e.encode(stream);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ else {
62
+ if (encodeFunc) {
63
+ encodeFunc(obj[field.name], stream);
64
+ }
65
+ else {
66
+ if (!obj[field.name].encode) {
67
+ // tslint:disable:no-console
68
+ console.log(obj.schema.fields, field);
69
+ throw new Error("encodeArrayOrElement: object field " + field.name + " has no encode method and encodeFunc is missing");
70
+ }
71
+ obj[field.name].encode(stream);
72
+ }
73
+ }
74
+ }
75
+ function decodeArrayOrElement(factory, field, obj, stream, decodeFunc) {
76
+ if (field.isArray) {
77
+ const array = [];
78
+ const nbElements = stream.readUInt32();
79
+ if (nbElements === 0xffffffff) {
80
+ obj[field.name] = null;
81
+ }
82
+ else {
83
+ for (let i = 0; i < nbElements; i++) {
84
+ if (decodeFunc) {
85
+ array.push(decodeFunc(stream));
86
+ }
87
+ else {
88
+ // construct an instance
89
+ const constructor = factory.getStructureTypeConstructor(field.fieldType);
90
+ const element = new constructor({});
91
+ element.decode(stream);
92
+ array.push(element);
93
+ }
94
+ }
95
+ obj[field.name] = array;
96
+ }
97
+ }
98
+ else {
99
+ if (decodeFunc) {
100
+ obj[field.name] = decodeFunc(stream);
101
+ }
102
+ else {
103
+ if (!obj[field.name]) {
104
+ const constructor = factory.getStructureTypeConstructor(field.fieldType);
105
+ obj[field.name] = new constructor({});
106
+ }
107
+ obj[field.name].decode(stream);
108
+ }
109
+ }
110
+ }
111
+ function initializeField(field, thisAny, options, schema, factory) {
112
+ const name = field.name;
113
+ switch (field.category) {
114
+ case node_opcua_factory_1.FieldCategory.complex: {
115
+ const constructor = factory.getStructureTypeConstructor(field.fieldType);
116
+ // getOrCreateConstructor(field.fieldType, factory) || BaseUAObject;
117
+ if (field.isArray) {
118
+ const arr = options[name] || [];
119
+ if (!arr.map) {
120
+ console.log("Error", options);
121
+ }
122
+ thisAny[name] = arr.map((x) => (constructor ? new constructor(x) : null));
123
+ }
124
+ else {
125
+ thisAny[name] = constructor ? new constructor(options[name]) : null;
126
+ }
127
+ // xx processStructuredType(fieldSchema);
128
+ break;
129
+ }
130
+ case node_opcua_factory_1.FieldCategory.enumeration:
131
+ case node_opcua_factory_1.FieldCategory.basic:
132
+ if (field.isArray) {
133
+ thisAny[name] = (0, node_opcua_factory_1.initialize_field_array)(field, options[name]);
134
+ }
135
+ else {
136
+ thisAny[name] = (0, node_opcua_factory_1.initialize_field)(field, options[name]);
137
+ }
138
+ break;
139
+ }
140
+ }
141
+ /**
142
+ * @private
143
+ * @param thisAny
144
+ * @param options
145
+ * @param schema
146
+ * @param factory
147
+ */
148
+ function initializeFields(thisAny, options, schema, factory) {
149
+ // initialize base class first
150
+ if (schema._baseSchema && schema._baseSchema.fields.length) {
151
+ initializeFields(thisAny, options, schema._baseSchema, factory);
152
+ }
153
+ // finding fields that are in options but not in schema!
154
+ for (const field of schema.fields) {
155
+ const name = field.name;
156
+ // dealing with optional fields
157
+ if (field.switchBit !== undefined && options[field.name] === undefined) {
158
+ thisAny[name] = undefined;
159
+ continue;
160
+ }
161
+ initializeField(field, thisAny, options, schema, factory);
162
+ }
163
+ }
164
+ function hasOptionalFieldsF(schema) {
165
+ if (schema.bitFields && schema.bitFields.length > 0) {
166
+ return true;
167
+ }
168
+ return schema._baseSchema ? hasOptionalFieldsF(schema._baseSchema) : false;
169
+ }
170
+ function _internal_encodeFields(thisAny, schema, stream) {
171
+ // encodeFields base class first
172
+ if (schema._baseSchema && schema._baseSchema.fields.length) {
173
+ _internal_encodeFields(thisAny, schema._baseSchema, stream);
174
+ }
175
+ for (const field of schema.fields) {
176
+ // ignore
177
+ if (field.switchBit !== undefined && thisAny[field.name] === undefined) {
178
+ continue;
179
+ }
180
+ switch (field.category) {
181
+ case node_opcua_factory_1.FieldCategory.complex:
182
+ encodeArrayOrElement(field, thisAny, stream);
183
+ break;
184
+ case node_opcua_factory_1.FieldCategory.enumeration:
185
+ case node_opcua_factory_1.FieldCategory.basic:
186
+ encodeArrayOrElement(field, thisAny, stream, field.schema.encode);
187
+ break;
188
+ default:
189
+ /* istanbul ignore next*/
190
+ throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
191
+ }
192
+ }
193
+ }
194
+ function makeBitField(thisAny, schema, bo) {
195
+ const data = schema._baseSchema ? makeBitField(thisAny, schema._baseSchema, bo) : bo;
196
+ let { bitField, allOptional } = data;
197
+ const { offset } = data;
198
+ let nbOptionalFields = 0;
199
+ for (const field of schema.fields) {
200
+ if (field.switchBit === undefined) {
201
+ allOptional = false;
202
+ continue;
203
+ }
204
+ nbOptionalFields += 1;
205
+ if (thisAny[field.name] === undefined) {
206
+ continue;
207
+ }
208
+ // tslint:disable-next-line:no-bitwise
209
+ bitField |= 1 << (field.switchBit + offset);
210
+ }
211
+ return { bitField, offset: nbOptionalFields + offset, allOptional };
212
+ }
213
+ function encodeFields(thisAny, schema, stream) {
214
+ const hasOptionalFields = hasOptionalFieldsF(schema);
215
+ // ============ Deal with switchBits
216
+ if (hasOptionalFields) {
217
+ const { bitField, allOptional } = makeBitField(thisAny, schema, { bitField: 0, offset: 0, allOptional: true });
218
+ if (!(bitField === 0 && allOptional)) {
219
+ stream.writeUInt32(bitField);
220
+ }
221
+ }
222
+ _internal_encodeFields(thisAny, schema, stream);
223
+ }
224
+ function internal_decodeFields(thisAny, bitField, hasOptionalFields, schema, stream, factory) {
225
+ // encodeFields base class first
226
+ if (schema._baseSchema && schema._baseSchema.fields.length) {
227
+ internal_decodeFields(thisAny, bitField, hasOptionalFields, schema._baseSchema, stream, factory);
228
+ }
229
+ for (const field of schema.fields) {
230
+ // ignore fields that have a switch bit when bit is not set
231
+ if (hasOptionalFields && field.switchBit !== undefined) {
232
+ // tslint:disable-next-line:no-bitwise
233
+ if ((bitField & (1 << field.switchBit)) === 0) {
234
+ thisAny[field.name] = undefined;
235
+ continue;
236
+ }
237
+ else {
238
+ if (field.category === node_opcua_factory_1.FieldCategory.complex && thisAny[field.name] === undefined) {
239
+ // need to create empty structure for deserialisation
240
+ initializeField(field, thisAny, {}, schema, factory);
241
+ }
242
+ }
243
+ }
244
+ switch (field.category) {
245
+ case node_opcua_factory_1.FieldCategory.complex:
246
+ decodeArrayOrElement(factory, field, thisAny, stream);
247
+ break;
248
+ case node_opcua_factory_1.FieldCategory.enumeration:
249
+ case node_opcua_factory_1.FieldCategory.basic:
250
+ decodeArrayOrElement(factory, field, thisAny, stream, field.schema.decode);
251
+ break;
252
+ default:
253
+ /* istanbul ignore next*/
254
+ throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
255
+ }
256
+ }
257
+ }
258
+ function decodeFields(thisAny, schema, stream, factory) {
259
+ // ============ Deal with switchBits
260
+ const hasOptionalFields = hasOptionalFieldsF(schema);
261
+ let bitField = 0;
262
+ if (hasOptionalFields && stream.buffer.length - stream.length > 0) {
263
+ bitField = stream.readUInt32();
264
+ }
265
+ internal_decodeFields(thisAny, bitField, hasOptionalFields, schema, stream, factory);
266
+ }
267
+ function ___fieldToJson(field, value) {
268
+ switch (field.category) {
269
+ case node_opcua_factory_1.FieldCategory.complex:
270
+ return value ? value === null || value === void 0 ? void 0 : value.toJSON() : null;
271
+ case node_opcua_factory_1.FieldCategory.enumeration:
272
+ case node_opcua_factory_1.FieldCategory.basic:
273
+ return value instanceof Date ? new Date(value.getTime()) : (value === null || value === void 0 ? void 0 : value.toJSON) ? value === null || value === void 0 ? void 0 : value.toJSON() : value;
274
+ default:
275
+ /* istanbul ignore next*/
276
+ throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
277
+ }
278
+ }
279
+ function fieldToJSON(field, value) {
280
+ if (field.isArray) {
281
+ if (value) {
282
+ return value.map(___fieldToJson.bind(null, field));
283
+ }
284
+ }
285
+ else {
286
+ return ___fieldToJson(field, value);
287
+ }
288
+ }
289
+ function encodeToJson(thisAny, schema, pojo) {
290
+ if (schema._baseSchema && schema._baseSchema.fields.length) {
291
+ encodeToJson(thisAny, schema._baseSchema, pojo);
292
+ }
293
+ for (const field of schema.fields) {
294
+ const value = thisAny[field.name];
295
+ if (value === undefined) {
296
+ continue;
297
+ }
298
+ pojo[field.name] = fieldToJSON(field, value);
299
+ }
300
+ }
301
+ const _private = new WeakMap();
302
+ class DynamicExtensionObject extends node_opcua_extension_object_1.ExtensionObject {
303
+ constructor(options, schema, factory) {
304
+ (0, node_opcua_assert_1.assert)(schema, "expecting a schema here ");
305
+ (0, node_opcua_assert_1.assert)(factory, "expecting a typeDic");
306
+ super(options);
307
+ options = options || {};
308
+ _private.set(this, { schema, factory });
309
+ (0, node_opcua_factory_1.check_options_correctness_against_schema)(this, this.schema, options);
310
+ initializeFields(this, options, this.schema, factory);
311
+ }
312
+ encode(stream) {
313
+ super.encode(stream);
314
+ encodeFields(this, this.schema, stream);
315
+ }
316
+ decode(stream) {
317
+ super.decode(stream);
318
+ decodeFields(this, this.schema, stream, _private.get(this).factory);
319
+ }
320
+ get schema() {
321
+ const r = _private.get(this);
322
+ return r.schema;
323
+ }
324
+ toJSON() {
325
+ const pojo = {};
326
+ encodeToJson(this, this.schema, pojo);
327
+ return pojo;
328
+ }
329
+ }
330
+ exports.DynamicExtensionObject = DynamicExtensionObject;
331
+ DynamicExtensionObject.schema = node_opcua_extension_object_1.ExtensionObject.schema;
332
+ DynamicExtensionObject.possibleFields = [];
333
+ // tslint:disable-next-line:max-classes-per-file
334
+ class UnionBaseClass extends node_opcua_factory_1.BaseUAObject {
335
+ // eslint-disable-next-line max-statements
336
+ constructor(options, schema, factory) {
337
+ super();
338
+ (0, node_opcua_assert_1.assert)(schema, "expecting a schema here ");
339
+ (0, node_opcua_assert_1.assert)(factory, "expecting a typeDic");
340
+ options = options || {};
341
+ _private.set(this, { schema });
342
+ (0, node_opcua_factory_1.check_options_correctness_against_schema)(this, this.schema, options);
343
+ let uniqueFieldHasBeenFound = false;
344
+ let switchFieldName = "";
345
+ // finding fields that are in options but not in schema!
346
+ for (const field of this.schema.fields) {
347
+ const name = field.name;
348
+ if (field.switchValue === undefined) {
349
+ // this is the switch value field
350
+ switchFieldName = field.name;
351
+ continue;
352
+ }
353
+ (0, node_opcua_assert_1.assert)(switchFieldName.length > 0, "It seems that there is no switch field in union schema");
354
+ (0, node_opcua_assert_1.assert)(field.switchValue !== undefined, "union schema must only have one switched value field");
355
+ // dealing with optional fields
356
+ /* istanbul ignore next */
357
+ if (uniqueFieldHasBeenFound && options[field.name] !== undefined) {
358
+ // let try to be helpful for the developper by providing some hint
359
+ debugLog(this.schema);
360
+ throw new Error("union must have only one choice in " +
361
+ JSON.stringify(options) +
362
+ "\n found while investigating " +
363
+ field.name +
364
+ "\n switchFieldName = " +
365
+ switchFieldName);
366
+ }
367
+ if (options[switchFieldName] !== undefined) {
368
+ // then options[switchFieldName] must equal
369
+ if (options[switchFieldName] !== field.switchValue) {
370
+ continue;
371
+ }
372
+ }
373
+ else {
374
+ // the is no switchFieldName , in this case the i
375
+ if (options[name] === undefined) {
376
+ continue;
377
+ }
378
+ }
379
+ uniqueFieldHasBeenFound = true;
380
+ this[switchFieldName] = field.switchValue;
381
+ switch (field.category) {
382
+ case node_opcua_factory_1.FieldCategory.complex: {
383
+ const constuctor = factory.getStructureTypeConstructor(field.fieldType);
384
+ // getOrCreateConstructor(field.fieldType, factory) || BaseUAObject;
385
+ if (field.isArray) {
386
+ this[name] = (options[name] || []).map((x) => (constuctor ? new constuctor(x) : null));
387
+ }
388
+ else {
389
+ this[name] = constuctor ? new constuctor(options[name]) : null;
390
+ }
391
+ // xx processStructuredType(fieldSchema);
392
+ break;
393
+ }
394
+ case node_opcua_factory_1.FieldCategory.enumeration:
395
+ case node_opcua_factory_1.FieldCategory.basic:
396
+ if (field.isArray) {
397
+ this[name] = (0, node_opcua_factory_1.initialize_field_array)(field, options[name]);
398
+ }
399
+ else {
400
+ this[name] = (0, node_opcua_factory_1.initialize_field)(field, options[name]);
401
+ }
402
+ break;
403
+ }
404
+ }
405
+ if (!uniqueFieldHasBeenFound) {
406
+ if (Object.keys(options).length === 0) {
407
+ this[switchFieldName] = 0x00;
408
+ return;
409
+ }
410
+ const r = schema.fields
411
+ .filter((f) => f.switchValue !== undefined)
412
+ .map((f) => f.name)
413
+ .join(" , ");
414
+ // it is possible also that the switchfield value do not correspond to a valid field
415
+ const foundFieldForSwitchValue = schema.fields.findIndex((f) => f.switchValue !== undefined && f.switchValue === options[switchFieldName]);
416
+ if (foundFieldForSwitchValue) {
417
+ // throw new Error(this.schema.name + ": cannot find field with value "
418
+ // + options[switchFieldName]);
419
+ }
420
+ else {
421
+ console.log(this.schema);
422
+ throw new Error(this.schema.name + ": At least one of [ " + r + " ] must be specified in " + JSON.stringify(options));
423
+ }
424
+ }
425
+ }
426
+ encode(stream) {
427
+ const switchFieldName = this.schema.fields[0].name;
428
+ const switchValue = this[switchFieldName];
429
+ if (typeof switchValue !== "number") {
430
+ throw new Error("Invalid switchValue " + switchFieldName + " value = " + switchValue);
431
+ }
432
+ stream.writeUInt32(switchValue);
433
+ for (const field of this.schema.fields) {
434
+ if (field.switchValue === undefined || field.switchValue !== switchValue) {
435
+ continue;
436
+ }
437
+ switch (field.category) {
438
+ case node_opcua_factory_1.FieldCategory.complex:
439
+ encodeArrayOrElement(field, this, stream);
440
+ break;
441
+ case node_opcua_factory_1.FieldCategory.enumeration:
442
+ case node_opcua_factory_1.FieldCategory.basic:
443
+ encodeArrayOrElement(field, this, stream, field.schema.encode);
444
+ break;
445
+ default:
446
+ /* istanbul ignore next*/
447
+ throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
448
+ }
449
+ break;
450
+ }
451
+ }
452
+ decode(stream) {
453
+ const factory = this.schema.$$factory;
454
+ const switchValue = stream.readUInt32();
455
+ const switchFieldName = this.schema.fields[0].name;
456
+ this[switchFieldName] = switchValue;
457
+ for (const field of this.schema.fields) {
458
+ if (field.switchValue === undefined || field.switchValue !== switchValue) {
459
+ continue;
460
+ }
461
+ switch (field.category) {
462
+ case node_opcua_factory_1.FieldCategory.complex:
463
+ decodeArrayOrElement(factory, field, this, stream);
464
+ break;
465
+ case node_opcua_factory_1.FieldCategory.enumeration:
466
+ case node_opcua_factory_1.FieldCategory.basic:
467
+ decodeArrayOrElement(factory, field, this, stream, field.schema.decode);
468
+ break;
469
+ default:
470
+ /* istanbul ignore next*/
471
+ throw new Error("Invalid category " + field.category + " " + node_opcua_factory_1.FieldCategory[field.category]);
472
+ }
473
+ break;
474
+ }
475
+ }
476
+ get schema() {
477
+ return _private.get(this).schema;
478
+ }
479
+ toString() {
480
+ return super.toString();
481
+ }
482
+ toJSON() {
483
+ const pojo = {};
484
+ const switchFieldName = this.schema.fields[0].name;
485
+ const switchValue = this[switchFieldName];
486
+ if (typeof switchValue !== "number") {
487
+ throw new Error("Invalid switchValue " + switchValue);
488
+ }
489
+ pojo[switchFieldName] = switchValue;
490
+ for (const field of this.schema.fields) {
491
+ if (field.switchValue === undefined || field.switchValue !== switchValue) {
492
+ continue;
493
+ }
494
+ const value = this[field.name];
495
+ if (value === undefined) {
496
+ continue;
497
+ }
498
+ pojo[field.name] = fieldToJSON(field, value);
499
+ break;
500
+ }
501
+ return pojo;
502
+ }
503
+ }
504
+ function _createDynamicUnionConstructor(schema, factory) {
505
+ const possibleFields = schema.fields.map((x) => x.name);
506
+ // tslint:disable-next-line:max-classes-per-file
507
+ class UNION extends UnionBaseClass {
508
+ constructor(options) {
509
+ super(options, schema, factory);
510
+ (0, node_opcua_assert_1.assert)(this.schema === schema);
511
+ }
512
+ }
513
+ UNION.possibleFields = possibleFields;
514
+ UNION.schema = schema;
515
+ // to do : may be remove DataType suffix here ?
516
+ Object.defineProperty(UNION, "name", { value: schema.name });
517
+ return UNION;
518
+ }
519
+ function createDynamicObjectConstructor(schema, dataTypeFactory) {
520
+ var _a;
521
+ const schemaPriv = schema;
522
+ if (schemaPriv.$Constructor) {
523
+ return schemaPriv.$Constructor;
524
+ }
525
+ const dataTypeNodeId = schemaPriv.id;
526
+ if (schema.baseType === "Union") {
527
+ const UNIONConstructor = _createDynamicUnionConstructor(schema, dataTypeFactory);
528
+ schemaPriv.$Constructor = UNIONConstructor;
529
+ dataTypeFactory.registerClassDefinition(dataTypeNodeId, schema.name, UNIONConstructor);
530
+ return UNIONConstructor;
531
+ }
532
+ let possibleFields = schema.fields.map((x) => x.name);
533
+ let BaseClass = DynamicExtensionObject;
534
+ if (schema.baseType !== "ExtensionObject" &&
535
+ schema.baseType !== "OptionSet" &&
536
+ schema.baseType !== "DataTypeDescription" &&
537
+ schema.baseType !== "DataTypeDefinition" &&
538
+ schema.baseType !== "EnumValueType" &&
539
+ schema.baseType !== "Structure") {
540
+ try {
541
+ const baseSchema = dataTypeFactory.getStructuredTypeSchema(schema.baseType);
542
+ schema._baseSchema = baseSchema;
543
+ if (((_a = baseSchema.encodingDefaultBinary) === null || _a === void 0 ? void 0 : _a.value) === 0) {
544
+ // is abstract
545
+ }
546
+ else {
547
+ BaseClass = getOrCreateConstructor(schema.baseType, dataTypeFactory);
548
+ if (!BaseClass) {
549
+ throw new Error("Cannot find base class : " + schema.baseType);
550
+ }
551
+ if (BaseClass.possibleFields) {
552
+ possibleFields = BaseClass.possibleFields.concat(possibleFields);
553
+ }
554
+ schema._baseSchema = BaseClass.schema;
555
+ }
556
+ }
557
+ catch (err) {
558
+ // xx console.log("createDynamicObjectConstructor err= ", err.message);
559
+ }
560
+ }
561
+ // tslint:disable-next-line:max-classes-per-file
562
+ class EXTENSION extends BaseClass {
563
+ constructor(options, schema2, factory2) {
564
+ super(options, schema2 ? schema2 : schema, factory2 ? factory2 : dataTypeFactory);
565
+ }
566
+ static get schema() {
567
+ return schema;
568
+ }
569
+ toString() {
570
+ return super.toString();
571
+ }
572
+ toJSON() {
573
+ const pojo = {};
574
+ encodeToJson(this, this.schema, pojo);
575
+ return pojo;
576
+ }
577
+ encode(stream) {
578
+ super.encode(stream);
579
+ }
580
+ decode(stream) {
581
+ super.decode(stream);
582
+ }
583
+ }
584
+ EXTENSION.encodingDefaultXml = new node_opcua_nodeid_1.ExpandedNodeId(node_opcua_nodeid_1.NodeIdType.NUMERIC, 0, 0);
585
+ EXTENSION.encodingDefaultBinary = new node_opcua_nodeid_1.ExpandedNodeId(node_opcua_nodeid_1.NodeIdType.NUMERIC, 0, 0);
586
+ EXTENSION.possibleFields = possibleFields;
587
+ // to do : may be remove DataType suffix here ?
588
+ Object.defineProperty(EXTENSION, "name", { value: schema.name });
589
+ schemaPriv.$Constructor = EXTENSION;
590
+ EXTENSION.encodingDefaultBinary = schema.encodingDefaultBinary;
591
+ dataTypeFactory.registerClassDefinition(dataTypeNodeId, schema.name, EXTENSION);
592
+ return EXTENSION;
593
+ }
594
+ exports.createDynamicObjectConstructor = createDynamicObjectConstructor;
595
595
  //# sourceMappingURL=dynamic_extension_object.js.map