node-opcua-nodeid
Advanced tools
Comparing version 2.121.0 to 2.125.0
@@ -94,2 +94,3 @@ /// <reference types="node" /> | ||
addressSpace?: any; | ||
namespaceArray?: string[]; | ||
}): string; | ||
@@ -99,3 +100,5 @@ /** | ||
*/ | ||
toJSON(): string; | ||
toJSON(options?: { | ||
namespaceArray?: string[]; | ||
}): string; | ||
displayText(): string; | ||
@@ -108,2 +111,6 @@ /** | ||
export type NodeIdLike = string | NodeId | number; | ||
export interface ResolveNodeIdOptions { | ||
namespaceArray?: string[]; | ||
defaultNamespaceIndex?: number; | ||
} | ||
/** | ||
@@ -121,5 +128,8 @@ * Convert a value into a nodeId: | ||
* @param value | ||
* @param namespace {number} | ||
* @param namespaceOptions {number} | ||
* @param namespaceOptions.namespace {number} | ||
* @param namespaceOptions.namespaceArray {number} | ||
* | ||
*/ | ||
export declare function coerceNodeId(value: unknown, namespace?: number): NodeId; | ||
export declare function coerceNodeId(value: unknown, namespaceOptions?: number | ResolveNodeIdOptions): NodeId; | ||
/** | ||
@@ -142,3 +152,3 @@ * construct a node Id from a value and a namespace. | ||
*/ | ||
export declare function resolveNodeId(nodeIdOrString: NodeIdLike): NodeId; | ||
export declare function resolveNodeId(nodeIdOrString: NodeIdLike, options?: ResolveNodeIdOptions): NodeId; | ||
export declare function sameNodeId(n1: NodeId, n2: NodeId): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sameNodeId = exports.resolveNodeId = exports.makeNodeId = exports.coerceNodeId = exports.NodeId = exports.NodeIdType = void 0; | ||
/* eslint-disable complexity */ | ||
/** | ||
@@ -111,2 +112,5 @@ * @module node-opcua-nodeid | ||
const addressSpace = options ? options.addressSpace : null; | ||
const namespacePart = options?.namespaceArray ? | ||
(this.namespace == 0 ? "" : `nsu=${options.namespaceArray[this.namespace] || `<unknown namespace with index ${this.namespace}>`};`) | ||
: `ns=${this.namespace};`; | ||
let str; | ||
@@ -116,9 +120,9 @@ const _this = this; | ||
case NodeIdType.NUMERIC: | ||
str = "ns=" + this.namespace + ";i=" + _this.value; | ||
str = `${namespacePart}i=${_this.value}`; | ||
break; | ||
case NodeIdType.STRING: | ||
str = "ns=" + this.namespace + ";s=" + _this.value; | ||
str = `${namespacePart}s=${_this.value}`; | ||
break; | ||
case NodeIdType.GUID: | ||
str = "ns=" + this.namespace + ";g=" + (0, node_opcua_guid_1.normalizeGuid)(_this.value); | ||
str = `${namespacePart}g=${(0, node_opcua_guid_1.normalizeGuid)(_this.value)}`; | ||
break; | ||
@@ -128,6 +132,6 @@ default: | ||
if (this.value) { | ||
str = "ns=" + this.namespace + ";b=" + this.value.toString("base64"); | ||
str = `${namespacePart}b=${this.value.toString("base64")}`; | ||
} | ||
else { | ||
str = "ns=" + this.namespace + ";b=<null>"; | ||
str = `${namespacePart}b=<null>`; | ||
} | ||
@@ -154,4 +158,4 @@ break; | ||
*/ | ||
toJSON() { | ||
return this.toString(); | ||
toJSON(options) { | ||
return this.toString(options); | ||
} | ||
@@ -198,2 +202,7 @@ displayText() { | ||
const regexNamespaceG = /ns=([0-9]+);g=([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12})/; | ||
const regexNSU = /nsu=(.*);(.*)/; | ||
const regexNamespaceNSU_I = /nsu=(.+);i=([0-9]+)/; | ||
const regexNamespaceNSU_S = /nsu=(.+);s=(.*)/; | ||
const regexNamespaceNSU_B = /nsu=(.+);b=(.*)/; | ||
const regexNamespaceNSU_G = /nsu=(.+);g=([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12})/; | ||
/** | ||
@@ -211,6 +220,9 @@ * Convert a value into a nodeId: | ||
* @param value | ||
* @param namespace {number} | ||
* @param namespaceOptions {number} | ||
* @param namespaceOptions.namespace {number} | ||
* @param namespaceOptions.namespaceArray {number} | ||
* | ||
*/ | ||
// eslint-disable-next-line max-statements | ||
function coerceNodeId(value, namespace) { | ||
function coerceNodeId(value, namespaceOptions) { | ||
let matches; | ||
@@ -222,3 +234,4 @@ let twoFirst; | ||
value = value || 0; | ||
namespace = namespace || 0; | ||
let namespace = (typeof namespaceOptions === "number" ? namespaceOptions : namespaceOptions?.defaultNamespaceIndex) || 0; | ||
const namespaceArray = namespaceOptions?.namespaceArray || undefined; | ||
let identifierType = NodeIdType.NUMERIC; | ||
@@ -270,3 +283,15 @@ if (typeof value === "string") { | ||
else { | ||
throw new Error("String cannot be coerced to a nodeId : " + value); | ||
// eslint-disable-next-line no-empty | ||
if (namespaceArray && (matches = regexNSU.exec(value)) !== null) { | ||
const namespaceIndex = namespaceArray.indexOf(matches[1]); | ||
if (namespaceIndex === -1) { | ||
throw new Error("Cannot find namespace with index " + matches[1] + " in " + namespaceArray.join(",")); | ||
} | ||
const nid = coerceNodeId(matches[2], namespace); | ||
nid.namespace = namespaceIndex; | ||
return nid; | ||
} | ||
else { | ||
throw new Error("String cannot be coerced to a nodeId : " + value); | ||
} | ||
} | ||
@@ -358,3 +383,3 @@ } | ||
*/ | ||
function resolveNodeId(nodeIdOrString) { | ||
function resolveNodeId(nodeIdOrString, options) { | ||
let nodeId; | ||
@@ -366,3 +391,3 @@ const rawId = typeof nodeIdOrString === "string" ? _nameToNodeIdIndex[nodeIdOrString] : undefined; | ||
else { | ||
nodeId = coerceNodeId(nodeIdOrString); | ||
nodeId = coerceNodeId(nodeIdOrString, options); | ||
} | ||
@@ -369,0 +394,0 @@ return nodeId; |
@@ -5,3 +5,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "2.121.0", | ||
"version": "2.125.0", | ||
"description": "pure nodejs OPCUA SDK - module nodeid", | ||
@@ -16,8 +16,8 @@ "scripts": { | ||
"node-opcua-assert": "2.120.0", | ||
"node-opcua-constants": "2.121.0", | ||
"node-opcua-constants": "2.125.0", | ||
"node-opcua-guid": "2.120.0" | ||
}, | ||
"devDependencies": { | ||
"node-opcua-benchmarker": "2.120.0", | ||
"node-opcua-debug": "2.121.0", | ||
"node-opcua-benchmarker": "2.125.0", | ||
"node-opcua-debug": "2.125.0", | ||
"should": "^13.2.3" | ||
@@ -40,3 +40,3 @@ }, | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "ba93a78eda343ecc0cc20476837347f6dfa259e0", | ||
"gitHead": "a0e0a2f1045e6e402dd4619c625c90008f0617ed", | ||
"files": [ | ||
@@ -43,0 +43,0 @@ "dist", |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable complexity */ | ||
/** | ||
@@ -147,4 +148,9 @@ * @module node-opcua-nodeid | ||
*/ | ||
public toString(options?: { addressSpace?: any }): string { | ||
public toString(options?: { addressSpace?: any , namespaceArray?: string[]}): string { | ||
const addressSpace = options ? options.addressSpace : null; | ||
const namespacePart: string = options?.namespaceArray ? | ||
(this.namespace == 0 ? "" : `nsu=${options.namespaceArray[this.namespace] || `<unknown namespace with index ${this.namespace}>`};`) | ||
: `ns=${this.namespace};`; | ||
let str; | ||
@@ -154,9 +160,9 @@ const _this = this as INodeId; | ||
case NodeIdType.NUMERIC: | ||
str = "ns=" + this.namespace + ";i=" + _this.value; | ||
str = `${namespacePart}i=${_this.value}`; | ||
break; | ||
case NodeIdType.STRING: | ||
str = "ns=" + this.namespace + ";s=" + _this.value; | ||
str = `${namespacePart}s=${_this.value}`; | ||
break; | ||
case NodeIdType.GUID: | ||
str = "ns=" + this.namespace + ";g=" + normalizeGuid(_this.value); | ||
str = `${namespacePart}g=${normalizeGuid(_this.value)}`; | ||
break; | ||
@@ -166,5 +172,5 @@ default: | ||
if (this.value) { | ||
str = "ns=" + this.namespace + ";b=" + (this.value as Buffer).toString("base64"); | ||
str = `${namespacePart}b=${(this.value as Buffer).toString("base64")}`; | ||
} else { | ||
str = "ns=" + this.namespace + ";b=<null>"; | ||
str = `${ namespacePart}b=<null>`; | ||
} | ||
@@ -192,4 +198,4 @@ break; | ||
*/ | ||
public toJSON(): string { | ||
return this.toString(); | ||
public toJSON(options?: {namespaceArray?: string[]}): string { | ||
return this.toString(options); | ||
} | ||
@@ -244,2 +250,13 @@ | ||
const regexNSU = /nsu=(.*);(.*)/; | ||
const regexNamespaceNSU_I = /nsu=(.+);i=([0-9]+)/; | ||
const regexNamespaceNSU_S = /nsu=(.+);s=(.*)/; | ||
const regexNamespaceNSU_B = /nsu=(.+);b=(.*)/; | ||
const regexNamespaceNSU_G = /nsu=(.+);g=([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12})/; | ||
export interface ResolveNodeIdOptions { | ||
namespaceArray?: string[]; | ||
defaultNamespaceIndex?: number ; | ||
} | ||
/** | ||
@@ -257,6 +274,9 @@ * Convert a value into a nodeId: | ||
* @param value | ||
* @param namespace {number} | ||
* @param namespaceOptions {number} | ||
* @param namespaceOptions.namespace {number} | ||
* @param namespaceOptions.namespaceArray {number} | ||
* | ||
*/ | ||
// eslint-disable-next-line max-statements | ||
export function coerceNodeId(value: unknown, namespace?: number): NodeId { | ||
export function coerceNodeId(value: unknown, namespaceOptions?: number | ResolveNodeIdOptions): NodeId { | ||
let matches; | ||
@@ -269,4 +289,7 @@ let twoFirst; | ||
value = value || 0; | ||
namespace = namespace || 0; | ||
let namespace = (typeof namespaceOptions === "number" ? namespaceOptions as number : namespaceOptions?.defaultNamespaceIndex )|| 0; | ||
const namespaceArray: string[] | undefined = (namespaceOptions as { namespace?: number, namespaceArray: string[] }) ?.namespaceArray || undefined; | ||
let identifierType = NodeIdType.NUMERIC; | ||
@@ -311,3 +334,15 @@ | ||
} else { | ||
throw new Error("String cannot be coerced to a nodeId : " + value); | ||
// eslint-disable-next-line no-empty | ||
if (namespaceArray && (matches = regexNSU.exec(value))!==null) { | ||
const namespaceIndex = namespaceArray.indexOf(matches[1]); | ||
if (namespaceIndex === -1) { | ||
throw new Error("Cannot find namespace with index " + matches[1] + " in " + namespaceArray.join(",")); | ||
} | ||
const nid = coerceNodeId(matches[2], namespace); | ||
nid.namespace = namespaceIndex; | ||
return nid; | ||
} else { | ||
throw new Error("String cannot be coerced to a nodeId : " + value); | ||
} | ||
} | ||
@@ -402,3 +437,3 @@ } else if (value instanceof Buffer) { | ||
*/ | ||
export function resolveNodeId(nodeIdOrString: NodeIdLike): NodeId { | ||
export function resolveNodeId(nodeIdOrString: NodeIdLike, options?: ResolveNodeIdOptions): NodeId { | ||
let nodeId; | ||
@@ -410,3 +445,3 @@ | ||
} else { | ||
nodeId = coerceNodeId(nodeIdOrString); | ||
nodeId = coerceNodeId(nodeIdOrString, options); | ||
} | ||
@@ -413,0 +448,0 @@ return nodeId; |
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
65253
1326
+ Addednode-opcua-constants@2.125.0(transitive)
- Removednode-opcua-constants@2.121.0(transitive)
Updatednode-opcua-constants@2.125.0