node-opcua-client 2.97.0 → 2.98.1

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 (78) hide show
  1. package/dist/alarms_and_conditions/client_alarm.d.ts +49 -49
  2. package/dist/alarms_and_conditions/client_alarm.js +109 -109
  3. package/dist/alarms_and_conditions/client_alarm_list.d.ts +25 -25
  4. package/dist/alarms_and_conditions/client_alarm_list.js +97 -97
  5. package/dist/alarms_and_conditions/client_alarm_tools.d.ts +4 -4
  6. package/dist/alarms_and_conditions/client_alarm_tools.js +156 -156
  7. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.d.ts +18 -18
  8. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js +192 -192
  9. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.d.ts +9 -9
  10. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js +72 -72
  11. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js.map +1 -1
  12. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +3 -3
  13. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +118 -118
  14. package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
  15. package/dist/alarms_and_conditions/client_tools.js +179 -179
  16. package/dist/client_base.d.ts +277 -277
  17. package/dist/client_base.js +14 -14
  18. package/dist/client_base.js.map +1 -1
  19. package/dist/client_monitored_item.d.ts +21 -21
  20. package/dist/client_monitored_item.js +11 -11
  21. package/dist/client_monitored_item_base.d.ts +39 -39
  22. package/dist/client_monitored_item_base.js +2 -2
  23. package/dist/client_monitored_item_group.d.ts +21 -21
  24. package/dist/client_monitored_item_group.js +13 -13
  25. package/dist/client_monitored_item_toolbox.d.ts +15 -15
  26. package/dist/client_monitored_item_toolbox.js +116 -116
  27. package/dist/client_session.d.ts +529 -529
  28. package/dist/client_session.js +10 -10
  29. package/dist/client_session_keepalive_manager.d.ts +34 -34
  30. package/dist/client_session_keepalive_manager.js +149 -149
  31. package/dist/client_subscription.d.ts +241 -241
  32. package/dist/client_subscription.js +14 -14
  33. package/dist/client_subscription.js.map +1 -1
  34. package/dist/client_utils.d.ts +22 -22
  35. package/dist/client_utils.js +87 -87
  36. package/dist/common.d.ts +17 -17
  37. package/dist/common.js +5 -5
  38. package/dist/index.d.ts +56 -56
  39. package/dist/index.js +94 -94
  40. package/dist/opcua_client.d.ts +118 -118
  41. package/dist/opcua_client.js +33 -33
  42. package/dist/private/client_base_impl.d.ts +160 -160
  43. package/dist/private/client_base_impl.js +1348 -1348
  44. package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
  45. package/dist/private/client_monitored_item_base_impl.js +4 -4
  46. package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
  47. package/dist/private/client_monitored_item_group_impl.js +159 -159
  48. package/dist/private/client_monitored_item_impl.d.ts +93 -93
  49. package/dist/private/client_monitored_item_impl.js +304 -304
  50. package/dist/private/client_publish_engine.d.ts +62 -62
  51. package/dist/private/client_publish_engine.js +408 -408
  52. package/dist/private/client_publish_engine.js.map +1 -1
  53. package/dist/private/client_session_impl.d.ts +631 -631
  54. package/dist/private/client_session_impl.js +1348 -1348
  55. package/dist/private/client_subscription_impl.d.ts +93 -93
  56. package/dist/private/client_subscription_impl.js +763 -763
  57. package/dist/private/i_private_client.d.ts +21 -21
  58. package/dist/private/i_private_client.js +2 -2
  59. package/dist/private/opcua_client_impl.d.ts +166 -166
  60. package/dist/private/opcua_client_impl.js +1000 -1000
  61. package/dist/private/opcua_client_impl.js.map +1 -1
  62. package/dist/private/performance.d.ts +1 -1
  63. package/dist/private/performance.js +18 -18
  64. package/dist/reconnection.d.ts +9 -9
  65. package/dist/reconnection.js +381 -381
  66. package/dist/tools/findservers.d.ts +20 -20
  67. package/dist/tools/findservers.js +61 -61
  68. package/dist/tools/read_history_server_capabilities.d.ts +6 -6
  69. package/dist/tools/read_history_server_capabilities.js +98 -98
  70. package/dist/user_identity_info.d.ts +1 -1
  71. package/dist/user_identity_info.js +2 -2
  72. package/dist/verify.d.ts +5 -5
  73. package/dist/verify.js +134 -134
  74. package/package.json +49 -45
  75. package/source/alarms_and_conditions/client_alarm_tools_dump_event.ts +1 -1
  76. package/.nycrc.json +0 -14
  77. package/test_helpers/create_certificates.js +0 -1
  78. package/typedoc.js +0 -20
@@ -1,49 +1,49 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { EventEmitter } from "events";
4
- import { NodeId } from "node-opcua-nodeid";
5
- import { StatusCode } from "node-opcua-status-code";
6
- import { Variant } from "node-opcua-variant";
7
- import { ClientSession } from "../client_session";
8
- export interface TVariant<T> extends Variant {
9
- value: T;
10
- }
11
- export interface TTwoStateStatus extends TVariant<string> {
12
- id: TVariant<boolean>;
13
- }
14
- export interface EventStuff {
15
- conditionId: TVariant<NodeId>;
16
- eventType: TVariant<NodeId>;
17
- eventId: TVariant<Buffer>;
18
- retain: TVariant<boolean>;
19
- activeState: TTwoStateStatus;
20
- ackedState: TTwoStateStatus;
21
- confirmedState: TTwoStateStatus;
22
- conditionName?: TVariant<string>;
23
- }
24
- export interface ClientAlarm {
25
- conditionId: NodeId;
26
- eventType: NodeId;
27
- fields: EventStuff;
28
- on(eventName: "changed", eventHandler: () => void): this;
29
- acknowledge(session: ClientSession, comment: string): Promise<StatusCode>;
30
- getField(fieldName: string): Variant | null;
31
- }
32
- /**
33
- * describes a OPCUA Alarm as seen in the client side
34
- */
35
- export declare class ClientAlarm extends EventEmitter {
36
- conditionId: NodeId;
37
- eventType: NodeId;
38
- eventId: Buffer;
39
- fields: EventStuff;
40
- constructor(eventFields: EventStuff);
41
- confirm(session: ClientSession, comment: string): Promise<StatusCode>;
42
- update(eventFields: EventStuff): void;
43
- getRetain(): boolean;
44
- toString(): string;
45
- }
46
- /**
47
- * @private
48
- */
49
- export declare function fieldsToJson(fields: string[], eventFields: Variant[], flat?: boolean): EventStuff;
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from "events";
4
+ import { NodeId } from "node-opcua-nodeid";
5
+ import { StatusCode } from "node-opcua-status-code";
6
+ import { Variant } from "node-opcua-variant";
7
+ import { ClientSession } from "../client_session";
8
+ export interface TVariant<T> extends Variant {
9
+ value: T;
10
+ }
11
+ export interface TTwoStateStatus extends TVariant<string> {
12
+ id: TVariant<boolean>;
13
+ }
14
+ export interface EventStuff {
15
+ conditionId: TVariant<NodeId>;
16
+ eventType: TVariant<NodeId>;
17
+ eventId: TVariant<Buffer>;
18
+ retain: TVariant<boolean>;
19
+ activeState: TTwoStateStatus;
20
+ ackedState: TTwoStateStatus;
21
+ confirmedState: TTwoStateStatus;
22
+ conditionName?: TVariant<string>;
23
+ }
24
+ export interface ClientAlarm {
25
+ conditionId: NodeId;
26
+ eventType: NodeId;
27
+ fields: EventStuff;
28
+ on(eventName: "changed", eventHandler: () => void): this;
29
+ acknowledge(session: ClientSession, comment: string): Promise<StatusCode>;
30
+ getField(fieldName: string): Variant | null;
31
+ }
32
+ /**
33
+ * describes a OPCUA Alarm as seen in the client side
34
+ */
35
+ export declare class ClientAlarm extends EventEmitter {
36
+ conditionId: NodeId;
37
+ eventType: NodeId;
38
+ eventId: Buffer;
39
+ fields: EventStuff;
40
+ constructor(eventFields: EventStuff);
41
+ confirm(session: ClientSession, comment: string): Promise<StatusCode>;
42
+ update(eventFields: EventStuff): void;
43
+ getRetain(): boolean;
44
+ toString(): string;
45
+ }
46
+ /**
47
+ * @private
48
+ */
49
+ export declare function fieldsToJson(fields: string[], eventFields: Variant[], flat?: boolean): EventStuff;
@@ -1,110 +1,110 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fieldsToJson = exports.ClientAlarm = void 0;
13
- const events_1 = require("events");
14
- const node_opcua_assert_1 = require("node-opcua-assert");
15
- const node_opcua_debug_1 = require("node-opcua-debug");
16
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
17
- const node_opcua_utils_1 = require("node-opcua-utils");
18
- const node_opcua_variant_1 = require("node-opcua-variant");
19
- const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
20
- /**
21
- * describes a OPCUA Alarm as seen in the client side
22
- */
23
- class ClientAlarm extends events_1.EventEmitter {
24
- constructor(eventFields) {
25
- super();
26
- this.conditionId = (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.conditionId.value);
27
- this.eventType = (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.eventType.value);
28
- this.eventId = eventFields.eventId.value;
29
- this.fields = eventFields;
30
- this.update(eventFields);
31
- }
32
- acknowledge(session, comment) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- return yield session.acknowledgeCondition(this.conditionId, this.eventId, comment);
35
- });
36
- }
37
- confirm(session, comment) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- return yield session.confirmCondition(this.conditionId, this.eventId, comment);
40
- });
41
- }
42
- update(eventFields) {
43
- (0, node_opcua_assert_1.assert)(this.conditionId.toString() === (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.conditionId.value).toString());
44
- (0, node_opcua_assert_1.assert)(this.eventType.toString() === (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.eventType.value).toString());
45
- this.eventId = eventFields.eventId.value;
46
- this.fields = eventFields;
47
- }
48
- getRetain() {
49
- return this.fields.retain.value;
50
- }
51
- toString() {
52
- return (this.constructor.name +
53
- ": " +
54
- this.conditionId.toString() +
55
- " " +
56
- this.eventType.toString() +
57
- " " +
58
- Object.entries(this.fields)
59
- .filter(([key, value]) => value.dataType !== node_opcua_variant_1.DataType.Null)
60
- .map(([key, value]) => key.padEnd(30) + "=" + value.toString())
61
- .join("\n") +
62
- "\n\n");
63
- }
64
- getField(fieldName) {
65
- return this.fields[fieldName] || null;
66
- }
67
- }
68
- exports.ClientAlarm = ClientAlarm;
69
- /**
70
- * @private
71
- */
72
- function fieldsToJson(fields, eventFields, flat) {
73
- function setProperty(_data, fieldName, value) {
74
- let name;
75
- if (!fieldName || value === null) {
76
- return;
77
- }
78
- if (!flat) {
79
- const f = fieldName.split(".");
80
- if (f.length === 1) {
81
- fieldName = (0, node_opcua_utils_1.lowerFirstLetter)(fieldName);
82
- _data[fieldName] = value;
83
- }
84
- else {
85
- for (let i = 0; i < f.length - 1; i++) {
86
- name = (0, node_opcua_utils_1.lowerFirstLetter)(f[i]);
87
- _data[name] = _data[name] || {};
88
- _data = _data[name];
89
- }
90
- name = (0, node_opcua_utils_1.lowerFirstLetter)(f[f.length - 1]);
91
- _data[name] = value;
92
- }
93
- }
94
- else {
95
- const name = fieldName.split(".").map(node_opcua_utils_1.lowerFirstLetter).join(".");
96
- _data[name] = value;
97
- }
98
- }
99
- if (fields.length > eventFields.length) {
100
- warningLog("warning fields.length !== eventFields.length", fields.length, eventFields.length);
101
- }
102
- const data = {};
103
- for (let index = 0; index < fields.length; index++) {
104
- const variant = eventFields[index];
105
- setProperty(data, fields[index], variant);
106
- }
107
- return data;
108
- }
109
- exports.fieldsToJson = fieldsToJson;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.fieldsToJson = exports.ClientAlarm = void 0;
13
+ const events_1 = require("events");
14
+ const node_opcua_assert_1 = require("node-opcua-assert");
15
+ const node_opcua_debug_1 = require("node-opcua-debug");
16
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
17
+ const node_opcua_utils_1 = require("node-opcua-utils");
18
+ const node_opcua_variant_1 = require("node-opcua-variant");
19
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
20
+ /**
21
+ * describes a OPCUA Alarm as seen in the client side
22
+ */
23
+ class ClientAlarm extends events_1.EventEmitter {
24
+ constructor(eventFields) {
25
+ super();
26
+ this.conditionId = (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.conditionId.value);
27
+ this.eventType = (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.eventType.value);
28
+ this.eventId = eventFields.eventId.value;
29
+ this.fields = eventFields;
30
+ this.update(eventFields);
31
+ }
32
+ acknowledge(session, comment) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return yield session.acknowledgeCondition(this.conditionId, this.eventId, comment);
35
+ });
36
+ }
37
+ confirm(session, comment) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return yield session.confirmCondition(this.conditionId, this.eventId, comment);
40
+ });
41
+ }
42
+ update(eventFields) {
43
+ (0, node_opcua_assert_1.assert)(this.conditionId.toString() === (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.conditionId.value).toString());
44
+ (0, node_opcua_assert_1.assert)(this.eventType.toString() === (0, node_opcua_nodeid_1.resolveNodeId)(eventFields.eventType.value).toString());
45
+ this.eventId = eventFields.eventId.value;
46
+ this.fields = eventFields;
47
+ }
48
+ getRetain() {
49
+ return this.fields.retain.value;
50
+ }
51
+ toString() {
52
+ return (this.constructor.name +
53
+ ": " +
54
+ this.conditionId.toString() +
55
+ " " +
56
+ this.eventType.toString() +
57
+ " " +
58
+ Object.entries(this.fields)
59
+ .filter(([key, value]) => value.dataType !== node_opcua_variant_1.DataType.Null)
60
+ .map(([key, value]) => key.padEnd(30) + "=" + value.toString())
61
+ .join("\n") +
62
+ "\n\n");
63
+ }
64
+ getField(fieldName) {
65
+ return this.fields[fieldName] || null;
66
+ }
67
+ }
68
+ exports.ClientAlarm = ClientAlarm;
69
+ /**
70
+ * @private
71
+ */
72
+ function fieldsToJson(fields, eventFields, flat) {
73
+ function setProperty(_data, fieldName, value) {
74
+ let name;
75
+ if (!fieldName || value === null) {
76
+ return;
77
+ }
78
+ if (!flat) {
79
+ const f = fieldName.split(".");
80
+ if (f.length === 1) {
81
+ fieldName = (0, node_opcua_utils_1.lowerFirstLetter)(fieldName);
82
+ _data[fieldName] = value;
83
+ }
84
+ else {
85
+ for (let i = 0; i < f.length - 1; i++) {
86
+ name = (0, node_opcua_utils_1.lowerFirstLetter)(f[i]);
87
+ _data[name] = _data[name] || {};
88
+ _data = _data[name];
89
+ }
90
+ name = (0, node_opcua_utils_1.lowerFirstLetter)(f[f.length - 1]);
91
+ _data[name] = value;
92
+ }
93
+ }
94
+ else {
95
+ const name = fieldName.split(".").map(node_opcua_utils_1.lowerFirstLetter).join(".");
96
+ _data[name] = value;
97
+ }
98
+ }
99
+ if (fields.length > eventFields.length) {
100
+ warningLog("warning fields.length !== eventFields.length", fields.length, eventFields.length);
101
+ }
102
+ const data = {};
103
+ for (let index = 0; index < fields.length; index++) {
104
+ const variant = eventFields[index];
105
+ setProperty(data, fields[index], variant);
106
+ }
107
+ return data;
108
+ }
109
+ exports.fieldsToJson = fieldsToJson;
110
110
  //# sourceMappingURL=client_alarm.js.map
@@ -1,25 +1,25 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from "events";
3
- import { ClientAlarm, EventStuff } from "./client_alarm";
4
- export interface ClientAlarmList {
5
- on(eventName: "alarmChanged", handler: (alarm: ClientAlarm) => void): this;
6
- on(eventName: "alarmDeleted", handler: (alarm: ClientAlarm) => void): this;
7
- on(eventName: "newAlarm", handler: (alarm: ClientAlarm) => void): this;
8
- emit(eventName: "alarmChanged", alarm: ClientAlarm): boolean;
9
- emit(eventName: "newAlarm", alarm: ClientAlarm): boolean;
10
- emit(eventName: "alarmDeleted", alarm: ClientAlarm): boolean;
11
- }
12
- export declare class ClientAlarmList extends EventEmitter implements Iterable<ClientAlarm> {
13
- private _map;
14
- constructor();
15
- [Symbol.iterator](): Iterator<ClientAlarm>;
16
- alarms(): ClientAlarm[];
17
- update(eventField: EventStuff): void;
18
- removeAlarm(eventField: EventStuff): void;
19
- get length(): number;
20
- purgeUnusedAlarms(): void;
21
- private _removeAlarm;
22
- private makeKey;
23
- private findAlarm;
24
- private deleteAlarm;
25
- }
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from "events";
3
+ import { ClientAlarm, EventStuff } from "./client_alarm";
4
+ export interface ClientAlarmList {
5
+ on(eventName: "alarmChanged", handler: (alarm: ClientAlarm) => void): this;
6
+ on(eventName: "alarmDeleted", handler: (alarm: ClientAlarm) => void): this;
7
+ on(eventName: "newAlarm", handler: (alarm: ClientAlarm) => void): this;
8
+ emit(eventName: "alarmChanged", alarm: ClientAlarm): boolean;
9
+ emit(eventName: "newAlarm", alarm: ClientAlarm): boolean;
10
+ emit(eventName: "alarmDeleted", alarm: ClientAlarm): boolean;
11
+ }
12
+ export declare class ClientAlarmList extends EventEmitter implements Iterable<ClientAlarm> {
13
+ private _map;
14
+ constructor();
15
+ [Symbol.iterator](): Iterator<ClientAlarm>;
16
+ alarms(): ClientAlarm[];
17
+ update(eventField: EventStuff): void;
18
+ removeAlarm(eventField: EventStuff): void;
19
+ get length(): number;
20
+ purgeUnusedAlarms(): void;
21
+ private _removeAlarm;
22
+ private makeKey;
23
+ private findAlarm;
24
+ private deleteAlarm;
25
+ }
@@ -1,98 +1,98 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientAlarmList = void 0;
4
- const events_1 = require("events");
5
- const node_opcua_assert_1 = require("node-opcua-assert");
6
- const client_alarm_1 = require("./client_alarm");
7
- // maintain a set of alarm list for a client
8
- class ClientAlarmList extends events_1.EventEmitter {
9
- constructor() {
10
- super();
11
- this._map = {};
12
- }
13
- [Symbol.iterator]() {
14
- let pointer = 0;
15
- const components = Object.values(this._map);
16
- return {
17
- next() {
18
- if (pointer >= components.length) {
19
- return {
20
- done: true,
21
- value: components[pointer++]
22
- };
23
- }
24
- else {
25
- return {
26
- done: false,
27
- value: components[pointer++]
28
- };
29
- }
30
- }
31
- };
32
- }
33
- alarms() {
34
- return Object.values(this._map);
35
- }
36
- update(eventField) {
37
- // Spec says:
38
- // Clients shall check for multiple Event Notifications for a ConditionBranch to avoid
39
- // overwriting a new state delivered together with an older state from the Refresh
40
- // process.
41
- const { conditionId, eventType } = eventField;
42
- (0, node_opcua_assert_1.assert)(conditionId, "must have a valid conditionId ( verify that event is a acknodweldgeable type");
43
- const alarm = this.findAlarm(conditionId.value, eventType.value);
44
- if (!alarm) {
45
- const key = this.makeKey(conditionId.value, eventType.value);
46
- const newAlarm = new client_alarm_1.ClientAlarm(eventField);
47
- this._map[key] = newAlarm;
48
- this.emit("newAlarm", newAlarm);
49
- this.emit("alarmChanged", newAlarm);
50
- }
51
- else {
52
- alarm.update(eventField);
53
- this.emit("alarmChanged", alarm);
54
- }
55
- }
56
- removeAlarm(eventField) {
57
- const { conditionId, eventType } = eventField;
58
- const alarm = this.findAlarm(conditionId.value, eventType.value);
59
- if (alarm) {
60
- alarm.update(eventField);
61
- this._removeAlarm(alarm);
62
- }
63
- }
64
- get length() {
65
- return Object.keys(this._map).length;
66
- }
67
- purgeUnusedAlarms() {
68
- const alarms = this.alarms();
69
- for (const alarm of alarms) {
70
- if (!alarm.getRetain()) {
71
- this._removeAlarm(alarm);
72
- }
73
- }
74
- }
75
- _removeAlarm(alarm) {
76
- this.emit("alarmDeleted", alarm);
77
- this.deleteAlarm(alarm.conditionId, alarm.eventType);
78
- }
79
- makeKey(conditionId, eventType) {
80
- return conditionId.toString() + "|" + eventType.toString();
81
- }
82
- findAlarm(conditionId, eventType) {
83
- const key = this.makeKey(conditionId, eventType);
84
- const _c = this._map[key];
85
- return _c || null;
86
- }
87
- deleteAlarm(conditionId, eventType) {
88
- const key = this.makeKey(conditionId, eventType);
89
- const _c = this._map[key];
90
- if (_c) {
91
- delete this._map[key];
92
- return true;
93
- }
94
- return false;
95
- }
96
- }
97
- exports.ClientAlarmList = ClientAlarmList;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientAlarmList = void 0;
4
+ const events_1 = require("events");
5
+ const node_opcua_assert_1 = require("node-opcua-assert");
6
+ const client_alarm_1 = require("./client_alarm");
7
+ // maintain a set of alarm list for a client
8
+ class ClientAlarmList extends events_1.EventEmitter {
9
+ constructor() {
10
+ super();
11
+ this._map = {};
12
+ }
13
+ [Symbol.iterator]() {
14
+ let pointer = 0;
15
+ const components = Object.values(this._map);
16
+ return {
17
+ next() {
18
+ if (pointer >= components.length) {
19
+ return {
20
+ done: true,
21
+ value: components[pointer++]
22
+ };
23
+ }
24
+ else {
25
+ return {
26
+ done: false,
27
+ value: components[pointer++]
28
+ };
29
+ }
30
+ }
31
+ };
32
+ }
33
+ alarms() {
34
+ return Object.values(this._map);
35
+ }
36
+ update(eventField) {
37
+ // Spec says:
38
+ // Clients shall check for multiple Event Notifications for a ConditionBranch to avoid
39
+ // overwriting a new state delivered together with an older state from the Refresh
40
+ // process.
41
+ const { conditionId, eventType } = eventField;
42
+ (0, node_opcua_assert_1.assert)(conditionId, "must have a valid conditionId ( verify that event is a acknodweldgeable type");
43
+ const alarm = this.findAlarm(conditionId.value, eventType.value);
44
+ if (!alarm) {
45
+ const key = this.makeKey(conditionId.value, eventType.value);
46
+ const newAlarm = new client_alarm_1.ClientAlarm(eventField);
47
+ this._map[key] = newAlarm;
48
+ this.emit("newAlarm", newAlarm);
49
+ this.emit("alarmChanged", newAlarm);
50
+ }
51
+ else {
52
+ alarm.update(eventField);
53
+ this.emit("alarmChanged", alarm);
54
+ }
55
+ }
56
+ removeAlarm(eventField) {
57
+ const { conditionId, eventType } = eventField;
58
+ const alarm = this.findAlarm(conditionId.value, eventType.value);
59
+ if (alarm) {
60
+ alarm.update(eventField);
61
+ this._removeAlarm(alarm);
62
+ }
63
+ }
64
+ get length() {
65
+ return Object.keys(this._map).length;
66
+ }
67
+ purgeUnusedAlarms() {
68
+ const alarms = this.alarms();
69
+ for (const alarm of alarms) {
70
+ if (!alarm.getRetain()) {
71
+ this._removeAlarm(alarm);
72
+ }
73
+ }
74
+ }
75
+ _removeAlarm(alarm) {
76
+ this.emit("alarmDeleted", alarm);
77
+ this.deleteAlarm(alarm.conditionId, alarm.eventType);
78
+ }
79
+ makeKey(conditionId, eventType) {
80
+ return conditionId.toString() + "|" + eventType.toString();
81
+ }
82
+ findAlarm(conditionId, eventType) {
83
+ const key = this.makeKey(conditionId, eventType);
84
+ const _c = this._map[key];
85
+ return _c || null;
86
+ }
87
+ deleteAlarm(conditionId, eventType) {
88
+ const key = this.makeKey(conditionId, eventType);
89
+ const _c = this._map[key];
90
+ if (_c) {
91
+ delete this._map[key];
92
+ return true;
93
+ }
94
+ return false;
95
+ }
96
+ }
97
+ exports.ClientAlarmList = ClientAlarmList;
98
98
  //# sourceMappingURL=client_alarm_list.js.map
@@ -1,4 +1,4 @@
1
- import { ClientSession } from "../client_session";
2
- import { ClientAlarmList } from "./client_alarm_list";
3
- export declare function uninstallAlarmMonitoring(session: ClientSession): Promise<void>;
4
- export declare function installAlarmMonitoring(session: ClientSession): Promise<ClientAlarmList>;
1
+ import { ClientSession } from "../client_session";
2
+ import { ClientAlarmList } from "./client_alarm_list";
3
+ export declare function uninstallAlarmMonitoring(session: ClientSession): Promise<void>;
4
+ export declare function installAlarmMonitoring(session: ClientSession): Promise<ClientAlarmList>;