node-opcua-address-space 2.59.0 → 2.60.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.
Files changed (61) hide show
  1. package/dist/source/address_space_ts.d.ts +0 -2
  2. package/dist/source/helpers/argument_list.js +12 -1
  3. package/dist/source/helpers/argument_list.js.map +1 -1
  4. package/dist/source/loader/load_nodeset2.js +47 -64
  5. package/dist/source/loader/load_nodeset2.js.map +1 -1
  6. package/dist/source/set_namespace_meta_data.js +1 -1
  7. package/dist/src/address_space.js +8 -5
  8. package/dist/src/address_space.js.map +1 -1
  9. package/dist/src/alarms_and_conditions/condition_snapshot.js +3 -3
  10. package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -1
  11. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +1 -1
  12. package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
  13. package/dist/src/alarms_and_conditions/ua_condition_impl.js +8 -6
  14. package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
  15. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +1 -1
  16. package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
  17. package/dist/src/base_node_private.js +2 -2
  18. package/dist/src/base_node_private.js.map +1 -1
  19. package/dist/src/event_data.js +1 -1
  20. package/dist/src/event_data.js.map +1 -1
  21. package/dist/src/namespace_impl.js +5 -5
  22. package/dist/src/namespace_impl.js.map +1 -1
  23. package/dist/src/nodeset_tools/nodeset_to_xml.js +15 -9
  24. package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
  25. package/dist/src/nodeset_tools/typedictionary_to_xml.js +17 -10
  26. package/dist/src/nodeset_tools/typedictionary_to_xml.js.map +1 -1
  27. package/dist/src/state_machine/ua_shelving_state_machine_ex.js +20 -13
  28. package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
  29. package/dist/src/ua_data_type_impl.d.ts +15 -5
  30. package/dist/src/ua_data_type_impl.js +129 -51
  31. package/dist/src/ua_data_type_impl.js.map +1 -1
  32. package/dist/src/ua_variable_impl.d.ts +6 -6
  33. package/dist/src/ua_variable_impl.js +236 -188
  34. package/dist/src/ua_variable_impl.js.map +1 -1
  35. package/dist/src/ua_variable_type_impl.d.ts +3 -4
  36. package/dist/src/ua_variable_type_impl.js +13 -18
  37. package/dist/src/ua_variable_type_impl.js.map +1 -1
  38. package/distHelpers/mock_session.js +1 -1
  39. package/distHelpers/mock_session.js.map +1 -1
  40. package/package.json +35 -35
  41. package/source/address_space_ts.ts +0 -1
  42. package/source/helpers/argument_list.ts +13 -3
  43. package/source/loader/load_nodeset2.ts +64 -80
  44. package/source/set_namespace_meta_data.ts +1 -1
  45. package/src/address_space.ts +15 -9
  46. package/src/alarms_and_conditions/condition_snapshot.ts +4 -4
  47. package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +2 -2
  48. package/src/alarms_and_conditions/ua_condition_impl.ts +18 -8
  49. package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +1 -1
  50. package/src/base_node_private.ts +6 -2
  51. package/src/event_data.ts +1 -1
  52. package/src/namespace_impl.ts +6 -6
  53. package/src/nodeset_tools/nodeset_to_xml.ts +20 -10
  54. package/src/nodeset_tools/typedictionary_to_xml.ts +17 -7
  55. package/src/state_machine/ua_shelving_state_machine_ex.ts +28 -16
  56. package/src/ua_data_type_impl.ts +168 -61
  57. package/src/ua_variable_impl.ts +290 -218
  58. package/src/ua_variable_type_impl.ts +9 -15
  59. package/test_helpers/mock_session.ts +1 -1
  60. package/test_helpers/test_fixtures/fixture_simple_statemachine_nodeset2.xml +9 -0
  61. package/test_helpers/test_fixtures/mini.Node.Set2.xml +14 -0
@@ -44,6 +44,7 @@ function dumpDataTypeStructure(
44
44
  addressSpace: IAddressSpace,
45
45
  map: { [key: number]: string },
46
46
  structureDefinition: StructureDefinition,
47
+ structureDefinitionBase: StructureDefinition | undefined| null,
47
48
  name: string,
48
49
  doc?: string
49
50
  ): void {
@@ -56,8 +57,14 @@ function dumpDataTypeStructure(
56
57
  xw.text(doc);
57
58
  xw.endElement();
58
59
  }
60
+
61
+ const fields = structureDefinition.fields || [];
62
+ // get base class
63
+ const nbFieldsInBase = structureDefinitionBase? structureDefinitionBase.fields?.length || 0 : 0;
64
+
59
65
  let optionalsCount = 0;
60
- for (const f of structureDefinition.fields || []) {
66
+ for (let index = nbFieldsInBase; index < fields.length; index ++) {
67
+ const f= fields [index];
61
68
  if (f.isOptional) {
62
69
  xw.startElement("opc:Field");
63
70
  xw.writeAttribute("Name", f.name + "Specified");
@@ -90,7 +97,9 @@ function dumpDataTypeStructure(
90
97
  xw.endElement();
91
98
  }
92
99
  }
93
- for (const f of structureDefinition.fields || []) {
100
+ for (let index = nbFieldsInBase; index < fields.length; index ++) {
101
+ const f= fields [index];
102
+
94
103
  const isArray = f.valueRank > 0 && f.arrayDimensions?.length;
95
104
 
96
105
  if (isArray) {
@@ -124,12 +133,13 @@ function dumpDataTypeToBSD(xw: XmlWriter, dataType: UADataType, map: { [key: num
124
133
 
125
134
  const name: string = dataType.browseName.name!;
126
135
 
127
- const def = (<UADataTypeImpl>dataType)._getDefinition(false);
128
- if (def instanceof StructureDefinition) {
129
- dumpDataTypeStructure(xw, addressSpace, map, def, name);
136
+ const definition = dataType.getDefinition();
137
+ if (definition instanceof StructureDefinition) {
138
+ const structureDefinitionBase = dataType.subtypeOfObj?.getStructureDefinition();
139
+ dumpDataTypeStructure(xw, addressSpace, map, definition, structureDefinitionBase, name);
130
140
  }
131
- if (def instanceof EnumDefinition) {
132
- dumpEnumeratedType(xw, def, name);
141
+ if (definition instanceof EnumDefinition) {
142
+ dumpEnumeratedType(xw, definition, name);
133
143
  }
134
144
  }
135
145
 
@@ -7,13 +7,14 @@
7
7
  // --------------------------------------------------------------------------------------------------
8
8
 
9
9
  import { assert } from "node-opcua-assert";
10
- import { CallbackT, StatusCodes } from "node-opcua-status-code";
10
+ import { Callback, CallbackT, StatusCodes } from "node-opcua-status-code";
11
11
  import { DataType, Variant, VariantLike } from "node-opcua-variant";
12
12
 
13
13
  import { UAProperty, ISessionContext, UAMethod, UAObject } from "node-opcua-address-space-base";
14
14
  import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
15
15
  import { UAShelvedStateMachine_Base, UAState } from "node-opcua-nodeset-ua";
16
16
  import { CallMethodResultOptions } from "node-opcua-service-call";
17
+ import { DataValue } from "node-opcua-data-value";
17
18
 
18
19
  import { UAAlarmConditionImpl } from "../alarms_and_conditions/ua_alarm_condition_impl";
19
20
  import { UATransitionEx } from "../../source/interfaces/state_machine/ua_transition_ex";
@@ -76,7 +77,7 @@ export class UAShelvedStateMachineEx extends UAStateMachineImpl implements UAShe
76
77
  shelvingState.unshelveTime.minimumSamplingInterval = 500;
77
78
  shelvingState.unshelveTime.bindVariable(
78
79
  {
79
- get: _unShelveTimeFunc.bind(null, shelvingState)
80
+ timestamped_get: _unShelveTimeFunc.bind(null, shelvingState)
80
81
  },
81
82
  true
82
83
  );
@@ -189,7 +190,11 @@ function _start_timer_for_automatic_unshelve(shelvingState: UAShelvedStateMachin
189
190
  // a reset of the shelved timer.
190
191
  // BadShelvingTimeOutOfRange
191
192
 
192
- function _timedShelve_method(inputArguments: VariantLike[], context: ISessionContext, callback: CallbackT<CallMethodResultOptions>) {
193
+ function _timedShelve_method(
194
+ inputArguments: VariantLike[],
195
+ context: ISessionContext,
196
+ callback: CallbackT<CallMethodResultOptions>
197
+ ) {
193
198
  assert(inputArguments.length === 1);
194
199
  if (!context.object) {
195
200
  return;
@@ -291,24 +296,27 @@ function _oneShotShelve_method(
291
296
  // TimedShelve Method call.
292
297
  // * For the OneShotShelved state the UnshelveTime will be a constant set to the maximum Duration
293
298
  // except if a MaxTimeShelved Property is provided.
294
- function _unShelveTimeFunc(shelvingState: UAShelvedStateMachineEx) {
299
+ function _unShelveTimeFunc(shelvingState: UAShelvedStateMachineEx): DataValue {
295
300
  if (shelvingState.getCurrentState() === "Unshelved") {
296
- return new Variant({
297
- dataType: DataType.StatusCode,
298
- value: StatusCodes.BadConditionNotShelved
301
+ return new DataValue({
302
+ statusCode: StatusCodes.BadConditionNotShelved,
303
+ value: { dataType: DataType.Double, value: 0 }
299
304
  });
300
305
  }
301
306
 
302
307
  if (!shelvingState._sheveldTime) {
303
- return new Variant({
304
- dataType: DataType.StatusCode,
305
- value: StatusCodes.BadConditionNotShelved
308
+ return new DataValue({
309
+ statusCode: StatusCodes.BadConditionNotShelved,
310
+ value: { dataType: DataType.Double, value: 0 }
306
311
  });
307
312
  }
308
313
  if (shelvingState.getCurrentState() === "OneShotShelved" && shelvingState._duration === UAAlarmConditionImpl.MaxDuration) {
309
- return new Variant({
310
- dataType: DataType.Double,
311
- value: UAAlarmConditionImpl.MaxDuration
314
+ return new DataValue({
315
+ statusCode: StatusCodes.Good,
316
+ value: {
317
+ dataType: DataType.Double,
318
+ value: UAAlarmConditionImpl.MaxDuration
319
+ }
312
320
  });
313
321
  }
314
322
  const now = new Date();
@@ -317,8 +325,12 @@ function _unShelveTimeFunc(shelvingState: UAShelvedStateMachineEx) {
317
325
 
318
326
  // timeToAutomaticUnshelvedState should always be greater than (or equal) zero
319
327
  timeToAutomaticUnshelvedState = Math.max(timeToAutomaticUnshelvedState, 0);
320
- return new Variant({
321
- dataType: DataType.Double, // duration
322
- value: timeToAutomaticUnshelvedState
328
+ return new DataValue({
329
+ statusCode: StatusCodes.Good,
330
+ value: {
331
+ dataType: DataType.Double, // duration
332
+ value: timeToAutomaticUnshelvedState
333
+ }
323
334
  });
324
335
  }
336
+
@@ -5,19 +5,28 @@ import * as chalk from "chalk";
5
5
 
6
6
  import { assert } from "node-opcua-assert";
7
7
  import { NodeClass, QualifiedNameLike } from "node-opcua-data-model";
8
- import { StructuredTypeSchema } from "node-opcua-factory";
8
+ import { EnumerationDefinition, StructuredTypeSchema } from "node-opcua-factory";
9
9
  import { AttributeIds } from "node-opcua-data-model";
10
10
  import { DataValue, DataValueLike } from "node-opcua-data-value";
11
11
  import { ExtensionObject } from "node-opcua-extension-object";
12
12
  import { ExpandedNodeId, NodeId } from "node-opcua-nodeid";
13
13
  import { NumericRange } from "node-opcua-numeric-range";
14
14
  import { StatusCodes } from "node-opcua-status-code";
15
- import { DataTypeDefinition, StructureDefinition, StructureField } from "node-opcua-types";
15
+ import {
16
+ DataTypeDefinition,
17
+ EnumDefinition,
18
+ EnumFieldOptions,
19
+ StructureDefinition,
20
+ StructureField,
21
+ StructureFieldOptions,
22
+ StructureType
23
+ } from "node-opcua-types";
16
24
  import { DataType } from "node-opcua-variant";
17
- import { UAObject, ISessionContext, UADataType, UAVariable, BaseNode } from "node-opcua-address-space-base";
25
+ import { UAObject, ISessionContext, UADataType, UAVariable, BaseNode, CreateDataTypeOptions } from "node-opcua-address-space-base";
26
+ import { DataTypeIds } from "node-opcua-constants";
18
27
 
19
28
  import { SessionContext } from "../source/session_context";
20
- import { BaseNodeImpl } from "./base_node_impl";
29
+ import { BaseNodeImpl, InternalBaseNodeOptions } from "./base_node_impl";
21
30
  import { BaseNode_References_toString, BaseNode_toString, ToStringBuilder, ToStringOption } from "./base_node_private";
22
31
  import * as tools from "./tool_isSupertypeOf";
23
32
  import { get_subtypeOf } from "./tool_isSupertypeOf";
@@ -44,13 +53,10 @@ export interface EnumerationInfo {
44
53
  nameIndex: { [id: string]: IEnumItem };
45
54
  valueIndex: { [id: number]: IEnumItem };
46
55
  }
47
-
48
- function findBasicDataType(dataType: UADataType): DataType {
49
- if (dataType.nodeId.namespace === 0 && dataType.nodeId.value <= 25) {
50
- // we have a well-known DataType
51
- return dataType.nodeId.value as DataType;
52
- }
53
- return findBasicDataType(dataType.subtypeOfObj as UADataType);
56
+ export interface UADataTypeOptions extends InternalBaseNodeOptions {
57
+ partialDefinition: StructureFieldOptions[] | EnumFieldOptions[];
58
+ isAbstract?: boolean;
59
+ symbolicName?: string;
54
60
  }
55
61
 
56
62
  export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
@@ -83,18 +89,23 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
83
89
 
84
90
  private enumStrings?: any;
85
91
  private enumValues?: any;
86
- private $definition?: DataTypeDefinition;
87
- private $fullDefinition?: DataTypeDefinition;
92
+ private $partialDefinition?: StructureFieldOptions[] | EnumFieldOptions[];
93
+ private $fullDefinition?: StructureDefinition | EnumDefinition;
88
94
 
89
- constructor(options: any) {
95
+ constructor(options: UADataTypeOptions) {
90
96
  super(options);
91
- this.$definition = options.$definition;
92
- this.isAbstract = options.isAbstract === null ? false : options.isAbstract;
97
+ if (options.partialDefinition) {
98
+ this.$partialDefinition = options.partialDefinition;
99
+ }
100
+ this.isAbstract = options.isAbstract === undefined || options.isAbstract === null ? false : options.isAbstract;
93
101
  this.symbolicName = options.symbolicName || this.browseName.name!;
94
102
  }
95
103
 
96
104
  public get basicDataType(): DataType {
97
- return findBasicDataType(this);
105
+ return this.getBasicDataType();
106
+ }
107
+ public getBasicDataType(): DataType {
108
+ return this.addressSpace.findCorrespondingBasicDataType(this);
98
109
  }
99
110
 
100
111
  public readAttribute(
@@ -113,7 +124,7 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
113
124
  break;
114
125
  case AttributeIds.DataTypeDefinition:
115
126
  {
116
- const _definition = this._getDefinition(true);
127
+ const _definition = this._getDefinition()?.clone();
117
128
  if (_definition !== null) {
118
129
  options.value = { dataType: DataType.ExtensionObject, value: _definition };
119
130
  } else {
@@ -246,57 +257,92 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
246
257
  return indexes;
247
258
  }
248
259
 
249
- public _getDefinition(mergeWithBase: boolean): DataTypeDefinition | null {
260
+ isStructure(): boolean {
261
+ const definition = this._getDefinition();
262
+ return definition instanceof StructureDefinition;
263
+ }
264
+ getStructureDefinition(): StructureDefinition {
265
+ const definition = this._getDefinition();
266
+ assert(definition instanceof StructureDefinition);
267
+ return definition as StructureDefinition;
268
+ }
269
+
270
+ isEnumeration(): boolean {
271
+ const definition = this._getDefinition();
272
+ return definition instanceof EnumDefinition;
273
+ }
274
+ getEnumDefinition(): EnumDefinition {
275
+ const definition = this._getDefinition();
276
+ assert(definition instanceof EnumDefinition);
277
+ return definition as EnumDefinition;
278
+ }
279
+
280
+ // eslint-disable-next-line complexity
281
+ public _getDefinition(): DataTypeDefinition | null {
250
282
  if (this.$fullDefinition !== undefined) {
251
- return mergeWithBase ? this.$fullDefinition : this.$definition!;
283
+ return this.$fullDefinition;
252
284
  }
253
- if (!this.$definition) {
254
- const structure = this.addressSpace.findDataType("Structure")!;
255
- if (!structure) {
256
- return null;
285
+ const addressSpace = this.addressSpace;
286
+ const enumeration = addressSpace.findDataType("Enumeration");
287
+ const structure = addressSpace.findDataType("Structure");
288
+ const union = addressSpace.findDataType("Union");
289
+
290
+ // we have a data type from a companion specification
291
+ // let's see if this data type need to be registered
292
+ const isEnumeration = enumeration && this.isSupertypeOf(enumeration);
293
+ const isStructure = structure && this.isSupertypeOf(structure);
294
+ const isUnion = !!(structure && union && this.isSupertypeOf(union));
295
+
296
+ const isRootDataType = (n: UADataType) => n.nodeId.namespace === 0 && n.nodeId.value === DataTypeIds.BaseDataType;
297
+ // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.49/#Table34
298
+ if (isStructure) {
299
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
300
+ let dataTypeNode: UADataTypeImpl | null = this;
301
+ const allPartialDefinitions: StructureFieldOptions[][] = [];
302
+ while (dataTypeNode && !isRootDataType(dataTypeNode)) {
303
+ if (dataTypeNode.$partialDefinition) {
304
+ allPartialDefinitions.push(dataTypeNode.$partialDefinition as StructureFieldOptions[]);
305
+ }
306
+ dataTypeNode = dataTypeNode.subtypeOfObj as UADataTypeImpl | null;
257
307
  }
258
- if (this.isSupertypeOf(structure)) {
259
- // <Definition> tag was missing in XML file as it was empty
260
- this.$definition = new StructureDefinition({});
308
+ // merge them:
309
+ const definitionFields: StructureFieldOptions[] = [];
310
+ for (const dd of allPartialDefinitions.reverse()) {
311
+ definitionFields.push(...dd);
261
312
  }
262
- }
263
-
264
- // https://reference.opcfoundation.org/v104/Core/docs/Part3/8.49/#Table34
265
- // The list of fields that make up the data type.
266
- // This definition assumes the structure has a sequential layout.
267
- // The StructureField DataType is defined in 8.51.
268
- // For Structures derived from another Structure DataType this list shall begin with the fields
269
- // of the baseDataType followed by the fields of this StructureDefinition.
270
-
271
- // from OPC Unified Architecture, Part 6 86 Release 1.04
272
- // A DataTypeDefinition defines an abstract representation of _a UADataType that can be used by
273
- // design tools to automatically create serialization code. The fields in the DataTypeDefinition type
274
- // are defined in Table F.12.
275
- const _definition = this.$definition || null;
276
- if (_definition && _definition instanceof StructureDefinition && this.binaryEncodingNodeId) {
277
- _definition.defaultEncodingId = this.binaryEncodingNodeId!;
278
- const subtype = this.subtypeOf;
279
- if (subtype) {
280
- _definition.baseDataType = subtype;
313
+ const basicDataType = this.subtypeOfObj?.nodeId || new NodeId();
314
+ const defaultEncodingId = this.binaryEncodingNodeId || this.xmlEncodingNodeId || new NodeId();
315
+ const definitionName = this.browseName.name!;
316
+ this.$fullDefinition = makeStructureDefinition(
317
+ definitionName,
318
+ basicDataType,
319
+ defaultEncodingId,
320
+ definitionFields,
321
+ isUnion
322
+ );
323
+ } else if (isEnumeration) {
324
+ const allPartialDefinitions: StructureFieldOptions[][] = [];
325
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
326
+ let dataTypeNode: UADataTypeImpl | null = this;
327
+ while (dataTypeNode && !isRootDataType(dataTypeNode)) {
328
+ if (dataTypeNode.$partialDefinition) {
329
+ allPartialDefinitions.push(dataTypeNode.$partialDefinition as StructureFieldOptions[]);
330
+ }
331
+ dataTypeNode = dataTypeNode.subtypeOfObj as UADataTypeImpl | null;
281
332
  }
282
- }
283
- this.$fullDefinition = this.$definition?.clone();
284
-
285
- let _baseDefinition: DataTypeDefinition | null = null;
286
- if (this.subtypeOfObj) {
287
- _baseDefinition = (this.subtypeOfObj as UADataTypeImpl)._getDefinition(mergeWithBase);
288
- }
289
- if (this.$fullDefinition && this.$definition instanceof StructureDefinition && _baseDefinition) {
290
- const b = _baseDefinition as StructureDefinition;
291
- if (b.fields?.length) {
292
- const f = this.$fullDefinition as StructureDefinition;
293
- f.fields = (<StructureField[]>[]).concat(b.fields!, f.fields!);
333
+ // merge them:
334
+ const definitionFields: StructureFieldOptions[] = [];
335
+ for (const dd of allPartialDefinitions.reverse()) {
336
+ definitionFields.push(...dd);
294
337
  }
338
+ this.$fullDefinition = makeEnumDefinition(definitionFields);
295
339
  }
296
- return mergeWithBase ? this.$fullDefinition || null : this.$definition || null;
340
+
341
+ return this.$fullDefinition!;
297
342
  }
343
+
298
344
  public getDefinition(): DataTypeDefinition {
299
- const d = this._getDefinition(true);
345
+ const d = this._getDefinition();
300
346
  if (!d) {
301
347
  throw new Error("DataType has no definition property");
302
348
  }
@@ -315,7 +361,7 @@ export class UADataTypeImpl extends BaseNodeImpl implements UADataType {
315
361
  }
316
362
 
317
363
  function dataTypeDefinition_toString(this: UADataTypeImpl, options: ToStringOption) {
318
- const definition = this._getDefinition(false);
364
+ const definition = this._getDefinition();
319
365
  if (!definition) {
320
366
  return;
321
367
  }
@@ -354,3 +400,64 @@ export function DataType_toString(this: UADataTypeImpl, options: ToStringOption)
354
400
 
355
401
  dataTypeDefinition_toString.call(this, options);
356
402
  }
403
+
404
+ function makeEnumDefinition(definitionFields: EnumFieldOptions[]) {
405
+ return new EnumDefinition({
406
+ fields: definitionFields.map((x) => ({
407
+ description: x.description,
408
+ name: x.name,
409
+ value: x.value
410
+ }))
411
+ });
412
+ }
413
+ function makeStructureDefinition(
414
+ name: string,
415
+ baseDataType: NodeId,
416
+ defaultEncodingId: NodeId,
417
+ fields: StructureFieldOptions[],
418
+ isUnion: boolean
419
+ ): StructureDefinition {
420
+ // Structure = 0,
421
+ // StructureWithOptionalFields = 1,
422
+ // Union = 2,
423
+ const hasOptionalFields = fields.filter((field) => field.isOptional).length > 0;
424
+
425
+ const structureType = isUnion
426
+ ? StructureType.Union
427
+ : hasOptionalFields
428
+ ? StructureType.StructureWithOptionalFields
429
+ : StructureType.Structure;
430
+
431
+ const sd = new StructureDefinition({
432
+ baseDataType,
433
+ defaultEncodingId,
434
+ fields,
435
+ structureType
436
+ });
437
+ return sd;
438
+ }
439
+
440
+ /*
441
+ function lockReadOnlyWithWriteDetection<T>(obj: T): T {
442
+ if (obj instanceof Array) {
443
+ return obj.map(lockReadOnlyWithWriteDetection) as unknown as T;
444
+ }
445
+ if (obj instanceof Object) {
446
+ const _org = obj;
447
+ for (const [key, value] of Object.entries(obj)) {
448
+ lockReadOnlyWithWriteDetection(value);
449
+ }
450
+ obj = new Proxy(obj, {
451
+ get: (target: any, prop: string) => {
452
+ return target[prop];
453
+ },
454
+ set: (target: any, prop: string | symbol, value: any, receiver: any) => {
455
+ console.log("QQQQQ Cannot modify stuff ");
456
+ debugger;
457
+ throw new Error("Invalid");
458
+ }
459
+ });
460
+ }
461
+ return obj;
462
+ }
463
+ */