node-opcua-nodeid 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/.mocharc.yml ADDED
@@ -0,0 +1,4 @@
1
+ recursive: true
2
+ bail: true
3
+ require:
4
+ - ../../node_modules/source-map-support/register
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,68 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * @module node-opcua-nodeid
4
+ */
5
+ import { Guid } from "node-opcua-guid";
6
+ import { NodeId, NodeIdType } from "./nodeid";
7
+ /**
8
+ * An ExpandedNodeId extends the NodeId structure.
9
+ *
10
+ * An ExpandedNodeId extends the NodeId structure by allowing the NamespaceUri to be
11
+ * explicitly specified instead of using the NamespaceIndex. The NamespaceUri is optional. If it
12
+ * is specified then the NamespaceIndex inside the NodeId shall be ignored.
13
+ *
14
+ * The ExpandedNodeId is encoded by first encoding a NodeId as described in Clause 5 .2.2.9
15
+ * and then encoding NamespaceUri as a String.
16
+ *
17
+ * An instance of an ExpandedNodeId may still use the NamespaceIndex instead of the
18
+ * NamespaceUri. In this case, the NamespaceUri is not encoded in the stream. The presence of
19
+ * the NamespaceUri in the stream is indicated by setting the NamespaceUri flag in the encoding
20
+ * format byte for the NodeId.
21
+ *
22
+ * If the NamespaceUri is present then the encoder shall encode the NamespaceIndex as 0 in
23
+ * the stream when the NodeId portion is encoded. The unused NamespaceIndex is included in
24
+ * the stream for consistency,
25
+ *
26
+ * An ExpandedNodeId may also have a ServerIndex which is encoded as a UInt32 after the
27
+ * NamespaceUri. The ServerIndex flag in the NodeId encoding byte indicates whether the
28
+ * ServerIndex is present in the stream. The ServerIndex is omitted if it is equal to zero.
29
+ *
30
+ * @class ExpandedNodeId
31
+ * @extends NodeId
32
+ *
33
+ *
34
+ *
35
+ * @param identifierType - the nodeID type
36
+ * @param value - the node id value. The type of Value depends on identifierType.
37
+ * @param namespace - the index of the related namespace (optional , default value = 0 )
38
+ * @param namespaceUri - NamespaceUri
39
+ * @param serverIndex - the server Index
40
+ * @constructor
41
+ */
42
+ export declare class ExpandedNodeId extends NodeId {
43
+ static nullExpandedNodeId: ExpandedNodeId;
44
+ static fromNodeId(nodeId: NodeId, namespaceUri?: string, serverIndex?: number): ExpandedNodeId;
45
+ namespaceUri: null | string;
46
+ serverIndex: number;
47
+ constructor(forDeserialization: null);
48
+ constructor(identifierType: NodeIdType, value: number | string | Guid | Buffer, namespace: number, namespaceUri?: null | string, serverIndex?: number);
49
+ /**
50
+ * @method toString
51
+ * @return {string}
52
+ */
53
+ toString(): string;
54
+ /**
55
+ * convert nodeId to a JSON string. same as {@link NodeId#toString }
56
+ * @method toJSON
57
+ * @return {String}
58
+ */
59
+ toJSON(): any;
60
+ }
61
+ export declare function coerceExpandedNodeId(value: any): ExpandedNodeId;
62
+ /**
63
+ * @method makeExpandedNodeId
64
+ * @param value
65
+ * @param [namespace=0] the namespace
66
+ * @return {ExpandedNodeId}
67
+ */
68
+ export declare function makeExpandedNodeId(value: any, namespace?: number): ExpandedNodeId;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeExpandedNodeId = exports.coerceExpandedNodeId = exports.ExpandedNodeId = void 0;
4
+ const nodeid_1 = require("./nodeid");
5
+ /**
6
+ * An ExpandedNodeId extends the NodeId structure.
7
+ *
8
+ * An ExpandedNodeId extends the NodeId structure by allowing the NamespaceUri to be
9
+ * explicitly specified instead of using the NamespaceIndex. The NamespaceUri is optional. If it
10
+ * is specified then the NamespaceIndex inside the NodeId shall be ignored.
11
+ *
12
+ * The ExpandedNodeId is encoded by first encoding a NodeId as described in Clause 5 .2.2.9
13
+ * and then encoding NamespaceUri as a String.
14
+ *
15
+ * An instance of an ExpandedNodeId may still use the NamespaceIndex instead of the
16
+ * NamespaceUri. In this case, the NamespaceUri is not encoded in the stream. The presence of
17
+ * the NamespaceUri in the stream is indicated by setting the NamespaceUri flag in the encoding
18
+ * format byte for the NodeId.
19
+ *
20
+ * If the NamespaceUri is present then the encoder shall encode the NamespaceIndex as 0 in
21
+ * the stream when the NodeId portion is encoded. The unused NamespaceIndex is included in
22
+ * the stream for consistency,
23
+ *
24
+ * An ExpandedNodeId may also have a ServerIndex which is encoded as a UInt32 after the
25
+ * NamespaceUri. The ServerIndex flag in the NodeId encoding byte indicates whether the
26
+ * ServerIndex is present in the stream. The ServerIndex is omitted if it is equal to zero.
27
+ *
28
+ * @class ExpandedNodeId
29
+ * @extends NodeId
30
+ *
31
+ *
32
+ *
33
+ * @param identifierType - the nodeID type
34
+ * @param value - the node id value. The type of Value depends on identifierType.
35
+ * @param namespace - the index of the related namespace (optional , default value = 0 )
36
+ * @param namespaceUri - NamespaceUri
37
+ * @param serverIndex - the server Index
38
+ * @constructor
39
+ */
40
+ class ExpandedNodeId extends nodeid_1.NodeId {
41
+ constructor(identifierType, value, namespace, namespaceUri, serverIndex) {
42
+ super(identifierType, value, namespace);
43
+ this.namespaceUri = namespaceUri || null;
44
+ this.serverIndex = serverIndex || 0;
45
+ }
46
+ static fromNodeId(nodeId, namespaceUri, serverIndex) {
47
+ return new ExpandedNodeId(nodeId.identifierType, nodeId.value, nodeId.namespace, namespaceUri, serverIndex);
48
+ }
49
+ /**
50
+ * @method toString
51
+ * @return {string}
52
+ */
53
+ toString() {
54
+ let str = nodeid_1.NodeId.prototype.toString.call(this);
55
+ if (this.namespaceUri) {
56
+ str += ";namespaceUri:" + this.namespaceUri;
57
+ }
58
+ if (this.serverIndex) {
59
+ str += ";serverIndex:" + this.serverIndex;
60
+ }
61
+ return str;
62
+ }
63
+ /**
64
+ * convert nodeId to a JSON string. same as {@link NodeId#toString }
65
+ * @method toJSON
66
+ * @return {String}
67
+ */
68
+ toJSON() {
69
+ return this.toString();
70
+ }
71
+ }
72
+ exports.ExpandedNodeId = ExpandedNodeId;
73
+ ExpandedNodeId.nullExpandedNodeId = new ExpandedNodeId(nodeid_1.NodeIdType.NUMERIC, 0, 0);
74
+ function coerceExpandedNodeId(value) {
75
+ const n = (0, nodeid_1.coerceNodeId)(value);
76
+ return new ExpandedNodeId(n.identifierType, n.value, n.namespace, /*namespaceUri*/ null, /*serverIndex*/ 0);
77
+ }
78
+ exports.coerceExpandedNodeId = coerceExpandedNodeId;
79
+ /**
80
+ * @method makeExpandedNodeId
81
+ * @param value
82
+ * @param [namespace=0] the namespace
83
+ * @return {ExpandedNodeId}
84
+ */
85
+ function makeExpandedNodeId(value, namespace) {
86
+ if (value === undefined && namespace === undefined) {
87
+ return new ExpandedNodeId(nodeid_1.NodeIdType.NUMERIC, 0, 0, null, 0);
88
+ }
89
+ const serverIndex = 0;
90
+ let n;
91
+ const namespaceUri = null;
92
+ if (value instanceof ExpandedNodeId) {
93
+ // construct from a ExpandedNodeId => copy
94
+ n = value;
95
+ return new ExpandedNodeId(n.identifierType, n.value, n.namespace, n.namespaceUri, n.serverIndex);
96
+ }
97
+ if (value instanceof nodeid_1.NodeId) {
98
+ // construct from a nodeId
99
+ n = value;
100
+ return new ExpandedNodeId(n.identifierType, n.value, n.namespace, namespaceUri, serverIndex);
101
+ }
102
+ const valueInt = parseInt(value, 10);
103
+ if (!isFinite(valueInt)) {
104
+ throw new Error(" cannot makeExpandedNodeId out of " + value);
105
+ }
106
+ namespace = namespace || 0;
107
+ return new ExpandedNodeId(nodeid_1.NodeIdType.NUMERIC, valueInt, namespace, namespaceUri, serverIndex);
108
+ }
109
+ exports.makeExpandedNodeId = makeExpandedNodeId;
110
+ //# sourceMappingURL=expanded_nodeid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expanded_nodeid.js","sourceRoot":"","sources":["../source/expanded_nodeid.ts"],"names":[],"mappings":";;;AAIA,qCAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,cAAe,SAAQ,eAAM;IAkBtC,YACI,cAAkC,EAClC,KAAuC,EACvC,SAAkB,EAClB,YAA4B,EAC5B,WAAoB;QAEpB,KAAK,CAAC,cAAc,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,IAAI,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,CAAC,CAAC;IACxC,CAAC;IAzBM,MAAM,CAAC,UAAU,CAAC,MAAc,EAAE,YAAqB,EAAE,WAAoB;QAChF,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IAChH,CAAC;IAyBD;;;OAGG;IACI,QAAQ;QACX,IAAI,GAAG,GAAG,eAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC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AAY,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;KACpG;IACD,IAAI,KAAK,YAAY,eAAM,EAAE;QACzB,0BAA0B;QAC1B,CAAC,GAAG,KAAK,CAAC;QACV,OAAO,IAAI,cAAc,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;KAChG;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,KAAK,CAAC,CAAC;KACjE;IACD,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC;IAC3B,OAAO,IAAI,cAAc,CAAC,mBAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAClG,CAAC;AAzBD,gDAyBC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @module node-opcua-nodeid
3
+ */
4
+ export * from "./nodeid";
5
+ export * from "./expanded_nodeid";
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
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-nodeid
15
+ */
16
+ __exportStar(require("./nodeid"), exports);
17
+ __exportStar(require("./expanded_nodeid"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;GAEG;AACH,2CAAyB;AACzB,oDAAkC"}
@@ -0,0 +1,121 @@
1
+ /// <reference types="node" />
2
+ import { Guid } from "node-opcua-guid";
3
+ /**
4
+ * `NodeIdType` an enumeration that specifies the possible types of a `NodeId` value.
5
+ */
6
+ export declare enum NodeIdType {
7
+ /**
8
+ * @static
9
+ * @property NUMERIC
10
+ * @default 0x1
11
+ */
12
+ NUMERIC = 1,
13
+ /**
14
+ * @static
15
+ * @property STRING
16
+ * @default 0x2
17
+ */
18
+ STRING = 2,
19
+ /**
20
+ * @static
21
+ * @property GUID
22
+ * @default 0x3
23
+ */
24
+ GUID = 3,
25
+ /**
26
+ * @static
27
+ * @property BYTESTRING
28
+ * @default 0x4
29
+ */
30
+ BYTESTRING = 4
31
+ }
32
+ /**
33
+ * Construct a node ID
34
+ *
35
+ * @class NodeId
36
+ * @example
37
+ *
38
+ * ``` javascript
39
+ * const nodeId = new NodeId(NodeIdType.NUMERIC,123,1);
40
+ * ```
41
+ * @constructor
42
+ */
43
+ export declare class NodeId {
44
+ static NodeIdType: typeof NodeIdType;
45
+ static nullNodeId: NodeId;
46
+ static resolveNodeId: (a: string | NodeId) => NodeId;
47
+ static sameNodeId: (n1: NodeId, n2: NodeId) => boolean;
48
+ identifierType: NodeIdType;
49
+ value: number | string | Buffer | Guid;
50
+ namespace: number;
51
+ /**
52
+ * @param identifierType - the nodeID type
53
+ * @param value - the node id value. The type of Value depends on identifierType.
54
+ * @param namespace - the index of the related namespace (optional , default value = 0 )
55
+ */
56
+ constructor(identifierType?: NodeIdType | null, value?: any, namespace?: number);
57
+ /**
58
+ * get the string representation of the nodeID.
59
+ *
60
+ * @method toString
61
+ * @example
62
+ *
63
+ * ``` javascript
64
+ * const nodeid = new NodeId(NodeIdType.NUMERIC, 123,1);
65
+ * console.log(nodeid.toString());
66
+ * ```
67
+ *
68
+ * ```
69
+ * >"ns=1;i=123"
70
+ * ```
71
+ *
72
+ * @param [options.addressSpace] {AddressSpace}
73
+ * @return {String}
74
+ */
75
+ toString(options?: {
76
+ addressSpace?: any;
77
+ }): string;
78
+ /**
79
+ * convert nodeId to a JSON string. same as {@link NodeId#toString }
80
+ */
81
+ toJSON(): string;
82
+ displayText(): string;
83
+ /**
84
+ * returns true if the NodeId is null or empty
85
+ */
86
+ isEmpty(): boolean;
87
+ }
88
+ export declare type NodeIdLike = string | NodeId | number;
89
+ /**
90
+ * Convert a value into a nodeId:
91
+ * @class opcua
92
+ * @method coerceNodeId
93
+ * @static
94
+ *
95
+ * @description:
96
+ * - if nodeId is a string of form : "i=1234" => nodeId({value=1234, identifierType: NodeIdType.NUMERIC})
97
+ * - if nodeId is a string of form : "s=foo" => nodeId({value="foo", identifierType: NodeIdType.STRING})
98
+ * - if nodeId is a {@link NodeId} : coerceNodeId returns value
99
+ * @param value
100
+ * @param namespace {number}
101
+ */
102
+ export declare function coerceNodeId(value: any, namespace?: number): NodeId;
103
+ /**
104
+ * construct a node Id from a value and a namespace.
105
+ * @class opcua
106
+ * @method makeNodeId
107
+ * @static
108
+ * @param {String|Buffer} value
109
+ * @param [namespace]=0 {Number} the node id namespace
110
+ * @return {NodeId}
111
+ */
112
+ export declare function makeNodeId(value: string | Buffer | number, namespace?: number): NodeId;
113
+ /**
114
+ * @class opcua
115
+ * @method resolveNodeId
116
+ * @static
117
+ * @param nodeIdOrString
118
+ * @return the nodeId
119
+ */
120
+ export declare function resolveNodeId(nodeIdOrString: NodeIdLike): NodeId;
121
+ export declare function sameNodeId(n1: NodeId, n2: NodeId): boolean;
package/dist/nodeid.js ADDED
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sameNodeId = exports.resolveNodeId = exports.makeNodeId = exports.coerceNodeId = exports.NodeId = exports.NodeIdType = void 0;
4
+ /**
5
+ * @module node-opcua-nodeid
6
+ */
7
+ // tslint:disable:no-conditional-assignment
8
+ const chalk = require("chalk");
9
+ const lodash_1 = require("lodash");
10
+ const node_opcua_assert_1 = require("node-opcua-assert");
11
+ const node_opcua_constants_1 = require("node-opcua-constants");
12
+ const node_opcua_guid_1 = require("node-opcua-guid");
13
+ /**
14
+ * `NodeIdType` an enumeration that specifies the possible types of a `NodeId` value.
15
+ */
16
+ var NodeIdType;
17
+ (function (NodeIdType) {
18
+ /**
19
+ * @static
20
+ * @property NUMERIC
21
+ * @default 0x1
22
+ */
23
+ NodeIdType[NodeIdType["NUMERIC"] = 1] = "NUMERIC";
24
+ /**
25
+ * @static
26
+ * @property STRING
27
+ * @default 0x2
28
+ */
29
+ NodeIdType[NodeIdType["STRING"] = 2] = "STRING";
30
+ /**
31
+ * @static
32
+ * @property GUID
33
+ * @default 0x3
34
+ */
35
+ NodeIdType[NodeIdType["GUID"] = 3] = "GUID";
36
+ /**
37
+ * @static
38
+ * @property BYTESTRING
39
+ * @default 0x4
40
+ */
41
+ NodeIdType[NodeIdType["BYTESTRING"] = 4] = "BYTESTRING";
42
+ })(NodeIdType = exports.NodeIdType || (exports.NodeIdType = {}));
43
+ /**
44
+ * Construct a node ID
45
+ *
46
+ * @class NodeId
47
+ * @example
48
+ *
49
+ * ``` javascript
50
+ * const nodeId = new NodeId(NodeIdType.NUMERIC,123,1);
51
+ * ```
52
+ * @constructor
53
+ */
54
+ class NodeId {
55
+ /**
56
+ * @param identifierType - the nodeID type
57
+ * @param value - the node id value. The type of Value depends on identifierType.
58
+ * @param namespace - the index of the related namespace (optional , default value = 0 )
59
+ */
60
+ constructor(identifierType, value, namespace) {
61
+ if (identifierType === null || identifierType === undefined) {
62
+ this.identifierType = NodeIdType.NUMERIC;
63
+ this.value = 0;
64
+ this.namespace = 0;
65
+ return;
66
+ }
67
+ this.identifierType = identifierType;
68
+ this.value = value;
69
+ this.namespace = namespace || 0;
70
+ // namespace shall be a UInt16
71
+ (0, node_opcua_assert_1.assert)(this.namespace >= 0 && this.namespace <= 0xffff);
72
+ (0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.NUMERIC || (this.value >= 0 && this.value <= 0xffffffff));
73
+ (0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.GUID || (0, node_opcua_guid_1.isValidGuid)(this.value));
74
+ (0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.STRING || typeof this.value === "string");
75
+ }
76
+ /**
77
+ * get the string representation of the nodeID.
78
+ *
79
+ * @method toString
80
+ * @example
81
+ *
82
+ * ``` javascript
83
+ * const nodeid = new NodeId(NodeIdType.NUMERIC, 123,1);
84
+ * console.log(nodeid.toString());
85
+ * ```
86
+ *
87
+ * ```
88
+ * >"ns=1;i=123"
89
+ * ```
90
+ *
91
+ * @param [options.addressSpace] {AddressSpace}
92
+ * @return {String}
93
+ */
94
+ toString(options) {
95
+ const addressSpace = options ? options.addressSpace : null;
96
+ let str;
97
+ switch (this.identifierType) {
98
+ case NodeIdType.NUMERIC:
99
+ str = "ns=" + this.namespace + ";i=" + this.value;
100
+ break;
101
+ case NodeIdType.STRING:
102
+ str = "ns=" + this.namespace + ";s=" + this.value;
103
+ break;
104
+ case NodeIdType.GUID:
105
+ str = "ns=" + this.namespace + ";g=" + this.value;
106
+ break;
107
+ default:
108
+ (0, node_opcua_assert_1.assert)(this.identifierType === NodeIdType.BYTESTRING, "invalid identifierType in NodeId : " + this.identifierType);
109
+ if (this.value) {
110
+ str = "ns=" + this.namespace + ";b=" + this.value.toString("base64");
111
+ }
112
+ else {
113
+ str = "ns=" + this.namespace + ";b=<null>";
114
+ }
115
+ break;
116
+ }
117
+ if (addressSpace) {
118
+ if (this.namespace === 0 && this.identifierType === NodeIdType.NUMERIC) {
119
+ // find standard browse name
120
+ const name = reverse_map(this.value.toString()) || "<undefined>";
121
+ str += " " + chalk.green.bold(name);
122
+ }
123
+ else if (addressSpace.findNode) {
124
+ // let use the provided address space to figure out the browseNode of this node.
125
+ // to make the message a little bit more useful.
126
+ const n = addressSpace.findNode(this);
127
+ str += " " + (n ? n.browseName.toString() : " (????)");
128
+ }
129
+ }
130
+ return str;
131
+ }
132
+ /**
133
+ * convert nodeId to a JSON string. same as {@link NodeId#toString }
134
+ */
135
+ toJSON() {
136
+ return this.toString();
137
+ }
138
+ displayText() {
139
+ if (this.namespace === 0 && this.identifierType === NodeIdType.NUMERIC) {
140
+ const name = reverse_map(this.value.toString());
141
+ if (name) {
142
+ return name + " (" + this.toString() + ")";
143
+ }
144
+ }
145
+ return this.toString();
146
+ }
147
+ /**
148
+ * returns true if the NodeId is null or empty
149
+ */
150
+ isEmpty() {
151
+ switch (this.identifierType) {
152
+ case NodeIdType.NUMERIC:
153
+ return this.value === 0;
154
+ case NodeIdType.STRING:
155
+ return !this.value || this.value.length === 0;
156
+ case NodeIdType.GUID:
157
+ return !this.value || this.value === node_opcua_guid_1.emptyGuid;
158
+ default:
159
+ (0, node_opcua_assert_1.assert)(this.identifierType === NodeIdType.BYTESTRING, "invalid identifierType in NodeId : " + this.identifierType);
160
+ return !this.value || this.value.length === 0;
161
+ }
162
+ }
163
+ }
164
+ exports.NodeId = NodeId;
165
+ NodeId.NodeIdType = NodeIdType;
166
+ NodeId.nullNodeId = new NodeId();
167
+ const regexNamespaceI = /ns=([0-9]+);i=([0-9]+)/;
168
+ const regexNamespaceS = /ns=([0-9]+);s=(.*)/;
169
+ const regexNamespaceB = /ns=([0-9]+);b=(.*)/;
170
+ const regexNamespaceG = /ns=([0-9]+);g=(.*)/;
171
+ /**
172
+ * Convert a value into a nodeId:
173
+ * @class opcua
174
+ * @method coerceNodeId
175
+ * @static
176
+ *
177
+ * @description:
178
+ * - if nodeId is a string of form : "i=1234" => nodeId({value=1234, identifierType: NodeIdType.NUMERIC})
179
+ * - if nodeId is a string of form : "s=foo" => nodeId({value="foo", identifierType: NodeIdType.STRING})
180
+ * - if nodeId is a {@link NodeId} : coerceNodeId returns value
181
+ * @param value
182
+ * @param namespace {number}
183
+ */
184
+ function coerceNodeId(value, namespace) {
185
+ let matches;
186
+ let twoFirst;
187
+ if (value instanceof NodeId) {
188
+ return value;
189
+ }
190
+ value = value || 0;
191
+ namespace = namespace || 0;
192
+ let identifierType = NodeIdType.NUMERIC;
193
+ if (typeof value === "string") {
194
+ identifierType = NodeIdType.STRING;
195
+ twoFirst = value.substr(0, 2);
196
+ if (twoFirst === "i=") {
197
+ identifierType = NodeIdType.NUMERIC;
198
+ value = parseInt(value.substr(2), 10);
199
+ }
200
+ else if (twoFirst === "s=") {
201
+ identifierType = NodeIdType.STRING;
202
+ value = value.substr(2);
203
+ }
204
+ else if (twoFirst === "b=") {
205
+ identifierType = NodeIdType.BYTESTRING;
206
+ value = Buffer.from(value.substr(2), "base64");
207
+ }
208
+ else if (twoFirst === "g=") {
209
+ identifierType = NodeIdType.GUID;
210
+ value = value.substr(2);
211
+ }
212
+ else if ((0, node_opcua_guid_1.isValidGuid)(value)) {
213
+ identifierType = NodeIdType.GUID;
214
+ }
215
+ else if ((matches = regexNamespaceI.exec(value)) !== null) {
216
+ identifierType = NodeIdType.NUMERIC;
217
+ namespace = parseInt(matches[1], 10);
218
+ value = parseInt(matches[2], 10);
219
+ }
220
+ else if ((matches = regexNamespaceS.exec(value)) !== null) {
221
+ identifierType = NodeIdType.STRING;
222
+ namespace = parseInt(matches[1], 10);
223
+ value = matches[2];
224
+ }
225
+ else if ((matches = regexNamespaceB.exec(value)) !== null) {
226
+ identifierType = NodeIdType.BYTESTRING;
227
+ namespace = parseInt(matches[1], 10);
228
+ value = Buffer.from(matches[2], "base64");
229
+ }
230
+ else if ((matches = regexNamespaceG.exec(value)) !== null) {
231
+ identifierType = NodeIdType.GUID;
232
+ namespace = parseInt(matches[1], 10);
233
+ value = matches[2];
234
+ }
235
+ else {
236
+ throw new Error("String cannot be coerced to a nodeId : " + value);
237
+ }
238
+ }
239
+ else if (value instanceof Buffer) {
240
+ identifierType = NodeIdType.BYTESTRING;
241
+ }
242
+ else if (value instanceof Object) {
243
+ // it could be a Enum or a NodeId Like object
244
+ const tmp = value;
245
+ value = tmp.value;
246
+ namespace = namespace || tmp.namespace;
247
+ identifierType = tmp.identifierType || identifierType;
248
+ return new NodeId(identifierType, value, namespace);
249
+ }
250
+ return new NodeId(identifierType, value, namespace);
251
+ }
252
+ exports.coerceNodeId = coerceNodeId;
253
+ const regEx1 = /^(s|g|b|i|ns)=/;
254
+ /**
255
+ * construct a node Id from a value and a namespace.
256
+ * @class opcua
257
+ * @method makeNodeId
258
+ * @static
259
+ * @param {String|Buffer} value
260
+ * @param [namespace]=0 {Number} the node id namespace
261
+ * @return {NodeId}
262
+ */
263
+ function makeNodeId(value, namespace) {
264
+ value = value || 0;
265
+ namespace = namespace || 0;
266
+ let identifierType = NodeIdType.NUMERIC;
267
+ if (typeof value === "string") {
268
+ if (value.match(regEx1)) {
269
+ throw new Error("please use coerce NodeId instead");
270
+ }
271
+ // 1 2 3
272
+ // 012345678901234567890123456789012345
273
+ // "72962B91-FA75-4AE6-8D28-B404DC7DAF63"
274
+ if ((0, node_opcua_guid_1.isValidGuid)(value)) {
275
+ identifierType = NodeIdType.GUID;
276
+ }
277
+ else {
278
+ identifierType = NodeIdType.STRING;
279
+ }
280
+ }
281
+ else if (value instanceof Buffer) {
282
+ identifierType = NodeIdType.BYTESTRING;
283
+ }
284
+ const nodeId = new NodeId(identifierType, value, namespace);
285
+ return nodeId;
286
+ }
287
+ exports.makeNodeId = makeNodeId;
288
+ // reverse maps
289
+ let _nodeIdToNameIndex = {};
290
+ let _nameToNodeIdIndex = {};
291
+ const regName = /[a-zA-Z_].*/;
292
+ (function build_standard_nodeid_indexes() {
293
+ function expand_map(directIndex) {
294
+ for (const name in directIndex) {
295
+ if (directIndex.hasOwnProperty(name) && regName.exec(name) !== null) {
296
+ const value = directIndex[name];
297
+ _nodeIdToNameIndex[value] = name;
298
+ _nameToNodeIdIndex[name] = new NodeId(NodeIdType.NUMERIC, value, 0);
299
+ }
300
+ }
301
+ }
302
+ _nodeIdToNameIndex = {};
303
+ _nameToNodeIdIndex = {};
304
+ expand_map(node_opcua_constants_1.ObjectIds);
305
+ expand_map(node_opcua_constants_1.ObjectTypeIds);
306
+ expand_map(node_opcua_constants_1.VariableIds);
307
+ expand_map(node_opcua_constants_1.VariableTypeIds);
308
+ expand_map(node_opcua_constants_1.MethodIds);
309
+ expand_map(node_opcua_constants_1.ReferenceTypeIds);
310
+ expand_map(node_opcua_constants_1.DataTypeIds);
311
+ })();
312
+ function reverse_map(nodeId) {
313
+ return _nodeIdToNameIndex[nodeId];
314
+ }
315
+ /**
316
+ * @class opcua
317
+ * @method resolveNodeId
318
+ * @static
319
+ * @param nodeIdOrString
320
+ * @return the nodeId
321
+ */
322
+ function resolveNodeId(nodeIdOrString) {
323
+ let nodeId;
324
+ const rawId = typeof nodeIdOrString === "string" ? _nameToNodeIdIndex[nodeIdOrString] : undefined;
325
+ if (rawId !== undefined) {
326
+ return rawId;
327
+ }
328
+ else {
329
+ nodeId = coerceNodeId(nodeIdOrString);
330
+ }
331
+ return nodeId;
332
+ }
333
+ exports.resolveNodeId = resolveNodeId;
334
+ NodeId.resolveNodeId = resolveNodeId;
335
+ function sameNodeId(n1, n2) {
336
+ if (n1.identifierType !== n2.identifierType) {
337
+ return false;
338
+ }
339
+ if (n1.namespace !== n2.namespace) {
340
+ return false;
341
+ }
342
+ switch (n1.identifierType) {
343
+ case NodeIdType.NUMERIC:
344
+ case NodeIdType.STRING:
345
+ return n1.value === n2.value;
346
+ default:
347
+ return (0, lodash_1.isEqual)(n1.value, n2.value);
348
+ }
349
+ }
350
+ exports.sameNodeId = sameNodeId;
351
+ NodeId.sameNodeId = sameNodeId;
352
+ //# sourceMappingURL=nodeid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeid.js","sourceRoot":"","sources":["../source/nodeid.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2CAA2C;AAC3C,+BAA+B;AAC/B,mCAAiC;AACjC,yDAA2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AO,IAAA,gBAAO,EAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;KAC1C;AACL,CAAC;AAdD,gCAcC;AAED,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "node-opcua-nodeid",
3
+ "main": "./dist/index.js",
4
+ "types": "./dist/index.d.ts",
5
+ "version": "2.51.0",
6
+ "description": "pure nodejs OPCUA SDK - module -nodeid",
7
+ "scripts": {
8
+ "build": "tsc -b",
9
+ "lint": "tslint source/**/*.ts",
10
+ "clean": "node -e \"require('rimraf').sync('dist');\"",
11
+ "test": "mocha"
12
+ },
13
+ "dependencies": {
14
+ "@types/lodash": "4.14.172",
15
+ "chalk": "4.1.2",
16
+ "lodash": "4.17.21",
17
+ "node-opcua-assert": "2.51.0",
18
+ "node-opcua-constants": "2.51.0",
19
+ "node-opcua-enum": "2.51.0",
20
+ "node-opcua-guid": "2.51.0"
21
+ },
22
+ "devDependencies": {
23
+ "node-opcua-benchmarker": "2.51.0",
24
+ "node-opcua-debug": "2.51.0",
25
+ "should": "^13.2.3",
26
+ "source-map-support": "^0.5.19"
27
+ },
28
+ "author": "Etienne Rossignon",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git://github.com/node-opcua/node-opcua.git"
33
+ },
34
+ "keywords": [
35
+ "OPCUA",
36
+ "opcua",
37
+ "m2m",
38
+ "iot",
39
+ "opc ua",
40
+ "internet of things"
41
+ ],
42
+ "homepage": "http://node-opcua.github.io/",
43
+ "gitHead": "75feb111daf7ec65fa0111e4fa5beb8987fd4945"
44
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @module node-opcua-nodeid
3
+ */
4
+ import { Guid } from "node-opcua-guid";
5
+ import { coerceNodeId, NodeId, NodeIdType } from "./nodeid";
6
+
7
+ /**
8
+ * An ExpandedNodeId extends the NodeId structure.
9
+ *
10
+ * An ExpandedNodeId extends the NodeId structure by allowing the NamespaceUri to be
11
+ * explicitly specified instead of using the NamespaceIndex. The NamespaceUri is optional. If it
12
+ * is specified then the NamespaceIndex inside the NodeId shall be ignored.
13
+ *
14
+ * The ExpandedNodeId is encoded by first encoding a NodeId as described in Clause 5 .2.2.9
15
+ * and then encoding NamespaceUri as a String.
16
+ *
17
+ * An instance of an ExpandedNodeId may still use the NamespaceIndex instead of the
18
+ * NamespaceUri. In this case, the NamespaceUri is not encoded in the stream. The presence of
19
+ * the NamespaceUri in the stream is indicated by setting the NamespaceUri flag in the encoding
20
+ * format byte for the NodeId.
21
+ *
22
+ * If the NamespaceUri is present then the encoder shall encode the NamespaceIndex as 0 in
23
+ * the stream when the NodeId portion is encoded. The unused NamespaceIndex is included in
24
+ * the stream for consistency,
25
+ *
26
+ * An ExpandedNodeId may also have a ServerIndex which is encoded as a UInt32 after the
27
+ * NamespaceUri. The ServerIndex flag in the NodeId encoding byte indicates whether the
28
+ * ServerIndex is present in the stream. The ServerIndex is omitted if it is equal to zero.
29
+ *
30
+ * @class ExpandedNodeId
31
+ * @extends NodeId
32
+ *
33
+ *
34
+ *
35
+ * @param identifierType - the nodeID type
36
+ * @param value - the node id value. The type of Value depends on identifierType.
37
+ * @param namespace - the index of the related namespace (optional , default value = 0 )
38
+ * @param namespaceUri - NamespaceUri
39
+ * @param serverIndex - the server Index
40
+ * @constructor
41
+ */
42
+ export class ExpandedNodeId extends NodeId {
43
+ public static nullExpandedNodeId = new ExpandedNodeId(NodeIdType.NUMERIC, 0, 0);
44
+
45
+ public static fromNodeId(nodeId: NodeId, namespaceUri?: string, serverIndex?: number): ExpandedNodeId {
46
+ return new ExpandedNodeId(nodeId.identifierType, nodeId.value, nodeId.namespace, namespaceUri, serverIndex);
47
+ }
48
+
49
+ public namespaceUri: null | string;
50
+ public serverIndex: number;
51
+
52
+ public constructor(forDeserialization: null);
53
+ public constructor(
54
+ identifierType: NodeIdType,
55
+ value: number | string | Guid | Buffer,
56
+ namespace: number,
57
+ namespaceUri?: null | string,
58
+ serverIndex?: number
59
+ );
60
+ public constructor(
61
+ identifierType?: NodeIdType | null,
62
+ value?: number | string | Guid | Buffer,
63
+ namespace?: number,
64
+ namespaceUri?: null | string,
65
+ serverIndex?: number
66
+ ) {
67
+ super(identifierType, value, namespace);
68
+ this.namespaceUri = namespaceUri || null;
69
+ this.serverIndex = serverIndex || 0;
70
+ }
71
+
72
+ /**
73
+ * @method toString
74
+ * @return {string}
75
+ */
76
+ public toString() {
77
+ let str = NodeId.prototype.toString.call(this);
78
+ if (this.namespaceUri) {
79
+ str += ";namespaceUri:" + this.namespaceUri;
80
+ }
81
+ if (this.serverIndex) {
82
+ str += ";serverIndex:" + this.serverIndex;
83
+ }
84
+ return str;
85
+ }
86
+
87
+ /**
88
+ * convert nodeId to a JSON string. same as {@link NodeId#toString }
89
+ * @method toJSON
90
+ * @return {String}
91
+ */
92
+ public toJSON(): any {
93
+ return this.toString();
94
+ }
95
+ }
96
+
97
+ export function coerceExpandedNodeId(value: any): ExpandedNodeId {
98
+ const n = coerceNodeId(value);
99
+ return new ExpandedNodeId(n.identifierType, n.value, n.namespace, /*namespaceUri*/ null, /*serverIndex*/ 0);
100
+ }
101
+
102
+ /**
103
+ * @method makeExpandedNodeId
104
+ * @param value
105
+ * @param [namespace=0] the namespace
106
+ * @return {ExpandedNodeId}
107
+ */
108
+ export function makeExpandedNodeId(value: any, namespace?: number) {
109
+ if (value === undefined && namespace === undefined) {
110
+ return new ExpandedNodeId(NodeIdType.NUMERIC, 0, 0, null, 0);
111
+ }
112
+ const serverIndex = 0;
113
+ let n;
114
+ const namespaceUri = null;
115
+
116
+ if (value instanceof ExpandedNodeId) {
117
+ // construct from a ExpandedNodeId => copy
118
+ n = value;
119
+ return new ExpandedNodeId(n.identifierType, n.value, n.namespace, n.namespaceUri, n.serverIndex);
120
+ }
121
+ if (value instanceof NodeId) {
122
+ // construct from a nodeId
123
+ n = value;
124
+ return new ExpandedNodeId(n.identifierType, n.value, n.namespace, namespaceUri, serverIndex);
125
+ }
126
+
127
+ const valueInt = parseInt(value, 10);
128
+ if (!isFinite(valueInt)) {
129
+ throw new Error(" cannot makeExpandedNodeId out of " + value);
130
+ }
131
+ namespace = namespace || 0;
132
+ return new ExpandedNodeId(NodeIdType.NUMERIC, valueInt, namespace, namespaceUri, serverIndex);
133
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @module node-opcua-nodeid
3
+ */
4
+ export * from "./nodeid";
5
+ export * from "./expanded_nodeid";
@@ -0,0 +1,373 @@
1
+ /**
2
+ * @module node-opcua-nodeid
3
+ */
4
+ // tslint:disable:no-conditional-assignment
5
+ import * as chalk from "chalk";
6
+ import { isEqual } from "lodash";
7
+ import { assert } from "node-opcua-assert";
8
+ import {
9
+ DataTypeIds,
10
+ MethodIds,
11
+ ObjectIds,
12
+ ObjectTypeIds,
13
+ ReferenceTypeIds,
14
+ VariableIds,
15
+ VariableTypeIds
16
+ } from "node-opcua-constants";
17
+ import { emptyGuid, Guid, isValidGuid } from "node-opcua-guid";
18
+
19
+ /**
20
+ * `NodeIdType` an enumeration that specifies the possible types of a `NodeId` value.
21
+ */
22
+ export enum NodeIdType {
23
+ /**
24
+ * @static
25
+ * @property NUMERIC
26
+ * @default 0x1
27
+ */
28
+ NUMERIC = 0x01,
29
+ /**
30
+ * @static
31
+ * @property STRING
32
+ * @default 0x2
33
+ */
34
+ STRING = 0x02,
35
+ /**
36
+ * @static
37
+ * @property GUID
38
+ * @default 0x3
39
+ */
40
+ GUID = 0x03,
41
+ /**
42
+ * @static
43
+ * @property BYTESTRING
44
+ * @default 0x4
45
+ */
46
+ BYTESTRING = 0x04
47
+ }
48
+
49
+ /**
50
+ * Construct a node ID
51
+ *
52
+ * @class NodeId
53
+ * @example
54
+ *
55
+ * ``` javascript
56
+ * const nodeId = new NodeId(NodeIdType.NUMERIC,123,1);
57
+ * ```
58
+ * @constructor
59
+ */
60
+ export class NodeId {
61
+ public static NodeIdType = NodeIdType;
62
+ public static nullNodeId: NodeId;
63
+ public static resolveNodeId: (a: string | NodeId) => NodeId;
64
+ public static sameNodeId: (n1: NodeId, n2: NodeId) => boolean;
65
+
66
+ public identifierType: NodeIdType;
67
+ public value: number | string | Buffer | Guid;
68
+ public namespace: number;
69
+
70
+ /**
71
+ * @param identifierType - the nodeID type
72
+ * @param value - the node id value. The type of Value depends on identifierType.
73
+ * @param namespace - the index of the related namespace (optional , default value = 0 )
74
+ */
75
+ constructor(identifierType?: NodeIdType | null, value?: any, namespace?: number) {
76
+ if (identifierType === null || identifierType === undefined) {
77
+ this.identifierType = NodeIdType.NUMERIC;
78
+ this.value = 0;
79
+ this.namespace = 0;
80
+ return;
81
+ }
82
+ this.identifierType = identifierType;
83
+ this.value = value;
84
+ this.namespace = namespace || 0;
85
+
86
+ // namespace shall be a UInt16
87
+ assert(this.namespace >= 0 && this.namespace <= 0xffff);
88
+
89
+ assert(this.identifierType !== NodeIdType.NUMERIC || (this.value >= 0 && this.value <= 0xffffffff));
90
+ assert(this.identifierType !== NodeIdType.GUID || isValidGuid(this.value as string));
91
+ assert(this.identifierType !== NodeIdType.STRING || typeof this.value === "string");
92
+ }
93
+
94
+ /**
95
+ * get the string representation of the nodeID.
96
+ *
97
+ * @method toString
98
+ * @example
99
+ *
100
+ * ``` javascript
101
+ * const nodeid = new NodeId(NodeIdType.NUMERIC, 123,1);
102
+ * console.log(nodeid.toString());
103
+ * ```
104
+ *
105
+ * ```
106
+ * >"ns=1;i=123"
107
+ * ```
108
+ *
109
+ * @param [options.addressSpace] {AddressSpace}
110
+ * @return {String}
111
+ */
112
+ public toString(options?: { addressSpace?: any }): string {
113
+ const addressSpace = options ? options.addressSpace : null;
114
+ let str;
115
+ switch (this.identifierType) {
116
+ case NodeIdType.NUMERIC:
117
+ str = "ns=" + this.namespace + ";i=" + this.value;
118
+ break;
119
+ case NodeIdType.STRING:
120
+ str = "ns=" + this.namespace + ";s=" + this.value;
121
+ break;
122
+ case NodeIdType.GUID:
123
+ str = "ns=" + this.namespace + ";g=" + this.value;
124
+ break;
125
+ default:
126
+ assert(this.identifierType === NodeIdType.BYTESTRING, "invalid identifierType in NodeId : " + this.identifierType);
127
+ if (this.value) {
128
+ str = "ns=" + this.namespace + ";b=" + (this.value as Buffer).toString("base64");
129
+ } else {
130
+ str = "ns=" + this.namespace + ";b=<null>";
131
+ }
132
+ break;
133
+ }
134
+
135
+ if (addressSpace) {
136
+ if (this.namespace === 0 && this.identifierType === NodeIdType.NUMERIC) {
137
+ // find standard browse name
138
+ const name = reverse_map(this.value.toString()) || "<undefined>";
139
+ str += " " + chalk.green.bold(name);
140
+ } else if (addressSpace.findNode) {
141
+ // let use the provided address space to figure out the browseNode of this node.
142
+ // to make the message a little bit more useful.
143
+ const n = addressSpace.findNode(this);
144
+ str += " " + (n ? n.browseName.toString() : " (????)");
145
+ }
146
+ }
147
+ return str;
148
+ }
149
+
150
+ /**
151
+ * convert nodeId to a JSON string. same as {@link NodeId#toString }
152
+ */
153
+ public toJSON(): string {
154
+ return this.toString();
155
+ }
156
+
157
+ public displayText(): string {
158
+ if (this.namespace === 0 && this.identifierType === NodeIdType.NUMERIC) {
159
+ const name = reverse_map(this.value.toString());
160
+ if (name) {
161
+ return name + " (" + this.toString() + ")";
162
+ }
163
+ }
164
+ return this.toString();
165
+ }
166
+
167
+ /**
168
+ * returns true if the NodeId is null or empty
169
+ */
170
+ public isEmpty(): boolean {
171
+ switch (this.identifierType) {
172
+ case NodeIdType.NUMERIC:
173
+ return this.value === 0;
174
+ case NodeIdType.STRING:
175
+ return !this.value || (this.value as string).length === 0;
176
+ case NodeIdType.GUID:
177
+ return !this.value || this.value === emptyGuid;
178
+ default:
179
+ assert(this.identifierType === NodeIdType.BYTESTRING, "invalid identifierType in NodeId : " + this.identifierType);
180
+ return !this.value || (this.value as Buffer).length === 0;
181
+ }
182
+ }
183
+ }
184
+
185
+ NodeId.nullNodeId = new NodeId();
186
+
187
+ export type NodeIdLike = string | NodeId | number;
188
+
189
+ const regexNamespaceI = /ns=([0-9]+);i=([0-9]+)/;
190
+ const regexNamespaceS = /ns=([0-9]+);s=(.*)/;
191
+ const regexNamespaceB = /ns=([0-9]+);b=(.*)/;
192
+ const regexNamespaceG = /ns=([0-9]+);g=(.*)/;
193
+
194
+ /**
195
+ * Convert a value into a nodeId:
196
+ * @class opcua
197
+ * @method coerceNodeId
198
+ * @static
199
+ *
200
+ * @description:
201
+ * - if nodeId is a string of form : "i=1234" => nodeId({value=1234, identifierType: NodeIdType.NUMERIC})
202
+ * - if nodeId is a string of form : "s=foo" => nodeId({value="foo", identifierType: NodeIdType.STRING})
203
+ * - if nodeId is a {@link NodeId} : coerceNodeId returns value
204
+ * @param value
205
+ * @param namespace {number}
206
+ */
207
+ export function coerceNodeId(value: any, namespace?: number): NodeId {
208
+ let matches;
209
+ let twoFirst;
210
+ if (value instanceof NodeId) {
211
+ return value;
212
+ }
213
+
214
+ value = value || 0;
215
+ namespace = namespace || 0;
216
+
217
+ let identifierType = NodeIdType.NUMERIC;
218
+
219
+ if (typeof value === "string") {
220
+ identifierType = NodeIdType.STRING;
221
+
222
+ twoFirst = value.substr(0, 2);
223
+ if (twoFirst === "i=") {
224
+ identifierType = NodeIdType.NUMERIC;
225
+ value = parseInt(value.substr(2), 10);
226
+ } else if (twoFirst === "s=") {
227
+ identifierType = NodeIdType.STRING;
228
+ value = value.substr(2);
229
+ } else if (twoFirst === "b=") {
230
+ identifierType = NodeIdType.BYTESTRING;
231
+ value = Buffer.from(value.substr(2), "base64");
232
+ } else if (twoFirst === "g=") {
233
+ identifierType = NodeIdType.GUID;
234
+ value = value.substr(2);
235
+ } else if (isValidGuid(value)) {
236
+ identifierType = NodeIdType.GUID;
237
+ } else if ((matches = regexNamespaceI.exec(value)) !== null) {
238
+ identifierType = NodeIdType.NUMERIC;
239
+ namespace = parseInt(matches[1], 10);
240
+ value = parseInt(matches[2], 10);
241
+ } else if ((matches = regexNamespaceS.exec(value)) !== null) {
242
+ identifierType = NodeIdType.STRING;
243
+ namespace = parseInt(matches[1], 10);
244
+ value = matches[2];
245
+ } else if ((matches = regexNamespaceB.exec(value)) !== null) {
246
+ identifierType = NodeIdType.BYTESTRING;
247
+ namespace = parseInt(matches[1], 10);
248
+ value = Buffer.from(matches[2], "base64");
249
+ } else if ((matches = regexNamespaceG.exec(value)) !== null) {
250
+ identifierType = NodeIdType.GUID;
251
+ namespace = parseInt(matches[1], 10);
252
+ value = matches[2];
253
+ } else {
254
+ throw new Error("String cannot be coerced to a nodeId : " + value);
255
+ }
256
+ } else if (value instanceof Buffer) {
257
+ identifierType = NodeIdType.BYTESTRING;
258
+ } else if (value instanceof Object) {
259
+ // it could be a Enum or a NodeId Like object
260
+ const tmp = value;
261
+ value = tmp.value;
262
+ namespace = namespace || tmp.namespace;
263
+ identifierType = tmp.identifierType || identifierType;
264
+ return new NodeId(identifierType, value, namespace);
265
+ }
266
+ return new NodeId(identifierType, value, namespace);
267
+ }
268
+
269
+ const regEx1 = /^(s|g|b|i|ns)=/;
270
+ /**
271
+ * construct a node Id from a value and a namespace.
272
+ * @class opcua
273
+ * @method makeNodeId
274
+ * @static
275
+ * @param {String|Buffer} value
276
+ * @param [namespace]=0 {Number} the node id namespace
277
+ * @return {NodeId}
278
+ */
279
+ export function makeNodeId(value: string | Buffer | number, namespace?: number) {
280
+ value = value || 0;
281
+ namespace = namespace || 0;
282
+
283
+ let identifierType = NodeIdType.NUMERIC;
284
+ if (typeof value === "string") {
285
+ if (value.match(regEx1)) {
286
+ throw new Error("please use coerce NodeId instead");
287
+ }
288
+ // 1 2 3
289
+ // 012345678901234567890123456789012345
290
+ // "72962B91-FA75-4AE6-8D28-B404DC7DAF63"
291
+ if (isValidGuid(value)) {
292
+ identifierType = NodeIdType.GUID;
293
+ } else {
294
+ identifierType = NodeIdType.STRING;
295
+ }
296
+ } else if (value instanceof Buffer) {
297
+ identifierType = NodeIdType.BYTESTRING;
298
+ }
299
+
300
+ const nodeId = new NodeId(identifierType, value, namespace);
301
+ return nodeId;
302
+ }
303
+
304
+ // reverse maps
305
+ let _nodeIdToNameIndex: any = {};
306
+ let _nameToNodeIdIndex: any = {};
307
+
308
+ const regName = /[a-zA-Z_].*/;
309
+
310
+ (function build_standard_nodeid_indexes() {
311
+ function expand_map(directIndex: any) {
312
+ for (const name in directIndex) {
313
+ if (directIndex.hasOwnProperty(name) && regName.exec(name) !== null) {
314
+ const value = directIndex[name];
315
+ _nodeIdToNameIndex[value] = name;
316
+ _nameToNodeIdIndex[name] = new NodeId(NodeIdType.NUMERIC, value, 0);
317
+ }
318
+ }
319
+ }
320
+
321
+ _nodeIdToNameIndex = {};
322
+ _nameToNodeIdIndex = {};
323
+ expand_map(ObjectIds);
324
+ expand_map(ObjectTypeIds);
325
+ expand_map(VariableIds);
326
+ expand_map(VariableTypeIds);
327
+ expand_map(MethodIds);
328
+ expand_map(ReferenceTypeIds);
329
+ expand_map(DataTypeIds);
330
+ })();
331
+
332
+ function reverse_map(nodeId: string) {
333
+ return _nodeIdToNameIndex[nodeId];
334
+ }
335
+
336
+ /**
337
+ * @class opcua
338
+ * @method resolveNodeId
339
+ * @static
340
+ * @param nodeIdOrString
341
+ * @return the nodeId
342
+ */
343
+ export function resolveNodeId(nodeIdOrString: NodeIdLike): NodeId {
344
+ let nodeId;
345
+
346
+ const rawId = typeof nodeIdOrString === "string" ? _nameToNodeIdIndex[nodeIdOrString] : undefined;
347
+ if (rawId !== undefined) {
348
+ return rawId;
349
+ } else {
350
+ nodeId = coerceNodeId(nodeIdOrString);
351
+ }
352
+ return nodeId;
353
+ }
354
+
355
+ NodeId.resolveNodeId = resolveNodeId;
356
+
357
+ export function sameNodeId(n1: NodeId, n2: NodeId): boolean {
358
+ if (n1.identifierType !== n2.identifierType) {
359
+ return false;
360
+ }
361
+ if (n1.namespace !== n2.namespace) {
362
+ return false;
363
+ }
364
+ switch (n1.identifierType) {
365
+ case NodeIdType.NUMERIC:
366
+ case NodeIdType.STRING:
367
+ return n1.value === n2.value;
368
+ default:
369
+ return isEqual(n1.value, n2.value);
370
+ }
371
+ }
372
+
373
+ NodeId.sameNodeId = sameNodeId;