Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-variant

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-variant - npm Package Compare versions

Comparing version 2.6.0-alpha.7 to 2.6.1

3

dist/DataType_enum.d.ts

@@ -0,1 +1,4 @@

/**
* @module node-opcua-variant
*/
import { Enum } from "node-opcua-enum";

@@ -2,0 +5,0 @@ export declare enum DataType {

@@ -0,3 +1,6 @@

/**
* @module node-opcua-variant
*/
export * from "./DataType_enum";
export * from "./VariantArrayType_enum";
export * from "./variant";

@@ -13,2 +13,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module node-opcua-variant
*/
__exportStar(require("./DataType_enum"), exports);

@@ -15,0 +18,0 @@ __exportStar(require("./VariantArrayType_enum"), exports);

@@ -0,1 +1,4 @@

/**
* @module node-opcua-variant
*/
/// <reference types="node" />

@@ -31,11 +34,34 @@ import { BaseUAObject, StructuredTypeSchema } from "node-opcua-factory";

export declare type VariantLike = VariantOptions;
/***
* @private
*/
export declare const VARIANT_ARRAY_MASK = 128;
/***
* @private
*/
export declare const VARIANT_ARRAY_DIMENSIONS_MASK = 64;
/***
* @private
*/
export declare const VARIANT_TYPE_MASK = 63;
/***
* @private
*/
export declare function encodeVariant(variant: Variant, stream: OutputBinaryStream): void;
/***
* @private
*/
export declare function decodeVariant(stream: BinaryStream): Variant;
/***
* @private
*/
export declare type BufferedArray2 = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
export declare function coerceVariantType(dataType: DataType, value: any): any;
export declare function isValidVariant(arrayType: VariantArrayType, dataType: DataType, value: any, dimensions?: number[] | null): boolean;
export declare function buildVariantArray(dataType: DataType, nbElements: number, defaultValue: any): any[] | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
export declare function buildVariantArray(dataType: DataType, nbElements: number, defaultValue: any): any[] | Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
/***
* returns true if the two variant represent the same value
* @param v1 the first variant to compare
* @param v2 the variant to compare with
*/
export declare function sameVariant(v1: Variant, v2: Variant): boolean;

@@ -42,0 +68,0 @@ export interface VariantOptionsT<T, DT extends DataType> extends VariantOptions {

"use strict";
/**
* @module node-opcua-variant
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -13,2 +16,3 @@ exports.sameVariant = exports.buildVariantArray = exports.isValidVariant = exports.coerceVariantType = exports.decodeVariant = exports.encodeVariant = exports.VARIANT_TYPE_MASK = exports.VARIANT_ARRAY_DIMENSIONS_MASK = exports.VARIANT_ARRAY_MASK = exports.Variant = void 0;

const VariantArrayType_enum_1 = require("./VariantArrayType_enum");
// tslint:disable:no-bitwise
const schemaVariant = node_opcua_factory_1.buildStructuredType({

@@ -43,3 +47,3 @@ baseType: "BaseUAObject",

}
let Variant = (() => {
let Variant = /** @class */ (() => {
class Variant extends node_opcua_factory_1.BaseUAObject {

@@ -53,8 +57,30 @@ constructor(options) {

const schema = schemaVariant;
/**
* the variant type.
* @property dataType
* @type {DataType}
* @default 0
*/
this.setDataType(node_opcua_factory_1.initialize_field(schema.fields[0], options.dataType));
/**
* @property arrayType
* @type {VariantArrayType}
* @default 0
*/
this.setArrayType(node_opcua_factory_1.initialize_field(schema.fields[1], options.arrayType));
/**
* @property value
* @default null
*/
this.value = node_opcua_factory_1.initialize_field(schema.fields[2], options.value);
/**
* the matrix dimensions
* @property dimensions
* @type {UInt32[]}
* @default null
*/
this.dimensions = node_opcua_factory_1.initialize_field_array(schema.fields[3], options.dimensions);
if (options.dataType === DataType_enum_1.DataType.ExtensionObject) {
if (this.arrayType === VariantArrayType_enum_1.VariantArrayType.Scalar) {
/* istanbul ignore next */
if (this.value && !(this.value instanceof node_opcua_factory_1.BaseUAObject)) {

@@ -66,2 +92,3 @@ throw new Error("A variant with DataType.ExtensionObject must have a ExtensionObject value");

for (const e of this.value) {
/* istanbul ignore next */
if (e && !(e instanceof node_opcua_factory_1.BaseUAObject)) {

@@ -74,4 +101,6 @@ throw new Error("A variant with DataType.ExtensionObject must have a ExtensionObject value");

}
// Define Enumeration setters
setDataType(value) {
const coercedValue = DataType_enum_1._enumerationDataType.get(value);
/* istanbul ignore next */
if (coercedValue === undefined || coercedValue === null) {

@@ -84,2 +113,3 @@ throw new Error("value cannot be coerced to DataType: " + value);

const coercedValue = VariantArrayType_enum_1._enumerationVariantArrayType.get(value);
/* istanbul ignore next */
if (coercedValue === undefined || coercedValue === null) {

@@ -162,5 +192,17 @@ throw new Error("value cannot be coerced to VariantArrayType: " + value);

}
/***
* @private
*/
exports.VARIANT_ARRAY_MASK = 0x80;
/***
* @private
*/
exports.VARIANT_ARRAY_DIMENSIONS_MASK = 0x40;
/***
* @private
*/
exports.VARIANT_TYPE_MASK = 0x3f;
/***
* @private
*/
function encodeVariant(variant, stream) {

@@ -189,2 +231,5 @@ let encodingByte = variant.dataType;

exports.encodeVariant = encodeVariant;
/***
* @private
*/
function decodeDebugVariant(self, stream, options) {

@@ -200,2 +245,3 @@ const tracer = options.tracer;

const decode = node_opcua_factory_1.findBuiltInType(DataType_enum_1.DataType[self.dataType]).decode;
/* istanbul ignore next */
if (!decode) {

@@ -214,2 +260,10 @@ throw new Error("Variant.decode : cannot find decoder for type " + DataType_enum_1.DataType[self.dataType]);

}
// ArrayDimensions
// Int32[]
// The length of each dimension.
// This field is only present if the array dimensions flag is set in the encoding mask.
// The lower rank dimensions appear first in the array.
// All dimensions shall be specified and shall be greater than zero.
// If ArrayDimensions are inconsistent with the ArrayLength then the decoder shall
// stop and raise a BadDecodingError.
if (hasDimension) {

@@ -237,2 +291,3 @@ self.dimensions = decodeDimension(stream);

const verification = calculate_product(self.dimensions);
/* istanbul ignore next */
if (verification !== self.value.length) {

@@ -243,2 +298,5 @@ throw new Error("BadDecodingError");

}
/***
* @private
*/
function decodeVariant(stream) {

@@ -282,4 +340,6 @@ const value = new Variant({});

options.dataType = options.dataType || DataType_enum_1.DataType.Null;
// dataType could be a string
if (typeof options.dataType === "string") {
const d = node_opcua_factory_1.findBuiltInType(options.dataType);
/* istanbul ignore next */
if (!d) {

@@ -289,2 +349,3 @@ throw new Error("Cannot find data type buildIn");

const t = DataType_enum_1._enumerationDataType.get(d.name);
/* istanbul ignore next */
if (t === null) {

@@ -295,4 +356,6 @@ throw new Error("DataType: invalid " + options.dataType);

}
// array type could be a string
if (typeof options.arrayType === "string") {
const at = VariantArrayType_enum_1.VariantArrayType[options.arrayType];
/* istanbul ignore next */
if (utils.isNullOrUndefined(at)) {

@@ -304,3 +367,6 @@ throw new Error("ArrayType: invalid " + options.arrayType);

if (isArrayTypeUnspecified && _.isArray(options.value)) {
// when using UInt64 ou Int64 arrayType must be specified , as automatic detection cannot be made
/* istanbul ignore next */
if ((options.dataType === DataType_enum_1.DataType.UInt64 || options.dataType === DataType_enum_1.DataType.Int64)) {
// we do nothing here ....
throw new Error("Variant#constructor : when using UInt64 ou Int64" +

@@ -316,2 +382,3 @@ " arrayType must be specified , as automatic detection cannot be made");

node_opcua_assert_1.assert(options.arrayType === VariantArrayType_enum_1.VariantArrayType.Array || options.arrayType === VariantArrayType_enum_1.VariantArrayType.Matrix);
/* istanbul ignore else */
if (options.arrayType === VariantArrayType_enum_1.VariantArrayType.Array) {

@@ -327,5 +394,7 @@ options.value = options.value || [];

options.value = coerceVariantArray(options.dataType, options.value);
/* istanbul ignore next */
if (!options.dimensions) {
throw new Error("Matrix Variant : missing dimensions");
}
/* istanbul ignore next */
if (options.value.length !== calculate_product(options.dimensions)) {

@@ -342,3 +411,5 @@ throw new Error("Matrix Variant : invalid value size = options.value.length "

const tmp = options.value;
// scalar
options.value = coerceVariantType(options.dataType, options.value);
/* istanbul ignore next */
if (!isValidVariant(options.arrayType, options.dataType, options.value, null)) {

@@ -355,2 +426,3 @@ throw new Error("Invalid variant arrayType: " + options.arrayType.toString() +

function calculate_product(array) {
/* istanbul ignore next */
if (!array || array.length === 0) {

@@ -364,2 +436,3 @@ return 0;

const encode = node_opcua_factory_1.findBuiltInType(dataTypeAsString).encode;
/* istanbul ignore next */
if (!encode) {

@@ -373,2 +446,3 @@ throw new Error("Cannot find encode function for dataType " + dataTypeAsString);

const decode = node_opcua_factory_1.findBuiltInType(dataTypeAsString).decode;
/* istanbul ignore next */
if (!decode) {

@@ -385,4 +459,6 @@ throw new Error("Variant.decode : cannot find decoder for type " + dataTypeAsString);

if (arrayTypeConstructor && value instanceof arrayTypeConstructor) {
const newArray = new value.constructor(value.length);
const newArray = new value.constructor(value.length); // deep copy
/* istanbul ignore if */
if (newArray instanceof Buffer) {
// required for nodejs 4.x
value.copy(newArray);

@@ -401,7 +477,11 @@ }

}
// istanbul ignore next
if (arrayTypeConstructor && displayWarning && n > 10) {
// tslint:disable-next-line:no-console
console.log("Warning ! an array containing " + DataType_enum_1.DataType[dataType] +
" elements has been provided as a generic array. ");
// tslint:disable-next-line:no-console
console.log(" This is inefficient as every array value will " +
"have to be coerced and verified against the expected type");
// tslint:disable-next-line:no-console
console.log(" It is highly recommended that you use a " +

@@ -449,2 +529,4 @@ " typed array ", arrayTypeConstructor.constructor.name, " instead");

catch (err) {
/* istanbul ignore next */
// tslint:disable-next-line:no-console
console.log("encodeVariantArray error : DATATYPE", dataType, "\nvalue", value.length);

@@ -457,2 +539,3 @@ }

const length = node_opcua_basic_types_1.decodeUInt32(stream);
/* istanbul ignore next */
if (length === 0xFFFFFFFF) {

@@ -469,2 +552,3 @@ return null;

const length = node_opcua_basic_types_1.decodeUInt32(stream);
/* istanbul ignore next */
if (length === 0xFFFFFFFF) {

@@ -511,2 +595,3 @@ return null;

const n1 = Math.min(10, length);
// display a maximum of 10 elements
for (i = 0; i < n1; i++) {

@@ -516,5 +601,7 @@ tracer.trace("start_element", "", i);

element = decode(stream);
// arr.push(element);
tracer.trace("member", "Variant", element, cursorBefore, stream.length, DataType_enum_1.DataType[dataType]);
tracer.trace("end_element", "", i);
}
// keep reading
if (length >= n1) {

@@ -540,2 +627,3 @@ for (i = n1; i < length; i++) {

function coerceVariantType(dataType, value) {
/* eslint max-statements: ["error",1000], complexity: ["error",1000]*/
if (value === undefined) {

@@ -545,2 +633,5 @@ value = null;

if (isEnumerationItem(value)) {
// OPCUA Specification 1.0.3 5.8.2 encoding rules for various dataType:
// [...]Enumeration are always encoded as Int32 on the wire [...]
/* istanbul ignore next */
if (dataType !== DataType_enum_1.DataType.Int32) {

@@ -571,2 +662,3 @@ throw new Error("expecting DataType.Int32 for enumeration values ;" +

if (isEnumerationItem(value)) {
// value is a enumeration of some sort
value = value.value;

@@ -577,3 +669,5 @@ }

}
/* istanbul ignore next */
if (!_.isFinite(value)) {
// xx console.log("xxx ", value, ttt);
throw new Error("expecting a number " + value);

@@ -598,2 +692,3 @@ }

value = (typeof value === "string") ? Buffer.from(value) : value;
// istanbul ignore next
if (!(value === null || value instanceof Buffer)) {

@@ -675,2 +770,3 @@ throw new Error("ByteString should be null or a Buffer");

}
// array values can be store in Buffer, Float32Array
node_opcua_assert_1.assert(_.isArray(value));

@@ -684,2 +780,3 @@ for (const valueItem of value) {

}
/*istanbul ignore next*/
function isValidMatrixVariant(dataType, value, dimensions) {

@@ -744,2 +841,3 @@ if (!dimensions) {

exports.buildVariantArray = buildVariantArray;
// old version of nodejs do not provide a Buffer#equals test
const oldNodeVersion = (process.versions.node && process.versions.node.substring(0, 1) === "0");

@@ -757,3 +855,6 @@ function __check_same_array(arr1, arr2) {

if (!oldNodeVersion && arr1.buffer) {
// v1 and v2 are TypedArray (such as Int32Array...)
// this is the most efficient way to compare 2 buffers but it doesn't work with node <= 0.12
node_opcua_assert_1.assert(arr2.buffer);
// compare byte by byte
const b1 = Buffer.from(arr1.buffer, arr1.byteOffset, arr1.byteLength);

@@ -771,2 +872,7 @@ const b2 = Buffer.from(arr2.buffer, arr2.byteOffset, arr2.byteLength);

}
/***
* returns true if the two variant represent the same value
* @param v1 the first variant to compare
* @param v2 the variant to compare with
*/
function sameVariant(v1, v2) {

@@ -790,2 +896,3 @@ if (v1 === v2) {

if (v1.dataType === DataType_enum_1.DataType.ExtensionObject) {
// compare two extension objects
return _.isEqual(v1.value, v2.value);

@@ -812,2 +919,3 @@ }

exports.sameVariant = sameVariant;
// ---------------------------------------------------------------------------------------------------------
node_opcua_factory_1.registerSpecialVariantEncoder(Variant);

@@ -814,0 +922,0 @@ node_opcua_factory_1.registerType({

@@ -0,1 +1,4 @@

/**
* @module node-opcua-variant
*/
import { Enum } from "node-opcua-enum";

@@ -7,2 +10,5 @@ export declare enum VariantArrayType {

}
/***
* @private
*/
export declare const _enumerationVariantArrayType: Enum;

@@ -15,3 +15,6 @@ "use strict";

};
/***
* @private
*/
exports._enumerationVariantArrayType = node_opcua_factory_1.registerEnumeration(schemaVariantArrayType);
//# sourceMappingURL=VariantArrayType_enum.js.map

32

package.json
{
"name": "node-opcua-variant",
"version": "2.6.0-alpha.7",
"version": "2.6.1",
"description": "pure nodejs OPCUA SDK - module -variant",

@@ -13,19 +13,19 @@ "main": "./dist/index.js",

"dependencies": {
"node-opcua-assert": "^2.6.0-alpha.1",
"node-opcua-basic-types": "^2.6.0-alpha.1",
"node-opcua-data-model": "^2.6.0-alpha.7",
"node-opcua-enum": "^2.6.0-alpha.1",
"node-opcua-extension-object": "^2.6.0-alpha.7",
"node-opcua-factory": "^2.6.0-alpha.7",
"node-opcua-nodeid": "^2.6.0-alpha.1",
"node-opcua-utils": "^2.6.0-alpha.1",
"node-opcua-assert": "^2.6.1",
"node-opcua-basic-types": "^2.6.1",
"node-opcua-data-model": "^2.6.1",
"node-opcua-enum": "^2.6.1",
"node-opcua-extension-object": "^2.6.1",
"node-opcua-factory": "^2.6.1",
"node-opcua-nodeid": "^2.6.1",
"node-opcua-utils": "^2.6.1",
"underscore": "^1.10.2"
},
"devDependencies": {
"node-opcua-benchmarker": "^2.6.0-alpha.1",
"node-opcua-binary-stream": "^2.6.0-alpha.1",
"node-opcua-debug": "^2.6.0-alpha.1",
"node-opcua-numeric-range": "^2.6.0-alpha.7",
"node-opcua-packet-analyzer": "^2.6.0-alpha.7",
"node-opcua-status-code": "^2.6.0-alpha.1",
"node-opcua-benchmarker": "^2.6.1",
"node-opcua-binary-stream": "^2.6.1",
"node-opcua-debug": "^2.6.1",
"node-opcua-numeric-range": "^2.6.1",
"node-opcua-packet-analyzer": "^2.6.1",
"node-opcua-status-code": "^2.6.1",
"should": "^13.2.3",

@@ -49,3 +49,3 @@ "source-map-support": "^0.5.19"

"homepage": "http://node-opcua.github.io/",
"gitHead": "6af0c6f183dcb96ddc5a2befc98851d0960c5fd0"
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc