node-opcua-service-filter 2.51.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/LICENSE +20 -0
- package/dist/imports.d.ts +4 -0
- package/dist/imports.js +19 -0
- package/dist/imports.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/tools_event_filter.d.ts +32 -0
- package/dist/tools_event_filter.js +158 -0
- package/dist/tools_event_filter.js.map +1 -0
- package/package.json +47 -0
- package/source/imports.ts +33 -0
- package/source/index.ts +42 -0
- package/source/tools_event_filter.ts +169 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2021 Etienne Rossignon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-service-filter
|
|
3
|
+
*/
|
|
4
|
+
export { FilterOperator, AttributeOperand, ElementOperand, FilterOperand, LiteralOperand, SimpleAttributeOperand, MonitoringFilter, ContentFilterElement, ContentFilter, EventFilter, DataChangeFilter, AttributeOperandOptions, ElementOperandOptions, FilterOperandOptions, LiteralOperandOptions, SimpleAttributeOperandOptions, MonitoringFilterOptions, ContentFilterElementOptions, ContentFilterOptions, EventFilterOptions } from "node-opcua-types";
|
package/dist/imports.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataChangeFilter = exports.EventFilter = exports.ContentFilter = exports.ContentFilterElement = exports.MonitoringFilter = exports.SimpleAttributeOperand = exports.LiteralOperand = exports.FilterOperand = exports.ElementOperand = exports.AttributeOperand = exports.FilterOperator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-service-filter
|
|
6
|
+
*/
|
|
7
|
+
var node_opcua_types_1 = require("node-opcua-types");
|
|
8
|
+
Object.defineProperty(exports, "FilterOperator", { enumerable: true, get: function () { return node_opcua_types_1.FilterOperator; } });
|
|
9
|
+
Object.defineProperty(exports, "AttributeOperand", { enumerable: true, get: function () { return node_opcua_types_1.AttributeOperand; } });
|
|
10
|
+
Object.defineProperty(exports, "ElementOperand", { enumerable: true, get: function () { return node_opcua_types_1.ElementOperand; } });
|
|
11
|
+
Object.defineProperty(exports, "FilterOperand", { enumerable: true, get: function () { return node_opcua_types_1.FilterOperand; } });
|
|
12
|
+
Object.defineProperty(exports, "LiteralOperand", { enumerable: true, get: function () { return node_opcua_types_1.LiteralOperand; } });
|
|
13
|
+
Object.defineProperty(exports, "SimpleAttributeOperand", { enumerable: true, get: function () { return node_opcua_types_1.SimpleAttributeOperand; } });
|
|
14
|
+
Object.defineProperty(exports, "MonitoringFilter", { enumerable: true, get: function () { return node_opcua_types_1.MonitoringFilter; } });
|
|
15
|
+
Object.defineProperty(exports, "ContentFilterElement", { enumerable: true, get: function () { return node_opcua_types_1.ContentFilterElement; } });
|
|
16
|
+
Object.defineProperty(exports, "ContentFilter", { enumerable: true, get: function () { return node_opcua_types_1.ContentFilter; } });
|
|
17
|
+
Object.defineProperty(exports, "EventFilter", { enumerable: true, get: function () { return node_opcua_types_1.EventFilter; } });
|
|
18
|
+
Object.defineProperty(exports, "DataChangeFilter", { enumerable: true, get: function () { return node_opcua_types_1.DataChangeFilter; } });
|
|
19
|
+
//# sourceMappingURL=imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.js","sourceRoot":"","sources":["../source/imports.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,qDA6B0B;AA3BtB,kHAAA,cAAc,OAAA;AAEd,oHAAA,gBAAgB,OAAA;AAChB,kHAAA,cAAc,OAAA;AACd,iHAAA,aAAa,OAAA;AACb,kHAAA,cAAc,OAAA;AACd,0HAAA,sBAAsB,OAAA;AAEtB,oHAAA,gBAAgB,OAAA;AAEhB,wHAAA,oBAAoB,OAAA;AACpB,iHAAA,aAAa,OAAA;AACb,+GAAA,WAAW,OAAA;AACX,oHAAA,gBAAgB,OAAA"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
/**
|
|
14
|
+
* @module node-opcua-service-filter
|
|
15
|
+
*/
|
|
16
|
+
__exportStar(require("./imports"), exports);
|
|
17
|
+
__exportStar(require("./tools_event_filter"), exports);
|
|
18
|
+
// The SimpleAttributeOperand is a simplified form of the AttributeOperand and all of the rules that
|
|
19
|
+
// apply to the AttributeOperand also apply to the SimpleAttributeOperand. The examples provided in
|
|
20
|
+
// B.1 only use AttributeOperand, however, the AttributeOperand can be replaced by a
|
|
21
|
+
// SimpleAttributeOperand whenever all ReferenceTypes in the RelativePath are subtypes of
|
|
22
|
+
// HierarchicalReferences and the targets are Object or Variable Nodes and an Alias is not required
|
|
23
|
+
// typeDefinitionId
|
|
24
|
+
// This parameter restricts the operand to instances of the TypeDefinitionNode or
|
|
25
|
+
// one of its subtypes.
|
|
26
|
+
// { name: "typeDefinitionId", fieldType:"NodeId",documentation:"NodeId of a TypeDefinitionNode."},
|
|
27
|
+
// browsePath
|
|
28
|
+
// A relative path to a Node.
|
|
29
|
+
// This parameter specifies a relative path using a list of BrowseNames instead of
|
|
30
|
+
// the RelativePath structure used in the AttributeOperand. The list of
|
|
31
|
+
// BrowseNames is equivalent to a RelativePath that specifies forward references
|
|
32
|
+
// which are subtypes of the HierarchicalReferences ReferenceType.
|
|
33
|
+
// All Nodes followed by the browsePath shall be of the NodeClass Object or
|
|
34
|
+
// Variable.
|
|
35
|
+
// If this list is empty the Node is the instance of the TypeDefinition.
|
|
36
|
+
// { name: "browsePath", isArray:true, fieldType:"QualifiedName"},
|
|
37
|
+
// Id of the Attribute. The IntegerId is defined in 7.13.
|
|
38
|
+
// The Value Attribute shall be supported by all Servers. The support of other
|
|
39
|
+
// Attributes depends on requirements set in Profiles or other parts of this
|
|
40
|
+
// specification.
|
|
41
|
+
// { name: "attributeId", fieldType:"IntegerId"},
|
|
42
|
+
// This parameter is used to identify a single element of an array, or a single range
|
|
43
|
+
// of indexes for an array. The first element is identified by index 0 (zero).
|
|
44
|
+
// This parameter is ignored if the selected Node is not a Variable or the Value of a
|
|
45
|
+
// Variable is not an array.
|
|
46
|
+
// The parameter is null if not specified.
|
|
47
|
+
// All values in the array are used if this parameter is not specified.
|
|
48
|
+
// The NumericRange type is defined in 7.21.
|
|
49
|
+
// { name: "indexRange", fieldType:"NumericRange"}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;GAEG;AACH,4CAA0B;AAC1B,uDAAqC;AAErC,oGAAoG;AACpG,mGAAmG;AACnG,oFAAoF;AACpF,yFAAyF;AACzF,mGAAmG;AAEnG,mBAAmB;AACnB,iFAAiF;AACjF,uBAAuB;AACvB,mGAAmG;AAEnG,aAAa;AACb,6BAA6B;AAC7B,kFAAkF;AAClF,uEAAuE;AACvE,gFAAgF;AAChF,kEAAkE;AAClE,2EAA2E;AAC3E,YAAY;AACZ,wEAAwE;AACxE,mEAAmE;AAEnE,yDAAyD;AACzD,8EAA8E;AAC9E,4EAA4E;AAC5E,iBAAiB;AACjB,iDAAiD;AAEjD,qFAAqF;AACrF,8EAA8E;AAC9E,qFAAqF;AACrF,4BAA4B;AAC5B,0CAA0C;AAC1C,uEAAuE;AACvE,4CAA4C;AAC5C,kDAAkD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-service-filter
|
|
3
|
+
*/
|
|
4
|
+
import { NodeId } from "node-opcua-nodeid";
|
|
5
|
+
import { EventFilter, SimpleAttributeOperand } from "./imports";
|
|
6
|
+
/**
|
|
7
|
+
* helper to construct event filters:
|
|
8
|
+
* construct a simple event filter
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* constructEventFilter(["SourceName","Message","ReceiveTime"]);
|
|
14
|
+
*
|
|
15
|
+
* constructEventFilter(["SourceName",{namespaceIndex:2 , "MyData"}]);
|
|
16
|
+
* constructEventFilter(["SourceName","2:MyData" ]);
|
|
17
|
+
*
|
|
18
|
+
* constructEventFilter(["SourceName" ,["EnabledState","EffectiveDisplayName"] ]);
|
|
19
|
+
* constructEventFilter(["SourceName" ,"EnabledState.EffectiveDisplayName" ]);
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare function constructEventFilter(arrayOfNames: string[] | string, conditionTypes?: NodeId[] | NodeId): EventFilter;
|
|
23
|
+
/**
|
|
24
|
+
* @class SimpleAttributeOperand
|
|
25
|
+
* @method toShortString
|
|
26
|
+
* @return {String}
|
|
27
|
+
*
|
|
28
|
+
* @example:
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
export declare function simpleAttributeOperandToShortString(self: SimpleAttributeOperand, addressSpace: any): string;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-service-filter
|
|
4
|
+
*/
|
|
5
|
+
// tslint:disable:object-literal-shorthand
|
|
6
|
+
// tslint:disable:only-arrow-functions
|
|
7
|
+
// tslint:disable:max-line-length
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.simpleAttributeOperandToShortString = exports.constructEventFilter = void 0;
|
|
10
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
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 imports_1 = require("./imports");
|
|
15
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
16
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
17
|
+
/**
|
|
18
|
+
* helper to construct event filters:
|
|
19
|
+
* construct a simple event filter
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* constructEventFilter(["SourceName","Message","ReceiveTime"]);
|
|
25
|
+
*
|
|
26
|
+
* constructEventFilter(["SourceName",{namespaceIndex:2 , "MyData"}]);
|
|
27
|
+
* constructEventFilter(["SourceName","2:MyData" ]);
|
|
28
|
+
*
|
|
29
|
+
* constructEventFilter(["SourceName" ,["EnabledState","EffectiveDisplayName"] ]);
|
|
30
|
+
* constructEventFilter(["SourceName" ,"EnabledState.EffectiveDisplayName" ]);
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
function constructEventFilter(arrayOfNames, conditionTypes) {
|
|
34
|
+
if (!Array.isArray(arrayOfNames)) {
|
|
35
|
+
return constructEventFilter([arrayOfNames], conditionTypes);
|
|
36
|
+
}
|
|
37
|
+
if (conditionTypes && !Array.isArray(conditionTypes)) {
|
|
38
|
+
return constructEventFilter(arrayOfNames, [conditionTypes]);
|
|
39
|
+
}
|
|
40
|
+
// istanbul ignore next
|
|
41
|
+
if (!(arrayOfNames instanceof Array)) {
|
|
42
|
+
throw new Error("internal error");
|
|
43
|
+
}
|
|
44
|
+
// replace "string" element in the form A.B.C into [ "A","B","C"]
|
|
45
|
+
const arrayOfNames2 = arrayOfNames.map((path) => {
|
|
46
|
+
if (typeof path !== "string") {
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
49
|
+
return path.split(".");
|
|
50
|
+
});
|
|
51
|
+
const arrayOfNames3 = arrayOfNames2.map((path) => {
|
|
52
|
+
if (Array.isArray(path)) {
|
|
53
|
+
return path.map(node_opcua_data_model_1.stringToQualifiedName);
|
|
54
|
+
}
|
|
55
|
+
return path;
|
|
56
|
+
});
|
|
57
|
+
// replace "string" elements in arrayOfName with QualifiedName in namespace 0
|
|
58
|
+
const arrayOfNames4 = arrayOfNames3.map((s) => {
|
|
59
|
+
return typeof s === "string" ? (0, node_opcua_data_model_1.stringToQualifiedName)(s) : s;
|
|
60
|
+
});
|
|
61
|
+
// construct browse paths array
|
|
62
|
+
const browsePaths = arrayOfNames4.map((s) => {
|
|
63
|
+
return Array.isArray(s) ? s : [s];
|
|
64
|
+
});
|
|
65
|
+
// Part 4 page 127:
|
|
66
|
+
// In some cases the same BrowsePath will apply to multiple EventTypes. If the Client specifies the BaseEventType
|
|
67
|
+
// in the SimpleAttributeOperand then the Server shall evaluate the BrowsePath without considering the Type.
|
|
68
|
+
// [..]
|
|
69
|
+
// The SimpleAttributeOperand structure allows the Client to specify any Attribute, however, the Server is only
|
|
70
|
+
// required to support the Value Attribute for Variable Nodes and the NodeId Attribute for Object Nodes.
|
|
71
|
+
// That said, profiles defined in Part 7 may make support for additional Attributes mandatory.
|
|
72
|
+
let selectClauses = browsePaths.map((browsePath) => {
|
|
73
|
+
return new imports_1.SimpleAttributeOperand({
|
|
74
|
+
attributeId: node_opcua_data_model_1.AttributeIds.Value,
|
|
75
|
+
browsePath,
|
|
76
|
+
indexRange: undefined,
|
|
77
|
+
typeDefinitionId: (0, node_opcua_nodeid_1.makeNodeId)(node_opcua_constants_1.ObjectTypeIds.BaseEventType) // i=2041
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
if (conditionTypes && conditionTypes instanceof Array) {
|
|
81
|
+
const extraSelectClauses = conditionTypes.map((nodeId) => {
|
|
82
|
+
return new imports_1.SimpleAttributeOperand({
|
|
83
|
+
attributeId: node_opcua_data_model_1.AttributeIds.NodeId,
|
|
84
|
+
browsePath: undefined,
|
|
85
|
+
indexRange: undefined,
|
|
86
|
+
typeDefinitionId: nodeId // conditionType for instance
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
selectClauses = selectClauses.concat(extraSelectClauses);
|
|
90
|
+
}
|
|
91
|
+
const filter = new imports_1.EventFilter({
|
|
92
|
+
selectClauses: selectClauses,
|
|
93
|
+
whereClause: {
|
|
94
|
+
// ContentFilter
|
|
95
|
+
elements: [
|
|
96
|
+
// ContentFilterElement
|
|
97
|
+
// {
|
|
98
|
+
// filterOperator: FilterOperator.IsNull,
|
|
99
|
+
// filterOperands: [ //
|
|
100
|
+
// new ElementOperand({
|
|
101
|
+
// index: 123
|
|
102
|
+
// }),
|
|
103
|
+
// new AttributeOperand({
|
|
104
|
+
// nodeId: "i=10",
|
|
105
|
+
// alias: "someText",
|
|
106
|
+
// browsePath: { //RelativePath
|
|
107
|
+
//
|
|
108
|
+
// },
|
|
109
|
+
// attributeId: AttributeIds.Value
|
|
110
|
+
// })
|
|
111
|
+
// ]
|
|
112
|
+
// }
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return filter;
|
|
117
|
+
}
|
|
118
|
+
exports.constructEventFilter = constructEventFilter;
|
|
119
|
+
/**
|
|
120
|
+
* @class SimpleAttributeOperand
|
|
121
|
+
* @method toPath
|
|
122
|
+
* @return {String}
|
|
123
|
+
*
|
|
124
|
+
* @example:
|
|
125
|
+
*
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
function simpleAttributeOperandToPath(self) {
|
|
129
|
+
if (!self.browsePath) {
|
|
130
|
+
return "";
|
|
131
|
+
}
|
|
132
|
+
return self.browsePath
|
|
133
|
+
.map((a) => {
|
|
134
|
+
return a.name;
|
|
135
|
+
})
|
|
136
|
+
.join("/");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @class SimpleAttributeOperand
|
|
140
|
+
* @method toShortString
|
|
141
|
+
* @return {String}
|
|
142
|
+
*
|
|
143
|
+
* @example:
|
|
144
|
+
*
|
|
145
|
+
*
|
|
146
|
+
*/
|
|
147
|
+
function simpleAttributeOperandToShortString(self, addressSpace // Address Space
|
|
148
|
+
) {
|
|
149
|
+
let str = "";
|
|
150
|
+
if (addressSpace) {
|
|
151
|
+
const n = addressSpace.findNode(self.typeDefinitionId);
|
|
152
|
+
str += n.BrowseName.toString();
|
|
153
|
+
}
|
|
154
|
+
str += "[" + self.typeDefinitionId.toString() + "]" + simpleAttributeOperandToPath(self);
|
|
155
|
+
return str;
|
|
156
|
+
}
|
|
157
|
+
exports.simpleAttributeOperandToShortString = simpleAttributeOperandToShortString;
|
|
158
|
+
//# sourceMappingURL=tools_event_filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools_event_filter.js","sourceRoot":"","sources":["../source/tools_event_filter.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,0CAA0C;AAC1C,sCAAsC;AACtC,iCAAiC;;;AAGjC,+DAAqD;AACrD,iEAA4E;AAC5E,uDAAiE;AACjE,yDAAkF;AAGlF,uCAAgE;AAEhE,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,OAAO,GAAG,IAAA,iCAAc,EAAC,UAAU,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,oBAAoB,CAAC,YAA+B,EAAE,cAAkC;IACpG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QAC9B,OAAO,oBAAoB,CAAC,CAAC,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC;KAC/D;IACD,IAAI,cAAc,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QAClD,OAAO,oBAAoB,CAAC,YAAY,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;KAC/D;IACD,uBAAuB;IACvB,IAAI,CAAC,CAAC,YAAY,YAAY,KAAK,CAAC,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;KACrC;IACD,iEAAiE;IACjE,MAAM,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ,E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AY,EAAE;QACd,MAAM,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAE,CAAC;QACxD,GAAG,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;KAClC;IACD,GAAG,IAAI,GAAG,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,4BAA4B,CAAC,IAAI,CAAC,CAAC;IACzF,OAAO,GAAG,CAAC;AACf,CAAC;AAXD,kFAWC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-opcua-service-filter",
|
|
3
|
+
"version": "2.51.0",
|
|
4
|
+
"description": "pure nodejs OPCUA SDK - module -service-filter",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "mocha",
|
|
9
|
+
"clean": "node -e \"require('rimraf').sync('dist');\"",
|
|
10
|
+
"build": "tsc -b"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"node-opcua-assert": "2.51.0",
|
|
14
|
+
"node-opcua-basic-types": "2.51.0",
|
|
15
|
+
"node-opcua-binary-stream": "2.51.0",
|
|
16
|
+
"node-opcua-constants": "2.51.0",
|
|
17
|
+
"node-opcua-data-model": "2.51.0",
|
|
18
|
+
"node-opcua-debug": "2.51.0",
|
|
19
|
+
"node-opcua-factory": "2.51.0",
|
|
20
|
+
"node-opcua-nodeid": "2.51.0",
|
|
21
|
+
"node-opcua-numeric-range": "2.51.0",
|
|
22
|
+
"node-opcua-service-translate-browse-path": "2.51.0",
|
|
23
|
+
"node-opcua-status-code": "2.51.0",
|
|
24
|
+
"node-opcua-types": "2.51.0",
|
|
25
|
+
"node-opcua-variant": "2.51.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"node-opcua-service-secure-channel": "2.51.0",
|
|
29
|
+
"should": "^13.2.3"
|
|
30
|
+
},
|
|
31
|
+
"author": "Etienne Rossignon",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git://github.com/node-opcua/node-opcua.git"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"OPCUA",
|
|
39
|
+
"opcua",
|
|
40
|
+
"m2m",
|
|
41
|
+
"iot",
|
|
42
|
+
"opc ua",
|
|
43
|
+
"internet of things"
|
|
44
|
+
],
|
|
45
|
+
"homepage": "http://node-opcua.github.io/",
|
|
46
|
+
"gitHead": "75feb111daf7ec65fa0111e4fa5beb8987fd4945"
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-service-filter
|
|
3
|
+
*/
|
|
4
|
+
export {
|
|
5
|
+
|
|
6
|
+
FilterOperator,
|
|
7
|
+
|
|
8
|
+
AttributeOperand,
|
|
9
|
+
ElementOperand,
|
|
10
|
+
FilterOperand,
|
|
11
|
+
LiteralOperand,
|
|
12
|
+
SimpleAttributeOperand,
|
|
13
|
+
|
|
14
|
+
MonitoringFilter,
|
|
15
|
+
|
|
16
|
+
ContentFilterElement,
|
|
17
|
+
ContentFilter,
|
|
18
|
+
EventFilter,
|
|
19
|
+
DataChangeFilter,
|
|
20
|
+
|
|
21
|
+
AttributeOperandOptions,
|
|
22
|
+
ElementOperandOptions,
|
|
23
|
+
FilterOperandOptions,
|
|
24
|
+
LiteralOperandOptions,
|
|
25
|
+
SimpleAttributeOperandOptions,
|
|
26
|
+
|
|
27
|
+
MonitoringFilterOptions,
|
|
28
|
+
|
|
29
|
+
ContentFilterElementOptions,
|
|
30
|
+
ContentFilterOptions,
|
|
31
|
+
EventFilterOptions
|
|
32
|
+
|
|
33
|
+
} from "node-opcua-types";
|
package/source/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-service-filter
|
|
3
|
+
*/
|
|
4
|
+
export * from "./imports";
|
|
5
|
+
export * from "./tools_event_filter";
|
|
6
|
+
|
|
7
|
+
// The SimpleAttributeOperand is a simplified form of the AttributeOperand and all of the rules that
|
|
8
|
+
// apply to the AttributeOperand also apply to the SimpleAttributeOperand. The examples provided in
|
|
9
|
+
// B.1 only use AttributeOperand, however, the AttributeOperand can be replaced by a
|
|
10
|
+
// SimpleAttributeOperand whenever all ReferenceTypes in the RelativePath are subtypes of
|
|
11
|
+
// HierarchicalReferences and the targets are Object or Variable Nodes and an Alias is not required
|
|
12
|
+
|
|
13
|
+
// typeDefinitionId
|
|
14
|
+
// This parameter restricts the operand to instances of the TypeDefinitionNode or
|
|
15
|
+
// one of its subtypes.
|
|
16
|
+
// { name: "typeDefinitionId", fieldType:"NodeId",documentation:"NodeId of a TypeDefinitionNode."},
|
|
17
|
+
|
|
18
|
+
// browsePath
|
|
19
|
+
// A relative path to a Node.
|
|
20
|
+
// This parameter specifies a relative path using a list of BrowseNames instead of
|
|
21
|
+
// the RelativePath structure used in the AttributeOperand. The list of
|
|
22
|
+
// BrowseNames is equivalent to a RelativePath that specifies forward references
|
|
23
|
+
// which are subtypes of the HierarchicalReferences ReferenceType.
|
|
24
|
+
// All Nodes followed by the browsePath shall be of the NodeClass Object or
|
|
25
|
+
// Variable.
|
|
26
|
+
// If this list is empty the Node is the instance of the TypeDefinition.
|
|
27
|
+
// { name: "browsePath", isArray:true, fieldType:"QualifiedName"},
|
|
28
|
+
|
|
29
|
+
// Id of the Attribute. The IntegerId is defined in 7.13.
|
|
30
|
+
// The Value Attribute shall be supported by all Servers. The support of other
|
|
31
|
+
// Attributes depends on requirements set in Profiles or other parts of this
|
|
32
|
+
// specification.
|
|
33
|
+
// { name: "attributeId", fieldType:"IntegerId"},
|
|
34
|
+
|
|
35
|
+
// This parameter is used to identify a single element of an array, or a single range
|
|
36
|
+
// of indexes for an array. The first element is identified by index 0 (zero).
|
|
37
|
+
// This parameter is ignored if the selected Node is not a Variable or the Value of a
|
|
38
|
+
// Variable is not an array.
|
|
39
|
+
// The parameter is null if not specified.
|
|
40
|
+
// All values in the array are used if this parameter is not specified.
|
|
41
|
+
// The NumericRange type is defined in 7.21.
|
|
42
|
+
// { name: "indexRange", fieldType:"NumericRange"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-service-filter
|
|
3
|
+
*/
|
|
4
|
+
// tslint:disable:object-literal-shorthand
|
|
5
|
+
// tslint:disable:only-arrow-functions
|
|
6
|
+
// tslint:disable:max-line-length
|
|
7
|
+
|
|
8
|
+
import { assert } from "node-opcua-assert";
|
|
9
|
+
import { ObjectTypeIds } from "node-opcua-constants";
|
|
10
|
+
import { AttributeIds, stringToQualifiedName } from "node-opcua-data-model";
|
|
11
|
+
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
|
|
12
|
+
import { makeNodeId, NodeId, resolveNodeId, sameNodeId } from "node-opcua-nodeid";
|
|
13
|
+
import { DataType, Variant } from "node-opcua-variant";
|
|
14
|
+
|
|
15
|
+
import { EventFilter, SimpleAttributeOperand } from "./imports";
|
|
16
|
+
|
|
17
|
+
const debugLog = make_debugLog(__filename);
|
|
18
|
+
const doDebug = checkDebugFlag(__filename);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* helper to construct event filters:
|
|
22
|
+
* construct a simple event filter
|
|
23
|
+
*
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
* constructEventFilter(["SourceName","Message","ReceiveTime"]);
|
|
28
|
+
*
|
|
29
|
+
* constructEventFilter(["SourceName",{namespaceIndex:2 , "MyData"}]);
|
|
30
|
+
* constructEventFilter(["SourceName","2:MyData" ]);
|
|
31
|
+
*
|
|
32
|
+
* constructEventFilter(["SourceName" ,["EnabledState","EffectiveDisplayName"] ]);
|
|
33
|
+
* constructEventFilter(["SourceName" ,"EnabledState.EffectiveDisplayName" ]);
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export function constructEventFilter(arrayOfNames: string[] | string, conditionTypes?: NodeId[] | NodeId): EventFilter {
|
|
37
|
+
if (!Array.isArray(arrayOfNames)) {
|
|
38
|
+
return constructEventFilter([arrayOfNames], conditionTypes);
|
|
39
|
+
}
|
|
40
|
+
if (conditionTypes && !Array.isArray(conditionTypes)) {
|
|
41
|
+
return constructEventFilter(arrayOfNames, [conditionTypes]);
|
|
42
|
+
}
|
|
43
|
+
// istanbul ignore next
|
|
44
|
+
if (!(arrayOfNames instanceof Array)) {
|
|
45
|
+
throw new Error("internal error");
|
|
46
|
+
}
|
|
47
|
+
// replace "string" element in the form A.B.C into [ "A","B","C"]
|
|
48
|
+
const arrayOfNames2 = arrayOfNames.map((path) => {
|
|
49
|
+
if (typeof path !== "string") {
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
return path.split(".");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const arrayOfNames3 = arrayOfNames2.map((path) => {
|
|
56
|
+
if (Array.isArray(path)) {
|
|
57
|
+
return path.map(stringToQualifiedName);
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
});
|
|
61
|
+
// replace "string" elements in arrayOfName with QualifiedName in namespace 0
|
|
62
|
+
const arrayOfNames4 = arrayOfNames3.map((s) => {
|
|
63
|
+
return typeof s === "string" ? stringToQualifiedName(s) : s;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// construct browse paths array
|
|
67
|
+
const browsePaths = arrayOfNames4.map((s) => {
|
|
68
|
+
return Array.isArray(s) ? s : [s];
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Part 4 page 127:
|
|
72
|
+
// In some cases the same BrowsePath will apply to multiple EventTypes. If the Client specifies the BaseEventType
|
|
73
|
+
// in the SimpleAttributeOperand then the Server shall evaluate the BrowsePath without considering the Type.
|
|
74
|
+
|
|
75
|
+
// [..]
|
|
76
|
+
// The SimpleAttributeOperand structure allows the Client to specify any Attribute, however, the Server is only
|
|
77
|
+
// required to support the Value Attribute for Variable Nodes and the NodeId Attribute for Object Nodes.
|
|
78
|
+
// That said, profiles defined in Part 7 may make support for additional Attributes mandatory.
|
|
79
|
+
let selectClauses = browsePaths.map((browsePath) => {
|
|
80
|
+
return new SimpleAttributeOperand({
|
|
81
|
+
attributeId: AttributeIds.Value,
|
|
82
|
+
browsePath,
|
|
83
|
+
indexRange: undefined, // NumericRange
|
|
84
|
+
typeDefinitionId: makeNodeId(ObjectTypeIds.BaseEventType) // i=2041
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (conditionTypes && conditionTypes instanceof Array) {
|
|
89
|
+
const extraSelectClauses = conditionTypes.map((nodeId) => {
|
|
90
|
+
return new SimpleAttributeOperand({
|
|
91
|
+
attributeId: AttributeIds.NodeId,
|
|
92
|
+
browsePath: undefined,
|
|
93
|
+
indexRange: undefined, // NumericRange
|
|
94
|
+
typeDefinitionId: nodeId // conditionType for instance
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
selectClauses = selectClauses.concat(extraSelectClauses);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const filter = new EventFilter({
|
|
101
|
+
selectClauses: selectClauses,
|
|
102
|
+
|
|
103
|
+
whereClause: {
|
|
104
|
+
// ContentFilter
|
|
105
|
+
elements: [
|
|
106
|
+
// ContentFilterElement
|
|
107
|
+
// {
|
|
108
|
+
// filterOperator: FilterOperator.IsNull,
|
|
109
|
+
// filterOperands: [ //
|
|
110
|
+
// new ElementOperand({
|
|
111
|
+
// index: 123
|
|
112
|
+
// }),
|
|
113
|
+
// new AttributeOperand({
|
|
114
|
+
// nodeId: "i=10",
|
|
115
|
+
// alias: "someText",
|
|
116
|
+
// browsePath: { //RelativePath
|
|
117
|
+
//
|
|
118
|
+
// },
|
|
119
|
+
// attributeId: AttributeIds.Value
|
|
120
|
+
// })
|
|
121
|
+
// ]
|
|
122
|
+
// }
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return filter;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @class SimpleAttributeOperand
|
|
131
|
+
* @method toPath
|
|
132
|
+
* @return {String}
|
|
133
|
+
*
|
|
134
|
+
* @example:
|
|
135
|
+
*
|
|
136
|
+
*
|
|
137
|
+
*/
|
|
138
|
+
function simpleAttributeOperandToPath(self: SimpleAttributeOperand): string {
|
|
139
|
+
if (!self.browsePath) {
|
|
140
|
+
return "";
|
|
141
|
+
}
|
|
142
|
+
return self.browsePath
|
|
143
|
+
.map((a) => {
|
|
144
|
+
return a.name;
|
|
145
|
+
})
|
|
146
|
+
.join("/");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @class SimpleAttributeOperand
|
|
151
|
+
* @method toShortString
|
|
152
|
+
* @return {String}
|
|
153
|
+
*
|
|
154
|
+
* @example:
|
|
155
|
+
*
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
export function simpleAttributeOperandToShortString(
|
|
159
|
+
self: SimpleAttributeOperand,
|
|
160
|
+
addressSpace: any // Address Space
|
|
161
|
+
): string {
|
|
162
|
+
let str = "";
|
|
163
|
+
if (addressSpace) {
|
|
164
|
+
const n = addressSpace.findNode(self.typeDefinitionId)!;
|
|
165
|
+
str += n.BrowseName.toString();
|
|
166
|
+
}
|
|
167
|
+
str += "[" + self.typeDefinitionId.toString() + "]" + simpleAttributeOperandToPath(self);
|
|
168
|
+
return str;
|
|
169
|
+
}
|