node-opcua-nodeid
Advanced tools
Comparing version 2.90.1 to 2.97.0
@@ -32,2 +32,19 @@ /// <reference types="node" /> | ||
} | ||
export interface INodeIdNumeric extends NodeId { | ||
identifierType: NodeIdType.NUMERIC; | ||
value: number; | ||
} | ||
export interface INodeIdGuid extends NodeId { | ||
identifierType: NodeIdType.GUID; | ||
value: string; | ||
} | ||
export interface INodeIdByteString extends NodeId { | ||
identifierType: NodeIdType.BYTESTRING; | ||
value: Buffer; | ||
} | ||
export interface INodeIdString extends NodeId { | ||
identifierType: NodeIdType.STRING; | ||
value: string; | ||
} | ||
export type INodeId = INodeIdNumeric | INodeIdGuid | INodeIdString | INodeIdByteString; | ||
/** | ||
@@ -39,3 +56,3 @@ * Construct a node ID | ||
* | ||
* ``` javascript | ||
* ``` javascript | ||
* const nodeId = new NodeId(NodeIdType.NUMERIC,123,1); | ||
@@ -42,0 +59,0 @@ * ``` |
@@ -53,2 +53,3 @@ "use strict"; | ||
} | ||
const doDebug = false; | ||
/** | ||
@@ -60,3 +61,3 @@ * Construct a node ID | ||
* | ||
* ``` javascript | ||
* ``` javascript | ||
* const nodeId = new NodeId(NodeIdType.NUMERIC,123,1); | ||
@@ -84,6 +85,6 @@ * ``` | ||
// namespace shall be a UInt16 | ||
(0, node_opcua_assert_1.assert)(this.namespace >= 0 && this.namespace <= 0xffff); | ||
(0, node_opcua_assert_1.assert)(this.namespace >= 0 && this.namespace <= 0xffff, "NodeId: invalid namespace value"); | ||
(0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.NUMERIC || (this.value !== null && this.value >= 0 && this.value <= 0xffffffff)); | ||
(0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.GUID || (0, node_opcua_guid_1.isValidGuid)(this.value)); | ||
(0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.STRING || typeof this.value === "string"); | ||
(0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.GUID || (0, node_opcua_guid_1.isValidGuid)(this.value), "NodeId: Guid is invalid"); | ||
(0, node_opcua_assert_1.assert)(this.identifierType !== NodeIdType.STRING || typeof this.value === "string", "cannot empty string"); | ||
if (this.identifierType === NodeIdType.GUID) { | ||
@@ -114,11 +115,12 @@ this.value = (0, node_opcua_guid_1.normalizeGuid)(value); | ||
let str; | ||
switch (this.identifierType) { | ||
const _this = this; | ||
switch (_this.identifierType) { | ||
case NodeIdType.NUMERIC: | ||
str = "ns=" + this.namespace + ";i=" + this.value; | ||
str = "ns=" + this.namespace + ";i=" + _this.value; | ||
break; | ||
case NodeIdType.STRING: | ||
str = "ns=" + this.namespace + ";s=" + this.value; | ||
str = "ns=" + this.namespace + ";s=" + _this.value; | ||
break; | ||
case NodeIdType.GUID: | ||
str = "ns=" + this.namespace + ";g=" + (0, node_opcua_guid_1.normalizeGuid)(this.value); | ||
str = "ns=" + this.namespace + ";g=" + (0, node_opcua_guid_1.normalizeGuid)(_this.value); | ||
break; | ||
@@ -136,3 +138,3 @@ default: | ||
if (addressSpace) { | ||
if (this.namespace === 0 && this.identifierType === NodeIdType.NUMERIC) { | ||
if (this.namespace === 0 && _this.identifierType === NodeIdType.NUMERIC) { | ||
// find standard browse name | ||
@@ -170,12 +172,12 @@ const name = reverse_map((this.value || 0).toString()) || "<undefined>"; | ||
isEmpty() { | ||
switch (this.identifierType) { | ||
const _this = this; | ||
switch (_this.identifierType) { | ||
case NodeIdType.NUMERIC: | ||
return this.value === 0; | ||
return _this.value === 0; | ||
case NodeIdType.STRING: | ||
return !this.value || this.value.length === 0; | ||
return !_this.value; | ||
case NodeIdType.GUID: | ||
return !this.value || this.value === node_opcua_guid_1.emptyGuid; | ||
return !_this.value || _this.value === node_opcua_guid_1.emptyGuid; | ||
default: | ||
(0, node_opcua_assert_1.assert)(this.identifierType === NodeIdType.BYTESTRING, "invalid identifierType in NodeId : " + this.identifierType); | ||
return !this.value || this.value.length === 0; | ||
return !_this.value || _this.value.length === 0; | ||
} | ||
@@ -191,3 +193,3 @@ } | ||
set: () => { | ||
throw new Error("Cannot assign a value to constant NodeId.nullNodeId"); | ||
throw new Error("Cannot assign a value to constant NodeId.nullNodeId"); | ||
} | ||
@@ -194,0 +196,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "2.90.1", | ||
"version": "2.97.0", | ||
"description": "pure nodejs OPCUA SDK - module -nodeid", | ||
@@ -39,3 +39,3 @@ "scripts": { | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "3325ff5f8477fd058ba574d19e8128c36e3e831f" | ||
"gitHead": "19c96bda0810d2dec73dd1c2427546be40908646" | ||
} |
@@ -50,10 +50,31 @@ /** | ||
*/ | ||
function defaultValue(identifierType: NodeIdType): string | number| Buffer { | ||
switch(identifierType) { | ||
case NodeIdType.GUID : return emptyGuid; | ||
case NodeIdType.BYTESTRING : return null as any as Buffer;// Buffer.alloc(0); | ||
case NodeIdType.STRING : return ""; | ||
case NodeIdType.NUMERIC : return 0; | ||
function defaultValue(identifierType: NodeIdType): string | number | Buffer { | ||
switch (identifierType) { | ||
case NodeIdType.GUID: return emptyGuid; | ||
case NodeIdType.BYTESTRING: return null as any as Buffer;// Buffer.alloc(0); | ||
case NodeIdType.STRING: return ""; | ||
case NodeIdType.NUMERIC: return 0; | ||
} | ||
} | ||
export interface INodeIdNumeric extends NodeId { | ||
identifierType: NodeIdType.NUMERIC; | ||
value: number; | ||
} | ||
export interface INodeIdGuid extends NodeId { | ||
identifierType: NodeIdType.GUID; | ||
value: string; | ||
} | ||
export interface INodeIdByteString extends NodeId { | ||
identifierType: NodeIdType.BYTESTRING; | ||
value: Buffer; | ||
} | ||
export interface INodeIdString extends NodeId { | ||
identifierType: NodeIdType.STRING; | ||
value: string; | ||
} | ||
export type INodeId = INodeIdNumeric | INodeIdGuid | INodeIdString | INodeIdByteString; | ||
const doDebug = false; | ||
/** | ||
@@ -65,3 +86,3 @@ * Construct a node ID | ||
* | ||
* ``` javascript | ||
* ``` javascript | ||
* const nodeId = new NodeId(NodeIdType.NUMERIC,123,1); | ||
@@ -87,2 +108,4 @@ * ``` | ||
constructor(identifierType?: NodeIdType | null, value?: number | string | Buffer | Guid, namespace?: number) { | ||
if (identifierType === null || identifierType === undefined) { | ||
@@ -100,10 +123,9 @@ this.identifierType = NodeIdType.NUMERIC; | ||
// namespace shall be a UInt16 | ||
assert(this.namespace >= 0 && this.namespace <= 0xffff); | ||
assert(this.identifierType !== NodeIdType.NUMERIC || (this.value !== null && this.value >= 0 && this.value <= 0xffffffff)); | ||
assert(this.identifierType !== NodeIdType.GUID || isValidGuid(this.value as string)); | ||
assert(this.identifierType !== NodeIdType.STRING || typeof this.value === "string"); | ||
assert(this.namespace >= 0 && this.namespace <= 0xffff, "NodeId: invalid namespace value"); | ||
assert(this.identifierType !== NodeIdType.NUMERIC || (this.value !== null && this.value as number >= 0 && this.value as number <= 0xffffffff)); | ||
assert(this.identifierType !== NodeIdType.GUID || isValidGuid(this.value as string), "NodeId: Guid is invalid"); | ||
assert(this.identifierType !== NodeIdType.STRING || typeof this.value === "string", "cannot empty string"); | ||
if (this.identifierType === NodeIdType.GUID) { | ||
this.value = normalizeGuid(value as string); | ||
} | ||
} | ||
} | ||
@@ -132,11 +154,12 @@ | ||
let str; | ||
switch (this.identifierType) { | ||
const _this = this as INodeId; | ||
switch (_this.identifierType) { | ||
case NodeIdType.NUMERIC: | ||
str = "ns=" + this.namespace + ";i=" + this.value; | ||
str = "ns=" + this.namespace + ";i=" + _this.value; | ||
break; | ||
case NodeIdType.STRING: | ||
str = "ns=" + this.namespace + ";s=" + this.value; | ||
str = "ns=" + this.namespace + ";s=" + _this.value; | ||
break; | ||
case NodeIdType.GUID: | ||
str = "ns=" + this.namespace + ";g=" + normalizeGuid(this.value as string); | ||
str = "ns=" + this.namespace + ";g=" + normalizeGuid(_this.value); | ||
break; | ||
@@ -154,5 +177,5 @@ default: | ||
if (addressSpace) { | ||
if (this.namespace === 0 && this.identifierType === NodeIdType.NUMERIC) { | ||
if (this.namespace === 0 && _this.identifierType === NodeIdType.NUMERIC) { | ||
// find standard browse name | ||
const name = reverse_map((this.value||0).toString()) || "<undefined>"; | ||
const name = reverse_map((this.value || 0).toString()) || "<undefined>"; | ||
str += " " + name; | ||
@@ -190,12 +213,12 @@ } else if (addressSpace.findNode) { | ||
public isEmpty(): boolean { | ||
switch (this.identifierType) { | ||
const _this = this as INodeId; | ||
switch (_this.identifierType) { | ||
case NodeIdType.NUMERIC: | ||
return this.value === 0; | ||
return _this.value === 0; | ||
case NodeIdType.STRING: | ||
return !this.value || (this.value as string).length === 0; | ||
return !_this.value; | ||
case NodeIdType.GUID: | ||
return !this.value || this.value === emptyGuid; | ||
return !_this.value || _this.value === emptyGuid; | ||
default: | ||
assert(this.identifierType === NodeIdType.BYTESTRING, "invalid identifierType in NodeId : " + this.identifierType); | ||
return !this.value || (this.value as Buffer).length === 0; | ||
return !_this.value || (_this.value as Buffer).length === 0; | ||
} | ||
@@ -212,3 +235,3 @@ } | ||
set: () => { | ||
throw new Error("Cannot assign a value to constant NodeId.nullNodeId"); | ||
throw new Error("Cannot assign a value to constant NodeId.nullNodeId"); | ||
} | ||
@@ -287,3 +310,3 @@ }); | ||
namespace = parseInt(matches[1], 10); | ||
value =normalizeGuid(matches[2]); | ||
value = normalizeGuid(matches[2]); | ||
} else { | ||
@@ -290,0 +313,0 @@ throw new Error("String cannot be coerced to a nodeId : " + value); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60036
1242