node-opcua-numeric-range
Advanced tools
Comparing version 2.21.0 to 2.22.0
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { UAString } from "node-opcua-basic-types"; | ||
@@ -8,4 +9,4 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
defaultValue: () => NumericRange; | ||
encode: (value: NumericRange | null, stream: OutputBinaryStream) => void; | ||
decode: (stream: BinaryStream) => NumericRange; | ||
encode: typeof encodeNumericRange; | ||
decode: typeof decodeNumericRange; | ||
random: () => NumericRange; | ||
@@ -49,2 +50,11 @@ coerce: typeof coerceNumericRange; | ||
static coerce: typeof coerceNumericRange; | ||
static schema: { | ||
name: string; | ||
subType: string; | ||
defaultValue: () => NumericRange; | ||
encode: typeof encodeNumericRange; | ||
decode: typeof decodeNumericRange; | ||
random: () => NumericRange; | ||
coerce: typeof coerceNumericRange; | ||
}; | ||
static NumericRangeType: typeof NumericRangeType; | ||
@@ -55,3 +65,3 @@ static readonly empty: NumericalRange0; | ||
value: NumericalRangeValueType; | ||
constructor(value?: null | string | number | number[] | NumericRange, secondValue?: number); | ||
constructor(value?: null | string | number | number[], secondValue?: number); | ||
isValid(): boolean; | ||
@@ -70,8 +80,6 @@ isEmpty(): boolean; | ||
extract_values<U, T extends ArrayLike<U>>(array: T, dimensions?: number[]): ExtractResult<T>; | ||
set_values(arrayToAlter: any, newValues: any): { | ||
set_values(arrayToAlter: Buffer | [], newValues: Buffer | []): { | ||
array: any; | ||
statusCode: import("node-opcua-basic-types").ConstantStatusCode; | ||
}; | ||
encode(stream: OutputBinaryStream): void; | ||
decode(stream: BinaryStream): void; | ||
} | ||
@@ -84,4 +92,4 @@ export interface ExtractResult<T> { | ||
export declare function encodeNumericRange(numericRange: NumericRange, stream: OutputBinaryStream): void; | ||
export declare function decodeNumericRange(stream: BinaryStream): NumericRange; | ||
export declare function decodeNumericRange(stream: BinaryStream, _value?: NumericRange): NumericRange; | ||
declare function coerceNumericRange(value: any | string | NumericRange | null | number[]): NumericRange; | ||
export {}; |
@@ -46,11 +46,4 @@ "use strict"; | ||
}, | ||
encode: (value, stream) => { | ||
node_opcua_assert_1.assert(value === null || value instanceof NumericRange); | ||
const strValue = value === null ? null : value.toEncodeableString(); | ||
node_opcua_basic_types_1.encodeString(strValue, stream); | ||
}, | ||
decode: (stream) => { | ||
const str = node_opcua_basic_types_1.decodeString(stream); | ||
return new NumericRange(str); | ||
}, | ||
encode: encodeNumericRange, | ||
decode: decodeNumericRange, | ||
random: () => { | ||
@@ -166,9 +159,6 @@ function r() { | ||
case NumericRangeType.MatrixRange: | ||
// istanbul ignore next | ||
if (numericalRange.value === null) { | ||
throw new Error("Internal Error"); | ||
} | ||
node_opcua_assert_1.assert(typeof numericalRange.value[0][0] === "number"); | ||
node_opcua_assert_1.assert(typeof numericalRange.value[0][1] === "number"); | ||
node_opcua_assert_1.assert(typeof numericalRange.value[1][0] === "number"); | ||
node_opcua_assert_1.assert(typeof numericalRange.value[1][1] === "number"); | ||
return (_valid_range(numericalRange.value[0][0], numericalRange.value[0][1]) && | ||
@@ -178,7 +168,5 @@ _valid_range(numericalRange.value[1][0], numericalRange.value[1][1])); | ||
return _valid_range(numericalRange.value[0], numericalRange.value[1]); | ||
case NumericRangeType.SingleValue: | ||
return numericalRange.value >= 0; | ||
default: | ||
return true; | ||
} | ||
// istanbul ignore next | ||
throw new Error("unsupported case"); | ||
} | ||
@@ -214,19 +202,5 @@ function _set_range_value(low, high) { | ||
} | ||
// istanbul ignore next | ||
return { type: NumericRangeType.InvalidRange, value: "" + value }; | ||
} | ||
function _construct_from_NumericRange(nr) { | ||
const nrToClone = nr; | ||
switch (nrToClone.type) { | ||
case NumericRangeType.InvalidRange: | ||
return { type: NumericRangeType.InvalidRange, value: nrToClone.value }; | ||
case NumericRangeType.MatrixRange: | ||
return { type: NumericRangeType.MatrixRange, value: [...nrToClone.value] }; | ||
case NumericRangeType.ArrayRange: | ||
return { type: NumericRangeType.ArrayRange, value: [...nrToClone.value] }; | ||
case NumericRangeType.SingleValue: | ||
return { type: NumericRangeType.SingleValue, value: nrToClone.value }; | ||
case NumericRangeType.Empty: | ||
return { type: NumericRangeType.Empty, value: null }; | ||
} | ||
} | ||
class NumericRange { | ||
@@ -252,7 +226,2 @@ constructor(value, secondValue) { | ||
} | ||
else if (value instanceof NumericRange) { | ||
const a = _construct_from_NumericRange(value); | ||
this.type = a.type; | ||
this.value = a.value; | ||
} | ||
else { | ||
@@ -282,5 +251,5 @@ this.value = "<invalid>"; | ||
} | ||
// console.log(" NR1 = ", nr1.toEncodeableString()); | ||
// console.log(" NR2 = ", nr2.toEncodeableString()); | ||
// istanbul ignore next | ||
node_opcua_assert_1.assert(false, "NumericalRange#overlap : case not implemented yet "); // TODO | ||
// istanbul ignore next | ||
return false; | ||
@@ -297,2 +266,3 @@ } | ||
const value = this.value; | ||
// istanbul ignore next | ||
if (value < 0) { | ||
@@ -349,2 +319,3 @@ return false; | ||
case NumericRangeType.InvalidRange: | ||
// istanbul ignore next | ||
if (!(typeof this.value === "string")) { | ||
@@ -436,11 +407,6 @@ throw new Error("Internal Error"); | ||
} | ||
encode(stream) { | ||
node_opcua_basic_types_1.encodeString(this.toEncodeableString(), stream); | ||
} | ||
decode(stream) { | ||
const str = node_opcua_basic_types_1.decodeString(stream); | ||
} | ||
} | ||
exports.NumericRange = NumericRange; | ||
NumericRange.coerce = coerceNumericRange; | ||
NumericRange.schema = exports.schemaNumericRange; | ||
// tslint:disable:variable-name | ||
@@ -598,6 +564,6 @@ NumericRange.NumericRangeType = NumericRangeType; | ||
node_opcua_assert_1.assert(numericRange instanceof NumericRange); | ||
numericRange.encode(stream); | ||
node_opcua_basic_types_1.encodeString(numericRange.toEncodeableString(), stream); | ||
} | ||
exports.encodeNumericRange = encodeNumericRange; | ||
function decodeNumericRange(stream) { | ||
function decodeNumericRange(stream, _value) { | ||
const str = node_opcua_basic_types_1.decodeString(stream); | ||
@@ -604,0 +570,0 @@ return new NumericRange(str); |
{ | ||
"name": "node-opcua-numeric-range", | ||
"version": "2.21.0", | ||
"version": "2.22.0", | ||
"description": "pure nodejs OPCUA SDK - module -numeric-range", | ||
@@ -15,11 +15,11 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"node-opcua-assert": "2.16.0", | ||
"node-opcua-basic-types": "2.20.0", | ||
"node-opcua-binary-stream": "2.17.0", | ||
"node-opcua-factory": "2.20.0", | ||
"node-opcua-status-code": "2.17.0" | ||
"node-opcua-assert": "2.22.0", | ||
"node-opcua-basic-types": "2.22.0", | ||
"node-opcua-binary-stream": "2.22.0", | ||
"node-opcua-factory": "2.22.0", | ||
"node-opcua-status-code": "2.22.0" | ||
}, | ||
"devDependencies": { | ||
"node-opcua-nodeid": "2.20.0", | ||
"node-opcua-packet-analyzer": "2.21.0", | ||
"node-opcua-nodeid": "2.22.0", | ||
"node-opcua-packet-analyzer": "2.22.0", | ||
"node-opcua-test-helpers": "2.17.0", | ||
@@ -41,3 +41,3 @@ "should": "^13.2.3" | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "b829d1d82a537d6f836877832ec7ba43851a49f9" | ||
"gitHead": "8eb6d67ecc89e34aa5bb99e9d6025aec2fa79743" | ||
} |
@@ -6,3 +6,3 @@ /** | ||
import { decodeString, encodeString, UAString } from "node-opcua-basic-types"; | ||
import { decodeString, encodeString, UAString, UInt8 } from "node-opcua-basic-types"; | ||
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
@@ -50,14 +50,6 @@ import { registerBasicType } from "node-opcua-factory"; | ||
}, | ||
encode: encodeNumericRange, | ||
encode: (value: NumericRange | null, stream: OutputBinaryStream) => { | ||
assert(value === null || value instanceof NumericRange); | ||
const strValue = value === null ? null : value.toEncodeableString(); | ||
encodeString(strValue, stream); | ||
}, | ||
decode: decodeNumericRange, | ||
decode: (stream: BinaryStream) => { | ||
const str = decodeString(stream); | ||
return new NumericRange(str); | ||
}, | ||
random: (): NumericRange => { | ||
@@ -222,9 +214,6 @@ function r() { | ||
case NumericRangeType.MatrixRange: | ||
// istanbul ignore next | ||
if (numericalRange.value === null) { | ||
throw new Error("Internal Error"); | ||
} | ||
assert(typeof numericalRange.value[0][0] === "number"); | ||
assert(typeof numericalRange.value[0][1] === "number"); | ||
assert(typeof numericalRange.value[1][0] === "number"); | ||
assert(typeof numericalRange.value[1][1] === "number"); | ||
return ( | ||
@@ -236,7 +225,5 @@ _valid_range(numericalRange.value[0][0], numericalRange.value[0][1]) && | ||
return _valid_range(numericalRange.value[0], numericalRange.value[1]); | ||
case NumericRangeType.SingleValue: | ||
return numericalRange.value >= 0; | ||
default: | ||
return true; | ||
} | ||
// istanbul ignore next | ||
throw new Error("unsupported case"); | ||
} | ||
@@ -274,24 +261,10 @@ | ||
} | ||
// istanbul ignore next | ||
return { type: NumericRangeType.InvalidRange, value: "" + value }; | ||
} | ||
function _construct_from_NumericRange(nr: NumericalRange1): NumericalRange0 { | ||
const nrToClone = nr as NumericalRange0; | ||
switch (nrToClone.type) { | ||
case NumericRangeType.InvalidRange: | ||
return { type: NumericRangeType.InvalidRange, value: nrToClone.value }; | ||
case NumericRangeType.MatrixRange: | ||
return { type: NumericRangeType.MatrixRange, value: [...nrToClone.value] as number[][] }; | ||
case NumericRangeType.ArrayRange: | ||
return { type: NumericRangeType.ArrayRange, value: [...nrToClone.value] as number[] }; | ||
case NumericRangeType.SingleValue: | ||
return { type: NumericRangeType.SingleValue, value: nrToClone.value as number }; | ||
case NumericRangeType.Empty: | ||
return { type: NumericRangeType.Empty, value: null }; | ||
} | ||
} | ||
export class NumericRange implements NumericalRange1 { | ||
public static coerce = coerceNumericRange; | ||
public static schema = schemaNumericRange; | ||
// tslint:disable:variable-name | ||
@@ -321,5 +294,5 @@ public static NumericRangeType = NumericRangeType; | ||
} | ||
// console.log(" NR1 = ", nr1.toEncodeableString()); | ||
// console.log(" NR2 = ", nr2.toEncodeableString()); | ||
// istanbul ignore next | ||
assert(false, "NumericalRange#overlap : case not implemented yet "); // TODO | ||
// istanbul ignore next | ||
return false; | ||
@@ -331,3 +304,3 @@ } | ||
constructor(value?: null | string | number | number[] | NumericRange, secondValue?: number) { | ||
constructor(value?: null | string | number | number[], secondValue?: number) { | ||
this.type = NumericRangeType.InvalidRange; | ||
@@ -350,6 +323,2 @@ this.value = null; | ||
this.value = a.value; | ||
} else if (value instanceof NumericRange) { | ||
const a = _construct_from_NumericRange(value); | ||
this.type = a.type; | ||
this.value = a.value; | ||
} else { | ||
@@ -372,2 +341,3 @@ this.value = "<invalid>"; | ||
const value = this.value as number; | ||
// istanbul ignore next | ||
if (value < 0) { | ||
@@ -435,2 +405,3 @@ return false; | ||
case NumericRangeType.InvalidRange: | ||
// istanbul ignore next | ||
if (!(typeof this.value === "string")) { | ||
@@ -489,3 +460,3 @@ throw new Error("Internal Error"); | ||
public set_values(arrayToAlter: any, newValues: any) { | ||
public set_values(arrayToAlter: Buffer | [], newValues: Buffer | []) { | ||
assert_array_or_buffer(arrayToAlter); | ||
@@ -534,10 +505,2 @@ assert_array_or_buffer(newValues); | ||
} | ||
public encode(stream: OutputBinaryStream) { | ||
encodeString(this.toEncodeableString(), stream); | ||
} | ||
public decode(stream: BinaryStream) { | ||
const str = decodeString(stream); | ||
} | ||
} | ||
@@ -724,6 +687,6 @@ | ||
assert(numericRange instanceof NumericRange); | ||
numericRange.encode(stream); | ||
encodeString(numericRange.toEncodeableString(), stream); | ||
} | ||
export function decodeNumericRange(stream: BinaryStream): NumericRange { | ||
export function decodeNumericRange(stream: BinaryStream, _value?: NumericRange): NumericRange { | ||
const str = decodeString(stream); | ||
@@ -730,0 +693,0 @@ return new NumericRange(str); |
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
73169
1330
+ Addednode-opcua-assert@2.22.0(transitive)
+ Addednode-opcua-basic-types@2.22.0(transitive)
+ Addednode-opcua-binary-stream@2.22.0(transitive)
+ Addednode-opcua-buffer-utils@2.22.0(transitive)
+ Addednode-opcua-constants@2.22.0(transitive)
+ Addednode-opcua-date-time@2.22.0(transitive)
+ Addednode-opcua-debug@2.22.0(transitive)
+ Addednode-opcua-enum@2.22.0(transitive)
+ Addednode-opcua-factory@2.22.0(transitive)
+ Addednode-opcua-guid@2.22.0(transitive)
+ Addednode-opcua-nodeid@2.22.0(transitive)
+ Addednode-opcua-status-code@2.22.0(transitive)
+ Addednode-opcua-utils@2.22.0(transitive)
- Removednode-opcua-assert@2.16.0(transitive)
- Removednode-opcua-basic-types@2.20.0(transitive)
- Removednode-opcua-binary-stream@2.17.0(transitive)
- Removednode-opcua-buffer-utils@2.17.0(transitive)
- Removednode-opcua-constants@2.16.0(transitive)
- Removednode-opcua-date-time@2.19.0(transitive)
- Removednode-opcua-debug@2.20.0(transitive)
- Removednode-opcua-enum@2.17.0(transitive)
- Removednode-opcua-factory@2.20.0(transitive)
- Removednode-opcua-guid@2.16.0(transitive)
- Removednode-opcua-nodeid@2.20.0(transitive)
- Removednode-opcua-status-code@2.17.0(transitive)
- Removednode-opcua-utils@2.20.0(transitive)
Updatednode-opcua-assert@2.22.0
Updatednode-opcua-factory@2.22.0