node-opcua-client 2.75.0 → 2.76.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 (65) 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 +73 -73
  11. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +3 -3
  12. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +118 -118
  13. package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
  14. package/dist/alarms_and_conditions/client_tools.js +180 -180
  15. package/dist/client_base.d.ts +277 -277
  16. package/dist/client_base.js +14 -14
  17. package/dist/client_monitored_item.d.ts +21 -21
  18. package/dist/client_monitored_item.js +11 -11
  19. package/dist/client_monitored_item_base.d.ts +39 -39
  20. package/dist/client_monitored_item_base.js +2 -2
  21. package/dist/client_monitored_item_group.d.ts +18 -18
  22. package/dist/client_monitored_item_group.js +13 -13
  23. package/dist/client_monitored_item_toolbox.d.ts +15 -15
  24. package/dist/client_monitored_item_toolbox.js +117 -117
  25. package/dist/client_session.d.ts +484 -484
  26. package/dist/client_session.js +10 -10
  27. package/dist/client_session_keepalive_manager.d.ts +34 -34
  28. package/dist/client_session_keepalive_manager.js +150 -150
  29. package/dist/client_subscription.d.ts +241 -241
  30. package/dist/client_subscription.js +14 -14
  31. package/dist/client_utils.d.ts +22 -22
  32. package/dist/client_utils.js +88 -88
  33. package/dist/common.d.ts +17 -17
  34. package/dist/common.js +5 -5
  35. package/dist/index.d.ts +55 -55
  36. package/dist/index.js +93 -93
  37. package/dist/opcua_client.d.ts +132 -132
  38. package/dist/opcua_client.js +33 -33
  39. package/dist/private/client_base_impl.d.ts +157 -157
  40. package/dist/private/client_base_impl.js +1337 -1337
  41. package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
  42. package/dist/private/client_monitored_item_base_impl.js +4 -4
  43. package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
  44. package/dist/private/client_monitored_item_group_impl.js +159 -159
  45. package/dist/private/client_monitored_item_impl.d.ts +93 -93
  46. package/dist/private/client_monitored_item_impl.js +305 -305
  47. package/dist/private/client_publish_engine.d.ts +62 -62
  48. package/dist/private/client_publish_engine.js +408 -408
  49. package/dist/private/client_session_impl.d.ts +621 -621
  50. package/dist/private/client_session_impl.js +1302 -1302
  51. package/dist/private/client_subscription_impl.d.ts +93 -93
  52. package/dist/private/client_subscription_impl.js +748 -748
  53. package/dist/private/i_private_client.d.ts +18 -18
  54. package/dist/private/i_private_client.js +2 -2
  55. package/dist/private/opcua_client_impl.d.ts +169 -169
  56. package/dist/private/opcua_client_impl.js +981 -981
  57. package/dist/reconnection.d.ts +9 -9
  58. package/dist/reconnection.js +408 -408
  59. package/dist/tools/findservers.d.ts +20 -20
  60. package/dist/tools/findservers.js +61 -61
  61. package/dist/tools/read_history_server_capabilities.d.ts +6 -6
  62. package/dist/tools/read_history_server_capabilities.js +99 -99
  63. package/dist/verify.d.ts +5 -5
  64. package/dist/verify.js +134 -134
  65. package/package.json +46 -46
@@ -1,119 +1,119 @@
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.extractConditionFields = void 0;
13
- const node_opcua_data_model_1 = require("node-opcua-data-model");
14
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
- const node_opcua_types_1 = require("node-opcua-types");
16
- function extractConditionFields(session, conditionNodeId) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- // conditionNodeId could be a Object of type ConditionType
19
- // or it could be directly a ObjectType which is a subType of ConditionType
20
- const _duplicateMap = {};
21
- const fields1 = [];
22
- function addField(name) {
23
- if (!_duplicateMap[name]) {
24
- fields1.push(name);
25
- _duplicateMap[name] = name;
26
- }
27
- }
28
- const stack = [];
29
- function deferObjectOrVariableInvestigation(objectId, browseName) {
30
- stack.push({
31
- browseName,
32
- nodeId: objectId
33
- });
34
- }
35
- function _investigateObjectOrVariable() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- if (stack.length === 0) {
38
- return;
39
- }
40
- const extracted = stack.splice(0);
41
- const nodesToBrowse = extracted.map((e) => {
42
- const b = {
43
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
44
- includeSubtypes: true,
45
- // tslint:disable-next-line: no-bitwise
46
- nodeClassMask: node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClassMask.Variable,
47
- nodeId: e.nodeId,
48
- referenceTypeId: "HasChild",
49
- resultMask: 63
50
- };
51
- return b;
52
- });
53
- const results = yield session.browse(nodesToBrowse);
54
- let i = 0;
55
- for (const result of results) {
56
- const name = extracted[i].browseName.toString();
57
- i++;
58
- if (!result.references) {
59
- continue;
60
- }
61
- for (const ref of result.references) {
62
- const n = name + "." + ref.browseName.toString();
63
- if (ref.nodeClass === node_opcua_types_1.NodeClass.Variable) {
64
- addField(n);
65
- }
66
- deferObjectOrVariableInvestigation(ref.nodeId, n);
67
- }
68
- }
69
- yield _investigateObjectOrVariable();
70
- });
71
- }
72
- // tslint:disable-next-line: no-shadowed-variable
73
- function _investigateLevel(conditionNodeId) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const nodeToBrowse1 = {
76
- browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
77
- includeSubtypes: true,
78
- nodeClassMask: node_opcua_data_model_1.NodeClassMask.ObjectType,
79
- nodeId: conditionNodeId,
80
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
81
- resultMask: 63
82
- };
83
- const nodeToBrowse2 = {
84
- browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
85
- includeSubtypes: true,
86
- // tslint:disable-next-line: no-bitwise
87
- nodeClassMask: node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClassMask.Variable,
88
- nodeId: conditionNodeId,
89
- referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasChild"),
90
- resultMask: 63
91
- };
92
- const nodesToBrowse = [nodeToBrowse1, nodeToBrowse2];
93
- const browseResults = yield session.browse(nodesToBrowse);
94
- if (browseResults[1] && browseResults[1].references) {
95
- for (const ref of browseResults[1].references) {
96
- if (ref.nodeClass === node_opcua_types_1.NodeClass.Variable) {
97
- addField(ref.browseName.toString());
98
- }
99
- deferObjectOrVariableInvestigation(ref.nodeId, ref.browseName.toString());
100
- }
101
- }
102
- if (browseResults[0] && browseResults[0].references) {
103
- const promises = [];
104
- for (const reference of browseResults[0].references) {
105
- promises.push(_investigateLevel(reference.nodeId));
106
- }
107
- yield Promise.all(promises);
108
- }
109
- yield _investigateObjectOrVariable();
110
- });
111
- }
112
- yield _investigateLevel(conditionNodeId);
113
- // add this field which will always be added
114
- addField("ConditionId");
115
- return fields1;
116
- });
117
- }
118
- exports.extractConditionFields = extractConditionFields;
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.extractConditionFields = void 0;
13
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
14
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
15
+ const node_opcua_types_1 = require("node-opcua-types");
16
+ function extractConditionFields(session, conditionNodeId) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ // conditionNodeId could be a Object of type ConditionType
19
+ // or it could be directly a ObjectType which is a subType of ConditionType
20
+ const _duplicateMap = {};
21
+ const fields1 = [];
22
+ function addField(name) {
23
+ if (!_duplicateMap[name]) {
24
+ fields1.push(name);
25
+ _duplicateMap[name] = name;
26
+ }
27
+ }
28
+ const stack = [];
29
+ function deferObjectOrVariableInvestigation(objectId, browseName) {
30
+ stack.push({
31
+ browseName,
32
+ nodeId: objectId
33
+ });
34
+ }
35
+ function _investigateObjectOrVariable() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (stack.length === 0) {
38
+ return;
39
+ }
40
+ const extracted = stack.splice(0);
41
+ const nodesToBrowse = extracted.map((e) => {
42
+ const b = {
43
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
44
+ includeSubtypes: true,
45
+ // tslint:disable-next-line: no-bitwise
46
+ nodeClassMask: node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClassMask.Variable,
47
+ nodeId: e.nodeId,
48
+ referenceTypeId: "HasChild",
49
+ resultMask: 63
50
+ };
51
+ return b;
52
+ });
53
+ const results = yield session.browse(nodesToBrowse);
54
+ let i = 0;
55
+ for (const result of results) {
56
+ const name = extracted[i].browseName.toString();
57
+ i++;
58
+ if (!result.references) {
59
+ continue;
60
+ }
61
+ for (const ref of result.references) {
62
+ const n = name + "." + ref.browseName.toString();
63
+ if (ref.nodeClass === node_opcua_types_1.NodeClass.Variable) {
64
+ addField(n);
65
+ }
66
+ deferObjectOrVariableInvestigation(ref.nodeId, n);
67
+ }
68
+ }
69
+ yield _investigateObjectOrVariable();
70
+ });
71
+ }
72
+ // tslint:disable-next-line: no-shadowed-variable
73
+ function _investigateLevel(conditionNodeId) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const nodeToBrowse1 = {
76
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
77
+ includeSubtypes: true,
78
+ nodeClassMask: node_opcua_data_model_1.NodeClassMask.ObjectType,
79
+ nodeId: conditionNodeId,
80
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasSubtype"),
81
+ resultMask: 63
82
+ };
83
+ const nodeToBrowse2 = {
84
+ browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
85
+ includeSubtypes: true,
86
+ // tslint:disable-next-line: no-bitwise
87
+ nodeClassMask: node_opcua_data_model_1.NodeClassMask.Object | node_opcua_data_model_1.NodeClassMask.Variable,
88
+ nodeId: conditionNodeId,
89
+ referenceTypeId: (0, node_opcua_nodeid_1.resolveNodeId)("HasChild"),
90
+ resultMask: 63
91
+ };
92
+ const nodesToBrowse = [nodeToBrowse1, nodeToBrowse2];
93
+ const browseResults = yield session.browse(nodesToBrowse);
94
+ if (browseResults[1] && browseResults[1].references) {
95
+ for (const ref of browseResults[1].references) {
96
+ if (ref.nodeClass === node_opcua_types_1.NodeClass.Variable) {
97
+ addField(ref.browseName.toString());
98
+ }
99
+ deferObjectOrVariableInvestigation(ref.nodeId, ref.browseName.toString());
100
+ }
101
+ }
102
+ if (browseResults[0] && browseResults[0].references) {
103
+ const promises = [];
104
+ for (const reference of browseResults[0].references) {
105
+ promises.push(_investigateLevel(reference.nodeId));
106
+ }
107
+ yield Promise.all(promises);
108
+ }
109
+ yield _investigateObjectOrVariable();
110
+ });
111
+ }
112
+ yield _investigateLevel(conditionNodeId);
113
+ // add this field which will always be added
114
+ addField("ConditionId");
115
+ return fields1;
116
+ });
117
+ }
118
+ exports.extractConditionFields = extractConditionFields;
119
119
  //# sourceMappingURL=client_alarm_tools_extractConditionFields.js.map
@@ -1,7 +1,7 @@
1
- /**
2
- * @module node-opcua-client
3
- */
4
- import { ErrorCallback } from "node-opcua-status-code";
5
- import { ClientSubscription } from "../client_subscription";
6
- export declare function callConditionRefresh(subscription: ClientSubscription): Promise<void>;
7
- export declare function callConditionRefresh(subscription: ClientSubscription, callback: ErrorCallback): void;
1
+ /**
2
+ * @module node-opcua-client
3
+ */
4
+ import { ErrorCallback } from "node-opcua-status-code";
5
+ import { ClientSubscription } from "../client_subscription";
6
+ export declare function callConditionRefresh(subscription: ClientSubscription): Promise<void>;
7
+ export declare function callConditionRefresh(subscription: ClientSubscription, callback: ErrorCallback): void;
@@ -1,181 +1,181 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-client
4
- */
5
- // tslint:disable:no-empty
6
- // tslint:disable: only-arrow-functions
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.callConditionRefresh = void 0;
9
- const async = require("async");
10
- const node_opcua_assert_1 = require("node-opcua-assert");
11
- const node_opcua_data_model_1 = require("node-opcua-data-model");
12
- const node_opcua_debug_1 = require("node-opcua-debug");
13
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
14
- const node_opcua_service_call_1 = require("node-opcua-service-call");
15
- const node_opcua_service_translate_browse_path_1 = require("node-opcua-service-translate-browse-path");
16
- const node_opcua_status_code_1 = require("node-opcua-status-code");
17
- const node_opcua_variant_1 = require("node-opcua-variant");
18
- const client_session_impl_1 = require("../private/client_session_impl");
19
- const debugLog = (0, node_opcua_debug_1.make_debugLog)("A&E");
20
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("A&E");
21
- const warningLog = (0, node_opcua_debug_1.make_warningLog)("A&E");
22
- function callConditionRefresh(subscription, callback) {
23
- const subscriptionI = subscription;
24
- const theSession = subscriptionI.publishEngine.session;
25
- const subscriptionId = subscription.subscriptionId;
26
- (0, node_opcua_assert_1.assert)(isFinite(subscriptionId), "May be subscription is not yet initialized");
27
- (0, node_opcua_assert_1.assert)(typeof callback === "function");
28
- const conditionTypeNodeId = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType");
29
- let conditionRefreshId = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType_ConditionRefresh");
30
- async.series([
31
- // find conditionRefreshId
32
- (innerCallback) => {
33
- const browsePath = (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(conditionTypeNodeId, ".ConditionRefresh");
34
- theSession.translateBrowsePath(browsePath, (err, result) => {
35
- if (!err) {
36
- result = result;
37
- // istanbul ignore else
38
- if (result.targets && result.targets.length > 0) {
39
- conditionRefreshId = result.targets[0].targetId;
40
- }
41
- else {
42
- // cannot find conditionRefreshId
43
- debugLog("cannot find conditionRefreshId", result.toString());
44
- err = new Error(" cannot find conditionRefreshId");
45
- }
46
- }
47
- innerCallback(err ? err : undefined);
48
- });
49
- },
50
- (innerCallback) => {
51
- const methodToCall = {
52
- inputArguments: [new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.UInt32, value: subscriptionId })],
53
- methodId: conditionRefreshId,
54
- objectId: conditionTypeNodeId
55
- };
56
- doDebug && debugLog("Calling method ", new node_opcua_service_call_1.CallMethodRequest(methodToCall).toString());
57
- theSession.call(methodToCall, (err, result) => {
58
- if (err) {
59
- return innerCallback(err);
60
- }
61
- result = result;
62
- // istanbul ignore next
63
- if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
64
- warningLog(new node_opcua_service_call_1.CallMethodRequest(methodToCall).toString());
65
- return innerCallback(new Error("Error " + result.statusCode.toString()));
66
- }
67
- innerCallback();
68
- });
69
- }
70
- ], (err) => {
71
- callback(err || undefined);
72
- });
73
- }
74
- exports.callConditionRefresh = callConditionRefresh;
75
- client_session_impl_1.ClientSessionImpl.prototype.disableCondition = () => {
76
- /** */
77
- };
78
- client_session_impl_1.ClientSessionImpl.prototype.enableCondition = () => {
79
- /** */
80
- };
81
- client_session_impl_1.ClientSessionImpl.prototype.addCommentCondition = function (conditionId, eventId, comment, callback) {
82
- this._callMethodCondition("AddComment", conditionId, eventId, comment, callback);
83
- };
84
- client_session_impl_1.ClientSessionImpl.prototype.findMethodId = function (nodeId, methodName, callback) {
85
- const browsePath = (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(nodeId, "/" + methodName);
86
- let methodId;
87
- this.translateBrowsePath(browsePath, (err, result) => {
88
- if (err) {
89
- return callback(err);
90
- }
91
- /* istanbul ignore next */
92
- if (!result) {
93
- return callback(new Error("Internal Error"));
94
- }
95
- result.targets = result.targets || [];
96
- // istanbul ignore else
97
- if (result.targets.length > 0) {
98
- methodId = result.targets[0].targetId;
99
- return callback(null, methodId);
100
- }
101
- else {
102
- // cannot find objectWithMethodNodeId
103
- debugLog("cannot find " + methodName + " Method", result.toString());
104
- err = new Error(" cannot find " + methodName + " Method");
105
- }
106
- callback(err);
107
- });
108
- };
109
- /**
110
- *
111
- * @param methodName
112
- * @param conditionId
113
- * @param eventId
114
- * @param comment
115
- * @param callback
116
- * @private
117
- */
118
- client_session_impl_1.ClientSessionImpl.prototype._callMethodCondition = function (methodName, conditionId, eventId, comment, callback) {
119
- conditionId = (0, node_opcua_nodeid_1.coerceNodeId)(conditionId);
120
- (0, node_opcua_assert_1.assert)(conditionId instanceof node_opcua_nodeid_1.NodeId);
121
- (0, node_opcua_assert_1.assert)(eventId instanceof Buffer);
122
- (0, node_opcua_assert_1.assert)(typeof comment === "string" || comment instanceof node_opcua_data_model_1.LocalizedText);
123
- comment = node_opcua_data_model_1.LocalizedText.coerce(comment) || new node_opcua_data_model_1.LocalizedText();
124
- let methodId;
125
- let statusCode;
126
- async.series([
127
- (innerCallback) => {
128
- this.findMethodId(conditionId, methodName, (err, _methodId) => {
129
- if (err) {
130
- return innerCallback(err);
131
- }
132
- if (_methodId) {
133
- methodId = _methodId;
134
- }
135
- innerCallback();
136
- });
137
- },
138
- (innerCallback) => {
139
- const methodToCalls = [];
140
- methodToCalls.push(new node_opcua_service_call_1.CallMethodRequest({
141
- inputArguments: [
142
- /* eventId */ new node_opcua_variant_1.Variant({ dataType: "ByteString", value: eventId }),
143
- /* comment */ new node_opcua_variant_1.Variant({ dataType: "LocalizedText", value: comment })
144
- ],
145
- methodId,
146
- objectId: conditionId
147
- }));
148
- this.call(methodToCalls, (err, results) => {
149
- if (err) {
150
- return innerCallback(err);
151
- }
152
- statusCode = results[0].statusCode;
153
- innerCallback();
154
- });
155
- }
156
- ], (err) => {
157
- if (err) {
158
- return callback(err);
159
- }
160
- callback(null, statusCode);
161
- });
162
- };
163
- client_session_impl_1.ClientSessionImpl.prototype.confirmCondition = function (conditionId, eventId, comment, callback) {
164
- // ns=0;i=9113 AcknowledgeableConditionType#Confirm
165
- // note that confirm method is Optionals on condition
166
- this._callMethodCondition("Confirm", conditionId, eventId, comment, callback);
167
- };
168
- client_session_impl_1.ClientSessionImpl.prototype.acknowledgeCondition = function (conditionId, eventId, comment, callback) {
169
- // ns=0;i=9111 AcknowledgeableConditionType#Acknowledge
170
- this._callMethodCondition("Acknowledge", conditionId, eventId, comment, callback);
171
- };
172
- // tslint:disable:no-var-requires
173
- // tslint:disable:max-line-length
174
- const thenify = require("thenify");
175
- const opts = { multiArgs: false };
176
- client_session_impl_1.ClientSessionImpl.prototype.addCommentCondition = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.addCommentCondition, opts);
177
- client_session_impl_1.ClientSessionImpl.prototype.findMethodId = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.findMethodId, opts);
178
- client_session_impl_1.ClientSessionImpl.prototype.confirmCondition = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.confirmCondition, opts);
179
- client_session_impl_1.ClientSessionImpl.prototype.acknowledgeCondition = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.acknowledgeCondition, opts);
180
- module.exports.callConditionRefresh = thenify.withCallback(module.exports.callConditionRefresh, opts);
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-client
4
+ */
5
+ // tslint:disable:no-empty
6
+ // tslint:disable: only-arrow-functions
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.callConditionRefresh = void 0;
9
+ const async = require("async");
10
+ const node_opcua_assert_1 = require("node-opcua-assert");
11
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
12
+ const node_opcua_debug_1 = require("node-opcua-debug");
13
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
14
+ const node_opcua_service_call_1 = require("node-opcua-service-call");
15
+ const node_opcua_service_translate_browse_path_1 = require("node-opcua-service-translate-browse-path");
16
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
17
+ const node_opcua_variant_1 = require("node-opcua-variant");
18
+ const client_session_impl_1 = require("../private/client_session_impl");
19
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)("A&E");
20
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("A&E");
21
+ const warningLog = (0, node_opcua_debug_1.make_warningLog)("A&E");
22
+ function callConditionRefresh(subscription, callback) {
23
+ const subscriptionI = subscription;
24
+ const theSession = subscriptionI.publishEngine.session;
25
+ const subscriptionId = subscription.subscriptionId;
26
+ (0, node_opcua_assert_1.assert)(isFinite(subscriptionId), "May be subscription is not yet initialized");
27
+ (0, node_opcua_assert_1.assert)(typeof callback === "function");
28
+ const conditionTypeNodeId = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType");
29
+ let conditionRefreshId = (0, node_opcua_nodeid_1.resolveNodeId)("ConditionType_ConditionRefresh");
30
+ async.series([
31
+ // find conditionRefreshId
32
+ (innerCallback) => {
33
+ const browsePath = (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(conditionTypeNodeId, ".ConditionRefresh");
34
+ theSession.translateBrowsePath(browsePath, (err, result) => {
35
+ if (!err) {
36
+ result = result;
37
+ // istanbul ignore else
38
+ if (result.targets && result.targets.length > 0) {
39
+ conditionRefreshId = result.targets[0].targetId;
40
+ }
41
+ else {
42
+ // cannot find conditionRefreshId
43
+ debugLog("cannot find conditionRefreshId", result.toString());
44
+ err = new Error(" cannot find conditionRefreshId");
45
+ }
46
+ }
47
+ innerCallback(err ? err : undefined);
48
+ });
49
+ },
50
+ (innerCallback) => {
51
+ const methodToCall = {
52
+ inputArguments: [new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.UInt32, value: subscriptionId })],
53
+ methodId: conditionRefreshId,
54
+ objectId: conditionTypeNodeId
55
+ };
56
+ doDebug && debugLog("Calling method ", new node_opcua_service_call_1.CallMethodRequest(methodToCall).toString());
57
+ theSession.call(methodToCall, (err, result) => {
58
+ if (err) {
59
+ return innerCallback(err);
60
+ }
61
+ result = result;
62
+ // istanbul ignore next
63
+ if (result.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
64
+ warningLog(new node_opcua_service_call_1.CallMethodRequest(methodToCall).toString());
65
+ return innerCallback(new Error("Error " + result.statusCode.toString()));
66
+ }
67
+ innerCallback();
68
+ });
69
+ }
70
+ ], (err) => {
71
+ callback(err || undefined);
72
+ });
73
+ }
74
+ exports.callConditionRefresh = callConditionRefresh;
75
+ client_session_impl_1.ClientSessionImpl.prototype.disableCondition = () => {
76
+ /** */
77
+ };
78
+ client_session_impl_1.ClientSessionImpl.prototype.enableCondition = () => {
79
+ /** */
80
+ };
81
+ client_session_impl_1.ClientSessionImpl.prototype.addCommentCondition = function (conditionId, eventId, comment, callback) {
82
+ this._callMethodCondition("AddComment", conditionId, eventId, comment, callback);
83
+ };
84
+ client_session_impl_1.ClientSessionImpl.prototype.findMethodId = function (nodeId, methodName, callback) {
85
+ const browsePath = (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(nodeId, "/" + methodName);
86
+ let methodId;
87
+ this.translateBrowsePath(browsePath, (err, result) => {
88
+ if (err) {
89
+ return callback(err);
90
+ }
91
+ /* istanbul ignore next */
92
+ if (!result) {
93
+ return callback(new Error("Internal Error"));
94
+ }
95
+ result.targets = result.targets || [];
96
+ // istanbul ignore else
97
+ if (result.targets.length > 0) {
98
+ methodId = result.targets[0].targetId;
99
+ return callback(null, methodId);
100
+ }
101
+ else {
102
+ // cannot find objectWithMethodNodeId
103
+ debugLog("cannot find " + methodName + " Method", result.toString());
104
+ err = new Error(" cannot find " + methodName + " Method");
105
+ }
106
+ callback(err);
107
+ });
108
+ };
109
+ /**
110
+ *
111
+ * @param methodName
112
+ * @param conditionId
113
+ * @param eventId
114
+ * @param comment
115
+ * @param callback
116
+ * @private
117
+ */
118
+ client_session_impl_1.ClientSessionImpl.prototype._callMethodCondition = function (methodName, conditionId, eventId, comment, callback) {
119
+ conditionId = (0, node_opcua_nodeid_1.coerceNodeId)(conditionId);
120
+ (0, node_opcua_assert_1.assert)(conditionId instanceof node_opcua_nodeid_1.NodeId);
121
+ (0, node_opcua_assert_1.assert)(eventId instanceof Buffer);
122
+ (0, node_opcua_assert_1.assert)(typeof comment === "string" || comment instanceof node_opcua_data_model_1.LocalizedText);
123
+ comment = node_opcua_data_model_1.LocalizedText.coerce(comment) || new node_opcua_data_model_1.LocalizedText();
124
+ let methodId;
125
+ let statusCode;
126
+ async.series([
127
+ (innerCallback) => {
128
+ this.findMethodId(conditionId, methodName, (err, _methodId) => {
129
+ if (err) {
130
+ return innerCallback(err);
131
+ }
132
+ if (_methodId) {
133
+ methodId = _methodId;
134
+ }
135
+ innerCallback();
136
+ });
137
+ },
138
+ (innerCallback) => {
139
+ const methodToCalls = [];
140
+ methodToCalls.push(new node_opcua_service_call_1.CallMethodRequest({
141
+ inputArguments: [
142
+ /* eventId */ new node_opcua_variant_1.Variant({ dataType: "ByteString", value: eventId }),
143
+ /* comment */ new node_opcua_variant_1.Variant({ dataType: "LocalizedText", value: comment })
144
+ ],
145
+ methodId,
146
+ objectId: conditionId
147
+ }));
148
+ this.call(methodToCalls, (err, results) => {
149
+ if (err) {
150
+ return innerCallback(err);
151
+ }
152
+ statusCode = results[0].statusCode;
153
+ innerCallback();
154
+ });
155
+ }
156
+ ], (err) => {
157
+ if (err) {
158
+ return callback(err);
159
+ }
160
+ callback(null, statusCode);
161
+ });
162
+ };
163
+ client_session_impl_1.ClientSessionImpl.prototype.confirmCondition = function (conditionId, eventId, comment, callback) {
164
+ // ns=0;i=9113 AcknowledgeableConditionType#Confirm
165
+ // note that confirm method is Optionals on condition
166
+ this._callMethodCondition("Confirm", conditionId, eventId, comment, callback);
167
+ };
168
+ client_session_impl_1.ClientSessionImpl.prototype.acknowledgeCondition = function (conditionId, eventId, comment, callback) {
169
+ // ns=0;i=9111 AcknowledgeableConditionType#Acknowledge
170
+ this._callMethodCondition("Acknowledge", conditionId, eventId, comment, callback);
171
+ };
172
+ // tslint:disable:no-var-requires
173
+ // tslint:disable:max-line-length
174
+ const thenify = require("thenify");
175
+ const opts = { multiArgs: false };
176
+ client_session_impl_1.ClientSessionImpl.prototype.addCommentCondition = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.addCommentCondition, opts);
177
+ client_session_impl_1.ClientSessionImpl.prototype.findMethodId = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.findMethodId, opts);
178
+ client_session_impl_1.ClientSessionImpl.prototype.confirmCondition = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.confirmCondition, opts);
179
+ client_session_impl_1.ClientSessionImpl.prototype.acknowledgeCondition = thenify.withCallback(client_session_impl_1.ClientSessionImpl.prototype.acknowledgeCondition, opts);
180
+ module.exports.callConditionRefresh = thenify.withCallback(module.exports.callConditionRefresh, opts);
181
181
  //# sourceMappingURL=client_tools.js.map