node-opcua-address-space 2.167.0 → 2.169.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/loader/namespace_post_step.js +25 -17
- package/dist/source/loader/namespace_post_step.js.map +1 -1
- package/dist/source/session_context.d.ts +3 -1
- package/dist/source/session_context.js +26 -1
- package/dist/source/session_context.js.map +1 -1
- package/dist/src/address_space.d.ts +14 -11
- package/dist/src/address_space.js +55 -54
- package/dist/src/address_space.js.map +1 -1
- package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.d.ts +8 -8
- package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js +19 -19
- package/dist/src/alarms_and_conditions/ua_alarm_condition_impl.js.map +1 -1
- package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.d.ts +11 -13
- package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js +21 -13
- package/dist/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.js.map +1 -1
- package/dist/src/alarms_and_conditions/ua_condition_impl.js +1 -1
- package/dist/src/alarms_and_conditions/ua_condition_impl.js.map +1 -1
- package/dist/src/base_node_impl.d.ts +1 -0
- package/dist/src/base_node_impl.js +26 -15
- package/dist/src/base_node_impl.js.map +1 -1
- package/dist/src/namespace_impl.d.ts +40 -31
- package/dist/src/namespace_impl.js +174 -161
- package/dist/src/namespace_impl.js.map +1 -1
- package/dist/src/namespace_private.d.ts +12 -4
- package/dist/src/namespace_private.js +1 -4
- package/dist/src/namespace_private.js.map +1 -1
- package/dist/src/ua_method_impl.d.ts +11 -9
- package/dist/src/ua_method_impl.js +24 -27
- package/dist/src/ua_method_impl.js.map +1 -1
- package/dist/tsconfig_base.tsbuildinfo +1 -1
- package/package.json +35 -37
- package/source/loader/namespace_post_step.ts +28 -19
- package/source/session_context.ts +30 -1
- package/src/address_space.ts +113 -109
- package/src/alarms_and_conditions/ua_alarm_condition_impl.ts +26 -28
- package/src/alarms_and_conditions/ua_certificate_expiration_alarm_impl.ts +33 -27
- package/src/alarms_and_conditions/ua_condition_impl.ts +1 -1
- package/src/base_node_impl.ts +27 -14
- package/src/namespace_impl.ts +232 -201
- package/src/namespace_private.ts +15 -9
- package/src/ua_method_impl.ts +43 -50
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module node-opcua-address-space.AlarmsAndConditions
|
|
3
3
|
*/
|
|
4
|
-
import { isEqual } from "
|
|
5
|
-
|
|
4
|
+
import { isDeepStrictEqual as isEqual } from "node:util";
|
|
5
|
+
import type { BaseNode, INamespace, UAEventType, UAVariable } from "node-opcua-address-space-base";
|
|
6
6
|
import { assert } from "node-opcua-assert";
|
|
7
7
|
import { NodeClass } from "node-opcua-data-model";
|
|
8
|
-
import { DataValue } from "node-opcua-data-value";
|
|
8
|
+
import type { DataValue } from "node-opcua-data-value";
|
|
9
|
+
import { make_debugLog } from "node-opcua-debug";
|
|
9
10
|
import { NodeId, sameNodeId } from "node-opcua-nodeid";
|
|
10
11
|
import { StatusCodes } from "node-opcua-status-code";
|
|
11
|
-
import { DataType, VariantOptions } from "node-opcua-variant";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
12
|
+
import { DataType, type VariantOptions } from "node-opcua-variant";
|
|
13
|
+
import type { ConditionInfo } from "../../source/interfaces/alarms_and_conditions/condition_info_i";
|
|
14
|
+
import type { InstantiateAlarmConditionOptions } from "../../source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options";
|
|
15
|
+
import type { UAAlarmConditionEx } from "../../source/interfaces/alarms_and_conditions/ua_alarm_condition_ex";
|
|
16
|
+
import type { AddressSpacePrivate } from "../address_space_private";
|
|
17
|
+
import { _clear_timer_if_any, UAShelvedStateMachineExImpl } from "../state_machine/ua_shelving_state_machine_ex";
|
|
15
18
|
import { _install_TwoStateVariable_machinery } from "../state_machine/ua_two_state_variable";
|
|
16
|
-
import { UAShelvedStateMachineExImpl, _clear_timer_if_any } from "../state_machine/ua_shelving_state_machine_ex";
|
|
17
|
-
import { AddressSpacePrivate } from "../address_space_private";
|
|
18
|
-
import { ConditionInfo } from "../../source/interfaces/alarms_and_conditions/condition_info_i";
|
|
19
|
-
import { UAAlarmConditionEx } from "../../source/interfaces/alarms_and_conditions/ua_alarm_condition_ex";
|
|
20
|
-
import { InstantiateAlarmConditionOptions } from "../../source/interfaces/alarms_and_conditions/instantiate_alarm_condition_options";
|
|
21
19
|
|
|
22
20
|
import { ConditionInfoImpl } from "./condition_info_impl";
|
|
23
21
|
import { UAAcknowledgeableConditionImpl } from "./ua_acknowledgeable_condition_impl";
|
|
@@ -35,7 +33,7 @@ export declare interface UAAlarmConditionImpl extends UAAlarmConditionEx, UAAckn
|
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl implements UAAlarmConditionEx {
|
|
38
|
-
public static MaxDuration =
|
|
36
|
+
public static MaxDuration = 2 ** 31;
|
|
39
37
|
|
|
40
38
|
public static instantiate(
|
|
41
39
|
namespace: INamespace,
|
|
@@ -45,12 +43,12 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
45
43
|
): UAAlarmConditionImpl {
|
|
46
44
|
const addressSpace = namespace.addressSpace;
|
|
47
45
|
// xx assert(Object.prototype.hasOwnProperty.call(options,"conditionOf")); // must provide a conditionOf
|
|
48
|
-
assert(Object.
|
|
46
|
+
assert(Object.hasOwn(options, "inputNode")); // must provide a inputNode
|
|
49
47
|
const alarmConditionType = addressSpace.findEventType(alarmConditionTypeId);
|
|
50
48
|
|
|
51
49
|
/* c8 ignore next */
|
|
52
50
|
if (!alarmConditionType) {
|
|
53
|
-
throw new Error(
|
|
51
|
+
throw new Error(` cannot find Alarm Condition Type for ${alarmConditionTypeId}`);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
const alarmConditionTypeBase = addressSpace.findEventType("AlarmConditionType");
|
|
@@ -60,9 +58,9 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
options.optionals = options.optionals || [];
|
|
63
|
-
if (Object.
|
|
61
|
+
if (Object.hasOwn(options, "maxTimeShelved")) {
|
|
64
62
|
options.optionals.push("MaxTimeShelved");
|
|
65
|
-
assert(isFinite(options.maxTimeShelved!));
|
|
63
|
+
assert(Number.isFinite(options.maxTimeShelved!));
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
assert(alarmConditionTypeBase === alarmConditionType || alarmConditionType.isSubtypeOf(alarmConditionTypeBase));
|
|
@@ -142,12 +140,12 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
142
140
|
*
|
|
143
141
|
*/
|
|
144
142
|
if (alarmNode.suppressedState) {
|
|
145
|
-
alarmNode.suppressedState.on("value_changed", (
|
|
143
|
+
alarmNode.suppressedState.on("value_changed", (_newDataValue: DataValue) => {
|
|
146
144
|
_update_suppressedOrShelved(alarmNode);
|
|
147
145
|
});
|
|
148
146
|
}
|
|
149
147
|
if (alarmNode.shelvingState) {
|
|
150
|
-
alarmNode.shelvingState.currentState.on("value_changed", (
|
|
148
|
+
alarmNode.shelvingState.currentState.on("value_changed", (_newDataValue: DataValue) => {
|
|
151
149
|
_update_suppressedOrShelved(alarmNode);
|
|
152
150
|
});
|
|
153
151
|
}
|
|
@@ -220,7 +218,7 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
220
218
|
public isSuppressedOrShelved(): boolean {
|
|
221
219
|
let suppressed = false;
|
|
222
220
|
if (this.suppressedState) {
|
|
223
|
-
suppressed = this.suppressedState.id
|
|
221
|
+
suppressed = this.suppressedState.id?.readValue().value.value;
|
|
224
222
|
}
|
|
225
223
|
let shelved = false;
|
|
226
224
|
if (this.shelvingState) {
|
|
@@ -241,8 +239,8 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
241
239
|
* note: duration must be greater than 10ms and lesser than 2**31 ms
|
|
242
240
|
*/
|
|
243
241
|
public setMaxTimeShelved(duration: number): void {
|
|
244
|
-
if (duration < 10 || duration >=
|
|
245
|
-
throw new Error(
|
|
242
|
+
if (duration < 10 || duration >= 2 ** 31) {
|
|
243
|
+
throw new Error(` Invalid maxTimeShelved duration: ${duration} must be [10,2**31] `);
|
|
246
244
|
}
|
|
247
245
|
this.maxTimeShelved?.setValueFromSource({
|
|
248
246
|
dataType: "Duration", // <= Duration is basic Type Double! ( milliseconds)
|
|
@@ -280,7 +278,7 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
280
278
|
return this.addressSpace.findNode(nodeId) as UAVariable | null;
|
|
281
279
|
}
|
|
282
280
|
/**
|
|
283
|
-
*
|
|
281
|
+
*
|
|
284
282
|
*/
|
|
285
283
|
public getInputNodeValue(): any | null {
|
|
286
284
|
const node = this.getInputNodeNode();
|
|
@@ -297,7 +295,7 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
297
295
|
this._onInputDataValueChange(dataValue);
|
|
298
296
|
}
|
|
299
297
|
|
|
300
|
-
protected _onInputDataValueChange(
|
|
298
|
+
protected _onInputDataValueChange(_newValue: DataValue): void {
|
|
301
299
|
/** */
|
|
302
300
|
}
|
|
303
301
|
|
|
@@ -397,9 +395,9 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
397
395
|
*/
|
|
398
396
|
public _calculateConditionInfo(
|
|
399
397
|
stateData: string | null,
|
|
400
|
-
|
|
398
|
+
_isActive: boolean,
|
|
401
399
|
value: string,
|
|
402
|
-
|
|
400
|
+
_oldCondition: ConditionInfo
|
|
403
401
|
): ConditionInfo {
|
|
404
402
|
if (!stateData) {
|
|
405
403
|
return new ConditionInfoImpl({
|
|
@@ -410,7 +408,7 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
410
408
|
});
|
|
411
409
|
} else {
|
|
412
410
|
return new ConditionInfoImpl({
|
|
413
|
-
message:
|
|
411
|
+
message: `Condition is ${value} and state is ${stateData}`,
|
|
414
412
|
quality: StatusCodes.Good,
|
|
415
413
|
retain: true,
|
|
416
414
|
severity: 150
|
|
@@ -441,7 +439,7 @@ export class UAAlarmConditionImpl extends UAAcknowledgeableConditionImpl impleme
|
|
|
441
439
|
debugLog("oldConditionInfo", oldConditionInfo);
|
|
442
440
|
debugLog("oldConditionInfo", newConditionInfo);
|
|
443
441
|
throw new Error(
|
|
444
|
-
|
|
442
|
+
`condition values have not change, shall we really raise an event ? alarm ${this.browseName.toString()}`
|
|
445
443
|
);
|
|
446
444
|
}
|
|
447
445
|
assert(!isEqual(oldConditionInfo, newConditionInfo), "condition values have not change, shall we really raise an event ?");
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module node-opcua-address-space.AlarmsAndConditions
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { NodeId } from "node-opcua-nodeid";
|
|
8
|
-
import { DataType, Variant, VariantOptions } from "node-opcua-variant";
|
|
9
|
-
import { INamespace, UAObject, UAProperty, UAVariable } from "node-opcua-address-space-base";
|
|
4
|
+
|
|
5
|
+
import type { INamespace, UAObject, UAProperty, UAVariable } from "node-opcua-address-space-base";
|
|
6
|
+
import { type DateTime, getMinOPCUADate, isMinDate, StatusCodes } from "node-opcua-basic-types";
|
|
10
7
|
import { ObjectTypeIds } from "node-opcua-constants";
|
|
8
|
+
import { type Certificate, exploreCertificate, makeSHA1Thumbprint } from "node-opcua-crypto/web";
|
|
11
9
|
import { makeAccessLevelExFlag } from "node-opcua-data-model";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { make_warningLog } from "node-opcua-debug";
|
|
11
|
+
import type { NodeId } from "node-opcua-nodeid";
|
|
12
|
+
import { DataType } from "node-opcua-variant";
|
|
13
|
+
import type { InstantiateOffNormalAlarmOptions } from "../../source/interfaces/alarms_and_conditions/instantiate_off_normal_alarm_options";
|
|
14
|
+
import type { UACertificateExpirationAlarmEx } from "../../source/interfaces/alarms_and_conditions/ua_certificate_expiration_alarm_ex";
|
|
14
15
|
import { registerNodePromoter } from "../../source/loader/register_node_promoter";
|
|
15
16
|
import { UASystemOffNormalAlarmImpl } from "./ua_system_off_normal_alarm_impl";
|
|
16
17
|
|
|
@@ -18,7 +19,7 @@ const warningLog = make_warningLog("AlarmsAndConditions");
|
|
|
18
19
|
|
|
19
20
|
const ellipsis = (arg0: string, arg1 = 4) => {
|
|
20
21
|
arg1 = Math.max(arg1, 4);
|
|
21
|
-
return arg0.length <= arg1 ? arg0 : arg0.slice(0, arg1 / 2)
|
|
22
|
+
return arg0.length <= arg1 ? arg0 : `${arg0.slice(0, arg1 / 2)}...${arg0.slice(arg0.length - arg1 / 2)}`;
|
|
22
23
|
};
|
|
23
24
|
const d = (d: Date) => {
|
|
24
25
|
return d.toISOString();
|
|
@@ -31,24 +32,22 @@ export function instantiateCertificateExpirationAlarm(
|
|
|
31
32
|
return UACertificateExpirationAlarmImpl.instantiate(namespace, alarmType, options);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
interface UACertificateExpirationAlarmImpl {
|
|
35
|
-
expirationDate: UAProperty<Date, /*z*/ DataType.DateTime>;
|
|
36
|
-
expirationLimit?: UAProperty<number, /*z*/ DataType.Double>;
|
|
37
|
-
certificateType: UAProperty<NodeId, /*z*/ DataType.NodeId>;
|
|
38
|
-
certificate: UAProperty<Buffer, /*z*/ DataType.ByteString>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
35
|
// This Simple DataType is a Double that defines an interval of time in milliseconds (fractions can be used to define sub-millisecond values).
|
|
42
36
|
// Negative values are generally invalid but may have special meanings where the Duration is used.
|
|
43
37
|
export const OneDayDuration = 1000 * 60 * 60 * 24;
|
|
44
38
|
export const TwoWeeksDuration = OneDayDuration * 2 * 7;
|
|
45
39
|
|
|
46
40
|
/**
|
|
47
|
-
* This UACertificateExpirationAlarm (SystemOffNormalAlarmType) is raised by the Server when the Server
|
|
41
|
+
* This UACertificateExpirationAlarm (SystemOffNormalAlarmType) is raised by the Server when the Server's
|
|
48
42
|
* Certificate is within the ExpirationLimit
|
|
49
43
|
* of expiration. This alarm automatically returns to normal when the certificate is updated.
|
|
50
44
|
*/
|
|
51
45
|
class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implements UACertificateExpirationAlarmEx {
|
|
46
|
+
declare expirationDate: UAProperty<Date, DataType.DateTime>;
|
|
47
|
+
declare expirationLimit: UAProperty<number, DataType.Double> | undefined;
|
|
48
|
+
declare certificateType: UAProperty<NodeId, DataType.NodeId>;
|
|
49
|
+
declare certificate: UAProperty<Buffer, DataType.ByteString>;
|
|
50
|
+
|
|
52
51
|
private timer: NodeJS.Timeout | null = null;
|
|
53
52
|
|
|
54
53
|
public static instantiate(
|
|
@@ -57,7 +56,6 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
57
56
|
options: InstantiateOffNormalAlarmOptions
|
|
58
57
|
// data?: Record<string, VariantOptions>
|
|
59
58
|
): UACertificateExpirationAlarmImpl {
|
|
60
|
-
|
|
61
59
|
const alarm = UASystemOffNormalAlarmImpl.instantiate(
|
|
62
60
|
namespace,
|
|
63
61
|
alarmType || "CertificateExpirationAlarmType",
|
|
@@ -78,7 +76,7 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
78
76
|
this.raiseNewCondition({
|
|
79
77
|
message,
|
|
80
78
|
quality: StatusCodes.Good,
|
|
81
|
-
retain: isActive
|
|
79
|
+
retain: !!isActive,
|
|
82
80
|
severity
|
|
83
81
|
});
|
|
84
82
|
}
|
|
@@ -92,7 +90,7 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
92
90
|
warningLog(`expiry alarm ${this.nodeId.toString()} has no enabledState property`);
|
|
93
91
|
return;
|
|
94
92
|
}
|
|
95
|
-
|
|
93
|
+
|
|
96
94
|
const expirationDate = this.getExpirationDate();
|
|
97
95
|
|
|
98
96
|
const now = new Date();
|
|
@@ -104,7 +102,7 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
104
102
|
const certificate = this.getCertificate();
|
|
105
103
|
|
|
106
104
|
if (!expirationDate || (isMinDate(expirationDate) && !certificate)) {
|
|
107
|
-
if (
|
|
105
|
+
if (this.currentBranch()?.getActiveState()) {
|
|
108
106
|
this.updateAlarmState2(true, 255, "certificate is missing");
|
|
109
107
|
}
|
|
110
108
|
return;
|
|
@@ -147,11 +145,11 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
147
145
|
if (!this.expirationLimit) {
|
|
148
146
|
return TwoWeeksDuration;
|
|
149
147
|
}
|
|
150
|
-
const dataValue = this.expirationLimit
|
|
151
|
-
if ((dataValue as
|
|
148
|
+
const dataValue = this.expirationLimit.readValue();
|
|
149
|
+
if ((dataValue.value.dataType as DataType) === DataType.Null) {
|
|
152
150
|
return TwoWeeksDuration;
|
|
153
151
|
}
|
|
154
|
-
return (
|
|
152
|
+
return (dataValue.value.value as number) || 0;
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
public setExpirationLimit(value: number): void {
|
|
@@ -163,7 +161,7 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
163
161
|
}
|
|
164
162
|
|
|
165
163
|
public getCertificate(): Certificate | null {
|
|
166
|
-
return (this.getChildByName("Certificate") as UAVariable)?.readValue().value.value as Certificate || null;
|
|
164
|
+
return ((this.getChildByName("Certificate") as UAVariable)?.readValue().value.value as Certificate) || null;
|
|
167
165
|
}
|
|
168
166
|
|
|
169
167
|
private _extractAndSetExpiryDate(certificate: Certificate | null): void {
|
|
@@ -193,20 +191,28 @@ class UACertificateExpirationAlarmImpl extends UASystemOffNormalAlarmImpl implem
|
|
|
193
191
|
this.timer = null;
|
|
194
192
|
}
|
|
195
193
|
}
|
|
196
|
-
|
|
194
|
+
|
|
197
195
|
private _startTimer() {
|
|
198
196
|
this.timer = setTimeout(() => {
|
|
199
197
|
if (!this.timer) return;
|
|
200
198
|
this.update();
|
|
201
199
|
this._startTimer();
|
|
202
200
|
}, OneDayDuration / 48);
|
|
201
|
+
// don't keep the process alive just for this monitoring timer
|
|
202
|
+
if (this.timer && typeof this.timer.unref === "function") {
|
|
203
|
+
this.timer.unref();
|
|
204
|
+
}
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
_post_initialize() {
|
|
208
|
+
// ensure _branch0 is created (base UAConditionImpl)
|
|
209
|
+
if (!this.currentBranch()) {
|
|
210
|
+
this.post_initialize();
|
|
211
|
+
}
|
|
206
212
|
if (this.expirationLimit) {
|
|
207
213
|
this.expirationLimit.accessLevel = makeAccessLevelExFlag("CurrentRead | CurrentWrite");
|
|
208
214
|
this.expirationLimit.userAccessLevel = makeAccessLevelExFlag("CurrentRead | CurrentWrite");
|
|
209
|
-
this.expirationLimit.on("value_changed", (
|
|
215
|
+
this.expirationLimit.on("value_changed", (_dataValue) => {
|
|
210
216
|
// make sure we re-evaluate the certificate
|
|
211
217
|
const certificate = this.getCertificate();
|
|
212
218
|
this.setCertificate(certificate);
|
|
@@ -185,7 +185,7 @@ export class UAConditionImpl extends UABaseEventImpl implements UAConditionEx {
|
|
|
185
185
|
const statusCode = inner_func(eventId, comment, branch, conditionNode);
|
|
186
186
|
|
|
187
187
|
// record also who did the call
|
|
188
|
-
branch.setClientUserId(context.
|
|
188
|
+
branch.setClientUserId(context.getUserName());
|
|
189
189
|
|
|
190
190
|
callback(null, {
|
|
191
191
|
statusCode
|
package/src/base_node_impl.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @module node-opcua-address-space
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { isDeepStrictEqual as isEqual } from "node:util";
|
|
5
6
|
import { EventEmitter } from "node:events";
|
|
6
7
|
import chalk from "chalk";
|
|
7
|
-
import { isEqual } from "lodash";
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
10
|
AddReferenceOpts,
|
|
@@ -749,15 +749,15 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
749
749
|
// The type of reference to follow from the current node.
|
|
750
750
|
// The current path cannot be followed any further if the referenceTypeId is not available on the Node instance.
|
|
751
751
|
// If not specified then all References are included and the parameter includeSubtypes is ignored.
|
|
752
|
-
assert(Object.
|
|
752
|
+
assert(Object.hasOwn(relativePathElement, "referenceTypeId"));
|
|
753
753
|
|
|
754
754
|
// Indicates whether the inverse Reference should be followed.
|
|
755
755
|
// The inverse reference is followed if this value is TRUE.
|
|
756
|
-
assert(Object.
|
|
756
|
+
assert(Object.hasOwn(relativePathElement, "isInverse"));
|
|
757
757
|
|
|
758
758
|
// Indicates whether subtypes of the ReferenceType should be followed.
|
|
759
759
|
// Subtypes are included if this value is TRUE.
|
|
760
|
-
assert(Object.
|
|
760
|
+
assert(Object.hasOwn(relativePathElement, "includeSubtypes"));
|
|
761
761
|
|
|
762
762
|
const references = this.allReferences();
|
|
763
763
|
|
|
@@ -772,7 +772,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
772
772
|
) {
|
|
773
773
|
return false;
|
|
774
774
|
}
|
|
775
|
-
assert(Object.
|
|
775
|
+
assert(Object.hasOwn(reference, "isForward"));
|
|
776
776
|
const referenceType = resolveReferenceType(this.addressSpace, reference);
|
|
777
777
|
const referenceTypeId = referenceType.nodeId;
|
|
778
778
|
|
|
@@ -807,7 +807,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
807
807
|
// compare QualifiedName
|
|
808
808
|
|
|
809
809
|
const key = obj.nodeId.toString();
|
|
810
|
-
if (!Object.
|
|
810
|
+
if (!Object.hasOwn(nodeIdsMap, key)) {
|
|
811
811
|
nodeIds.push(obj.nodeId);
|
|
812
812
|
nodeIdsMap[key] = obj;
|
|
813
813
|
}
|
|
@@ -915,9 +915,9 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
915
915
|
public removeReference(referenceOpts: AddReferenceOpts): void {
|
|
916
916
|
const _private = BaseNode_getPrivate(this);
|
|
917
917
|
|
|
918
|
-
assert(Object.
|
|
918
|
+
assert(Object.hasOwn(referenceOpts, "referenceType"));
|
|
919
919
|
// xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
|
|
920
|
-
assert(Object.
|
|
920
|
+
assert(Object.hasOwn(referenceOpts, "nodeId"));
|
|
921
921
|
|
|
922
922
|
const addressSpace = this.addressSpace as AddressSpacePrivate;
|
|
923
923
|
|
|
@@ -1007,7 +1007,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
1007
1007
|
const childNode = resolveReferenceNode(addressSpace, reference);
|
|
1008
1008
|
|
|
1009
1009
|
const name = lowerFirstLetter(childNode.browseName.name || "");
|
|
1010
|
-
if (Object.
|
|
1010
|
+
if (Object.hasOwn(reservedNames, name)) {
|
|
1011
1011
|
// c8 ignore next
|
|
1012
1012
|
if (doDebug) {
|
|
1013
1013
|
// tslint:disable-next-line:no-console
|
|
@@ -1016,7 +1016,7 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
1016
1016
|
return;
|
|
1017
1017
|
}
|
|
1018
1018
|
/* c8 ignore next */
|
|
1019
|
-
if (!Object.
|
|
1019
|
+
if (!Object.hasOwn(this, name)) {
|
|
1020
1020
|
return;
|
|
1021
1021
|
}
|
|
1022
1022
|
|
|
@@ -1031,6 +1031,19 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
1031
1031
|
return options.toString();
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
|
+
public toJSON(): Record<string, string | undefined | null> {
|
|
1035
|
+
return {
|
|
1036
|
+
nodeId: this.nodeId.toString(),
|
|
1037
|
+
nodeClass: NodeClass[this.nodeClass],
|
|
1038
|
+
browseName: this.browseName.toString(),
|
|
1039
|
+
displayName: this.displayName.length ? this.displayName[0].text : ""
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
public [Symbol.for("nodejs.util.inspect.custom")](): string {
|
|
1044
|
+
return this.toString();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1034
1047
|
/**
|
|
1035
1048
|
* @property isFalseSubStateOf
|
|
1036
1049
|
* @type {BaseNode|null}
|
|
@@ -1285,9 +1298,9 @@ export class BaseNodeImpl extends EventEmitter implements BaseNode {
|
|
|
1285
1298
|
private __addReference(referenceOpts: AddReferenceOpts): UAReference {
|
|
1286
1299
|
const addressSpace = this.addressSpace as AddressSpacePrivate;
|
|
1287
1300
|
const _private = BaseNode_getPrivate(this);
|
|
1288
|
-
assert(Object.
|
|
1301
|
+
assert(Object.hasOwn(referenceOpts, "referenceType"));
|
|
1289
1302
|
// xx isForward is optional : assert(Object.prototype.hasOwnProperty.call(reference,"isForward"));
|
|
1290
|
-
assert(Object.
|
|
1303
|
+
assert(Object.hasOwn(referenceOpts, "nodeId"));
|
|
1291
1304
|
|
|
1292
1305
|
const reference: UAReference = addressSpace.normalizeReferenceTypes([referenceOpts])[0];
|
|
1293
1306
|
assert(reference instanceof ReferenceImpl);
|
|
@@ -1821,7 +1834,7 @@ function install_components_as_object_properties(parentObj: BaseNode) {
|
|
|
1821
1834
|
// assumption: we ignore namespace here .
|
|
1822
1835
|
const name = lowerFirstLetter(child.browseName.name || "");
|
|
1823
1836
|
|
|
1824
|
-
if (Object.
|
|
1837
|
+
if (Object.hasOwn(reservedNames, name)) {
|
|
1825
1838
|
// ignore reserved names
|
|
1826
1839
|
if (doDebug) {
|
|
1827
1840
|
debugLog(chalk.bgWhite.red(`Ignoring reserved keyword ${name}`));
|
|
@@ -1832,7 +1845,7 @@ function install_components_as_object_properties(parentObj: BaseNode) {
|
|
|
1832
1845
|
// ignore reserved names
|
|
1833
1846
|
doDebug && debugLog(`Installing property ${name}`, " on ", parentObj.browseName.toString());
|
|
1834
1847
|
|
|
1835
|
-
const hasProperty = Object.
|
|
1848
|
+
const hasProperty = Object.hasOwn(parentObj, name);
|
|
1836
1849
|
if (
|
|
1837
1850
|
hasProperty &&
|
|
1838
1851
|
(parentObj as unknown as Record<string, unknown>)[name] !== null &&
|