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.
- package/dist/source/address_space_ts.d.ts +0 -2
- package/dist/source/helpers/argument_list.js +12 -1
- package/dist/source/helpers/argument_list.js.map +1 -1
- package/dist/source/loader/load_nodeset2.js +47 -64
- package/dist/source/loader/load_nodeset2.js.map +1 -1
- package/dist/source/set_namespace_meta_data.js +1 -1
- package/dist/src/address_space.js +8 -5
- package/dist/src/address_space.js.map +1 -1
- package/dist/src/alarms_and_conditions/condition_snapshot.js +3 -3
- package/dist/src/alarms_and_conditions/condition_snapshot.js.map +1 -1
- package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +1 -1
- package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
- package/dist/src/alarms_and_conditions/ua_condition_impl.js +8 -6
- package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
- package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js +1 -1
- package/dist/src/alarms_and_conditions/ua_off_normal_alarm_impl.js.map +1 -1
- package/dist/src/base_node_private.js +2 -2
- package/dist/src/base_node_private.js.map +1 -1
- package/dist/src/event_data.js +1 -1
- package/dist/src/event_data.js.map +1 -1
- package/dist/src/namespace_impl.js +5 -5
- package/dist/src/namespace_impl.js.map +1 -1
- package/dist/src/nodeset_tools/nodeset_to_xml.js +15 -9
- package/dist/src/nodeset_tools/nodeset_to_xml.js.map +1 -1
- package/dist/src/nodeset_tools/typedictionary_to_xml.js +17 -10
- package/dist/src/nodeset_tools/typedictionary_to_xml.js.map +1 -1
- package/dist/src/state_machine/ua_shelving_state_machine_ex.js +20 -13
- package/dist/src/state_machine/ua_shelving_state_machine_ex.js.map +1 -1
- package/dist/src/ua_data_type_impl.d.ts +15 -5
- package/dist/src/ua_data_type_impl.js +129 -51
- package/dist/src/ua_data_type_impl.js.map +1 -1
- package/dist/src/ua_variable_impl.d.ts +6 -6
- package/dist/src/ua_variable_impl.js +236 -188
- package/dist/src/ua_variable_impl.js.map +1 -1
- package/dist/src/ua_variable_type_impl.d.ts +3 -4
- package/dist/src/ua_variable_type_impl.js +13 -18
- package/dist/src/ua_variable_type_impl.js.map +1 -1
- package/distHelpers/mock_session.js +1 -1
- package/distHelpers/mock_session.js.map +1 -1
- package/package.json +35 -35
- package/source/address_space_ts.ts +0 -1
- package/source/helpers/argument_list.ts +13 -3
- package/source/loader/load_nodeset2.ts +64 -80
- package/source/set_namespace_meta_data.ts +1 -1
- package/src/address_space.ts +15 -9
- package/src/alarms_and_conditions/condition_snapshot.ts +4 -4
- package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +2 -2
- package/src/alarms_and_conditions/ua_condition_impl.ts +18 -8
- package/src/alarms_and_conditions/ua_off_normal_alarm_impl.ts +1 -1
- package/src/base_node_private.ts +6 -2
- package/src/event_data.ts +1 -1
- package/src/namespace_impl.ts +6 -6
- package/src/nodeset_tools/nodeset_to_xml.ts +20 -10
- package/src/nodeset_tools/typedictionary_to_xml.ts +17 -7
- package/src/state_machine/ua_shelving_state_machine_ex.ts +28 -16
- package/src/ua_data_type_impl.ts +168 -61
- package/src/ua_variable_impl.ts +290 -218
- package/src/ua_variable_type_impl.ts +9 -15
- package/test_helpers/mock_session.ts +1 -1
- package/test_helpers/test_fixtures/fixture_simple_statemachine_nodeset2.xml +9 -0
- 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 (
|
|
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 (
|
|
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
|
|
128
|
-
if (
|
|
129
|
-
|
|
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 (
|
|
132
|
-
dumpEnumeratedType(xw,
|
|
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
|
-
|
|
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(
|
|
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
|
|
297
|
-
|
|
298
|
-
value:
|
|
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
|
|
304
|
-
|
|
305
|
-
value:
|
|
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
|
|
310
|
-
|
|
311
|
-
value:
|
|
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
|
|
321
|
-
|
|
322
|
-
value:
|
|
328
|
+
return new DataValue({
|
|
329
|
+
statusCode: StatusCodes.Good,
|
|
330
|
+
value: {
|
|
331
|
+
dataType: DataType.Double, // duration
|
|
332
|
+
value: timeToAutomaticUnshelvedState
|
|
333
|
+
}
|
|
323
334
|
});
|
|
324
335
|
}
|
|
336
|
+
|
package/src/ua_data_type_impl.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 $
|
|
87
|
-
private $fullDefinition?:
|
|
92
|
+
private $partialDefinition?: StructureFieldOptions[] | EnumFieldOptions[];
|
|
93
|
+
private $fullDefinition?: StructureDefinition | EnumDefinition;
|
|
88
94
|
|
|
89
|
-
constructor(options:
|
|
95
|
+
constructor(options: UADataTypeOptions) {
|
|
90
96
|
super(options);
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
|
283
|
+
return this.$fullDefinition;
|
|
252
284
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
308
|
+
// merge them:
|
|
309
|
+
const definitionFields: StructureFieldOptions[] = [];
|
|
310
|
+
for (const dd of allPartialDefinitions.reverse()) {
|
|
311
|
+
definitionFields.push(...dd);
|
|
261
312
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
340
|
+
|
|
341
|
+
return this.$fullDefinition!;
|
|
297
342
|
}
|
|
343
|
+
|
|
298
344
|
public getDefinition(): DataTypeDefinition {
|
|
299
|
-
const d = this._getDefinition(
|
|
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(
|
|
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
|
+
*/
|