node-opcua-factory
Advanced tools
Comparing version 2.51.0 to 2.52.0
@@ -40,2 +40,1 @@ import { ExpandedNodeId, NodeId } from "node-opcua-nodeid"; | ||
} | ||
export declare function callConstructor(constructor: ConstructorFunc): BaseUAObject; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.callConstructor = exports.DataTypeFactory = void 0; | ||
exports.DataTypeFactory = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
// tslint:disable:no-console | ||
const util = require("util"); | ||
const chalk = require("chalk"); | ||
const util = require("util"); | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -232,3 +231,3 @@ const node_opcua_debug_1 = require("node-opcua-debug"); | ||
} | ||
return callConstructor(constructor); | ||
return new constructor(); | ||
} | ||
@@ -325,8 +324,2 @@ associateWithBinaryEncoding(className, expandedNodeId) { | ||
} | ||
function callConstructor(constructor) { | ||
(0, node_opcua_assert_1.assert)(typeof constructor === "function"); | ||
const constructorFunc = constructor.bind.apply(constructor, arguments); | ||
return new constructorFunc(); | ||
} | ||
exports.callConstructor = callConstructor; | ||
//# sourceMappingURL=datatype_factory.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseUAObject = void 0; | ||
/* eslint-disable prefer-rest-params */ | ||
/* eslint-disable complexity */ | ||
/** | ||
@@ -10,2 +12,3 @@ * @module node-opcua-factory | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
const node_opcua_basic_types_1 = require("node-opcua-basic-types"); | ||
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream"); | ||
@@ -17,7 +20,5 @@ const node_opcua_debug_1 = require("node-opcua-debug"); | ||
const factories_enumerations_1 = require("./factories_enumerations"); | ||
const datatype_factory_1 = require("./datatype_factory"); | ||
const factories_factories_1 = require("./factories_factories"); | ||
const factories_structuredTypeSchema_1 = require("./factories_structuredTypeSchema"); | ||
const types_1 = require("./types"); | ||
const node_opcua_basic_types_1 = require("node-opcua-basic-types"); | ||
function r(str, length = 30) { | ||
@@ -53,3 +54,3 @@ return (str + " ").substr(0, length); | ||
const constructor = field.fieldTypeConstructor; | ||
value = (0, datatype_factory_1.callConstructor)(constructor); | ||
value = new constructor(); | ||
value.decodeDebug(stream, options); | ||
@@ -114,2 +115,4 @@ } | ||
} | ||
// eslint-disable-next-line complexity | ||
// eslint-disable-next-line max-statements | ||
function _exploreObject(self, field, data, args) { | ||
@@ -201,2 +204,3 @@ if (!self) { | ||
else if (typeof value === "object" && value !== null && value !== undefined) { | ||
// eslint-disable-next-line prefer-spread | ||
value = value.toString.apply(value, args); | ||
@@ -271,20 +275,22 @@ } | ||
case types_1.FieldCategory.enumeration: | ||
const s = field.schema; | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
// tslint:disable:no-console | ||
console.log("xxxx cannot find typeEnum", s); | ||
{ | ||
const s = field.schema; | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
// tslint:disable:no-console | ||
console.log("xxxx cannot find typeEnum", s); | ||
} | ||
// istanbul ignore next | ||
if (!s.typedEnum.get(value)) { | ||
// tslint:disable:no-console | ||
s.typedEnum._isFlaggable = true; | ||
console.log("xxxx cannot find typeEnum value ", value); | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value) + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} | ||
else { | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value).key + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} | ||
} | ||
// istanbul ignore next | ||
if (!s.typedEnum.get(value)) { | ||
// tslint:disable:no-console | ||
s.typedEnum._isFlaggable = true; | ||
console.log("xxxx cannot find typeEnum value ", value); | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value) + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} | ||
else { | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value).key + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} | ||
break; | ||
@@ -352,3 +358,5 @@ case types_1.FieldCategory.basic: | ||
class BaseUAObject { | ||
constructor() { } | ||
constructor() { | ||
/** */ | ||
} | ||
/** | ||
@@ -360,3 +368,5 @@ * Encode the object to the binary stream. | ||
*/ | ||
encode(stream) { } | ||
encode(stream) { | ||
/** */ | ||
} | ||
/** | ||
@@ -368,3 +378,5 @@ * Decode the object from the binary stream. | ||
*/ | ||
decode(stream) { } | ||
decode(stream) { | ||
/** */ | ||
} | ||
/** | ||
@@ -385,3 +397,3 @@ * Calculate the required size to store this object in a binary stream. | ||
toString(...args) { | ||
if (this.schema && this.schema.hasOwnProperty("toString")) { | ||
if (this.schema && Object.prototype.hasOwnProperty.call(this.schema, "toString")) { | ||
return this.schema.toString.apply(this, arguments); | ||
@@ -394,3 +406,3 @@ } | ||
} | ||
return this.explore.apply(this, arguments); | ||
return this.explore(); | ||
} | ||
@@ -425,3 +437,3 @@ } | ||
if (typeof field.switchValue === "number") { | ||
// skip | ||
// skip | ||
if (self["switchField"] !== field.switchValue) { | ||
@@ -428,0 +440,0 @@ continue; |
@@ -13,4 +13,3 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
// tslint:disable:no-empty | ||
// tslint:enable:no-unused-variable | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function defaultEncode(value, stream) { } | ||
@@ -46,2 +45,3 @@ function defaultDecode(stream) { | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function encodeNull(value, stream) { } | ||
@@ -48,0 +48,0 @@ function decodeNull(stream) { |
@@ -58,3 +58,3 @@ "use strict"; | ||
const name = options.name; | ||
if (_enumerations.hasOwnProperty(name)) { | ||
if (Object.prototype.hasOwnProperty.call(_enumerations, name)) { | ||
throw new Error("factories.registerEnumeration : Enumeration " + options.name + " has been already inserted"); | ||
@@ -61,0 +61,0 @@ } |
@@ -1,5 +0,5 @@ | ||
import { FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types"; | ||
import { BinaryStream } from "node-opcua-binary-stream"; | ||
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid"; | ||
import { DataTypeFactory } from "./datatype_factory"; | ||
import { FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types"; | ||
export declare class StructuredTypeSchema extends TypeSchemaBase { | ||
@@ -34,3 +34,2 @@ fields: FieldType[]; | ||
* (by walking up the inheritance chain) | ||
* @method extract_all_fields | ||
* | ||
@@ -37,0 +36,0 @@ */ |
@@ -8,3 +8,2 @@ "use strict"; | ||
const chalk = require("chalk"); | ||
const types_1 = require("./types"); | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -17,2 +16,3 @@ const node_opcua_nodeid_1 = require("node-opcua-nodeid"); | ||
const factories_schema_helpers_1 = require("./factories_schema_helpers"); | ||
const types_1 = require("./types"); | ||
function figureOutFieldCategory(field) { | ||
@@ -186,3 +186,2 @@ const fieldType = field.fieldType; | ||
* (by walking up the inheritance chain) | ||
* @method extract_all_fields | ||
* | ||
@@ -189,0 +188,0 @@ */ |
@@ -110,3 +110,3 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
*/ | ||
computer_default_value(defaultValue: any): any; | ||
computer_default_value(defaultValue: unknown): any; | ||
} |
@@ -14,6 +14,2 @@ "use strict"; | ||
})(FieldCategory = exports.FieldCategory || (exports.FieldCategory = {})); | ||
// tslint:disable-next-line:no-empty | ||
function defaultEncode(value, stream) { } | ||
// tslint:disable-next-line:no-empty | ||
function defaultDecode(stream) { } | ||
/** | ||
@@ -20,0 +16,0 @@ * @class TypeSchemaBase |
{ | ||
"name": "node-opcua-factory", | ||
"version": "2.51.0", | ||
"version": "2.52.0", | ||
"description": "pure nodejs OPCUA SDK - module -factory", | ||
@@ -9,3 +9,3 @@ "main": "./dist/index.js", | ||
"build": "tsc -b", | ||
"lint": "tslint source/**/*.ts", | ||
"lint": "eslint source/**/*.ts", | ||
"clean": "node -e \"require('rimraf').sync('dist');\"", | ||
@@ -16,11 +16,11 @@ "test": "echo no test" | ||
"chalk": "4.1.2", | ||
"node-opcua-assert": "2.51.0", | ||
"node-opcua-basic-types": "2.51.0", | ||
"node-opcua-binary-stream": "2.51.0", | ||
"node-opcua-debug": "2.51.0", | ||
"node-opcua-enum": "2.51.0", | ||
"node-opcua-guid": "2.51.0", | ||
"node-opcua-nodeid": "2.51.0", | ||
"node-opcua-status-code": "2.51.0", | ||
"node-opcua-utils": "2.51.0" | ||
"node-opcua-assert": "2.52.0", | ||
"node-opcua-basic-types": "2.52.0", | ||
"node-opcua-binary-stream": "2.52.0", | ||
"node-opcua-debug": "2.52.0", | ||
"node-opcua-enum": "2.52.0", | ||
"node-opcua-guid": "2.52.0", | ||
"node-opcua-nodeid": "2.52.0", | ||
"node-opcua-status-code": "2.52.0", | ||
"node-opcua-utils": "2.52.0" | ||
}, | ||
@@ -42,3 +42,3 @@ "author": "Etienne Rossignon", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "75feb111daf7ec65fa0111e4fa5beb8987fd4945" | ||
"gitHead": "3ec6296e8fd4df0e05b9d887f0b7dd20113a9ce1" | ||
} |
/** | ||
* @module node-opcua-factory | ||
*/ | ||
// tslint:disable:no-console | ||
import * as util from "util"; | ||
import * as chalk from "chalk"; | ||
import * as util from "util"; | ||
@@ -45,3 +44,3 @@ import { assert } from "node-opcua-assert"; | ||
// ----------------------------- | ||
public registerSimpleType(name: string, dataTypeNodeId: NodeId, def: BasicTypeDefinition) { | ||
public registerSimpleType(name: string, dataTypeNodeId: NodeId, def: BasicTypeDefinition): void { | ||
// istanbul ignore next | ||
@@ -261,6 +260,6 @@ if (this._simpleTypes.has(name)) { | ||
} | ||
return callConstructor(constructor); | ||
return new constructor(); | ||
} | ||
public associateWithBinaryEncoding(className: string, expandedNodeId: ExpandedNodeId) { | ||
public associateWithBinaryEncoding(className: string, expandedNodeId: ExpandedNodeId): void { | ||
const classConstructor = this.getStructureTypeConstructor(className); | ||
@@ -364,8 +363,2 @@ if (doDebug) { | ||
return expandedNodeId.toString(); | ||
} | ||
export function callConstructor(constructor: ConstructorFunc): BaseUAObject { | ||
assert(typeof constructor === "function"); | ||
const constructorFunc: any = constructor.bind.apply(constructor, arguments as any); | ||
return new constructorFunc(); | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable prefer-rest-params */ | ||
/* eslint-disable complexity */ | ||
/** | ||
@@ -7,2 +9,3 @@ * @module node-opcua-factory | ||
import { assert } from "node-opcua-assert"; | ||
import { AttributeIds } from "node-opcua-basic-types"; | ||
import { BinaryStream, BinaryStreamSizeCalculator, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
@@ -15,7 +18,6 @@ import { hexDump } from "node-opcua-debug"; | ||
import { getEnumeration, hasEnumeration } from "./factories_enumerations"; | ||
import { callConstructor, DataTypeFactory } from "./datatype_factory"; | ||
import { DataTypeFactory } from "./datatype_factory"; | ||
import { getStructureTypeConstructor } from "./factories_factories"; | ||
import { get_base_schema, StructuredTypeSchema } from "./factories_structuredTypeSchema"; | ||
import { EnumerationDefinition, FieldCategory, StructuredTypeField, BuiltInTypeDefinition, FieldType } from "./types"; | ||
import { AttributeIds } from "node-opcua-basic-types"; | ||
@@ -55,3 +57,3 @@ function r(str: string, length = 30) { | ||
const constructor = field.fieldTypeConstructor; | ||
value = callConstructor(constructor); | ||
value = new constructor(); | ||
value.decodeDebug(stream, options); | ||
@@ -128,3 +130,5 @@ } | ||
} | ||
function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: ExploreParams, args: any) { | ||
// eslint-disable-next-line complexity | ||
// eslint-disable-next-line max-statements | ||
function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: ExploreParams, args: any): void { | ||
if (!self) { | ||
@@ -224,2 +228,3 @@ return; | ||
} else if (typeof value === "object" && value !== null && value !== undefined) { | ||
// eslint-disable-next-line prefer-spread | ||
value = value.toString.apply(value, args); | ||
@@ -306,20 +311,22 @@ } | ||
case FieldCategory.enumeration: | ||
const s = field.schema as EnumerationDefinition; | ||
{ | ||
const s = field.schema as EnumerationDefinition; | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
// tslint:disable:no-console | ||
console.log("xxxx cannot find typeEnum", s); | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
// tslint:disable:no-console | ||
console.log("xxxx cannot find typeEnum", s); | ||
} | ||
// istanbul ignore next | ||
if (!s.typedEnum.get(value)) { | ||
// tslint:disable:no-console | ||
(s.typedEnum as any)._isFlaggable = true; | ||
console.log("xxxx cannot find typeEnum value ", value); | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value) + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} else { | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value)!.key + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} | ||
} | ||
// istanbul ignore next | ||
if (!s.typedEnum.get(value)) { | ||
// tslint:disable:no-console | ||
(s.typedEnum as any)._isFlaggable = true; | ||
console.log("xxxx cannot find typeEnum value ", value); | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value) + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} else { | ||
str = fieldNameF + " " + fieldTypeF + ": " + s.name + "." + s.typedEnum.get(value)!.key + " ( " + value + ")"; | ||
data.lines.push(str); | ||
} | ||
break; | ||
@@ -399,3 +406,5 @@ case FieldCategory.basic: | ||
export class BaseUAObject { | ||
constructor() {} | ||
constructor() { | ||
/** */ | ||
} | ||
@@ -408,3 +417,5 @@ /** | ||
*/ | ||
public encode(stream: OutputBinaryStream): void {} | ||
public encode(stream: OutputBinaryStream): void { | ||
/** */ | ||
} | ||
@@ -417,3 +428,5 @@ /** | ||
*/ | ||
public decode(stream: BinaryStream): void {} | ||
public decode(stream: BinaryStream): void { | ||
/** */ | ||
} | ||
@@ -436,3 +449,3 @@ /** | ||
public toString(...args: any[]): string { | ||
if (this.schema && this.schema.hasOwnProperty("toString")) { | ||
if (this.schema && Object.prototype.hasOwnProperty.call(this.schema, "toString")) { | ||
return this.schema.toString.apply(this, arguments as any); | ||
@@ -444,3 +457,3 @@ } else { | ||
} | ||
return this.explore.apply(this, arguments as any); | ||
return this.explore(); | ||
} | ||
@@ -478,4 +491,4 @@ } | ||
if (typeof field.switchValue === "number" ) { | ||
// skip | ||
if (typeof field.switchValue === "number") { | ||
// skip | ||
if (self["switchField"] !== field.switchValue) { | ||
@@ -482,0 +495,0 @@ continue; |
@@ -49,3 +49,3 @@ /** | ||
*/ | ||
export function registerBasicType(schema: BasicTypeOptions) { | ||
export function registerBasicType(schema: BasicTypeOptions): void { | ||
const exists: boolean = hasBuiltInType(schema.name); | ||
@@ -52,0 +52,0 @@ |
@@ -38,3 +38,3 @@ /** | ||
export function registerSpecialVariantEncoder(constructor: ConstructorFunc) { | ||
export function registerSpecialVariantEncoder(constructor: ConstructorFunc): void { | ||
assert(typeof constructor === "function"); | ||
@@ -41,0 +41,0 @@ |
@@ -68,4 +68,3 @@ /** | ||
// tslint:disable:no-empty | ||
// tslint:enable:no-unused-variable | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function defaultEncode(value: any, stream: OutputBinaryStream): void {} | ||
@@ -113,2 +112,3 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
function encodeNull(value: any, stream: OutputBinaryStream): void {} | ||
@@ -381,4 +381,4 @@ | ||
export function getTypeMap() { | ||
export function getTypeMap(): Map<string, BasicTypeSchema> { | ||
return _defaultTypeMap; | ||
} |
@@ -18,3 +18,3 @@ /** | ||
const value = stream.readInteger(); | ||
const e = (typedEnum.get(value) as any) as string; | ||
const e = typedEnum.get(value) as any as string; | ||
// istanbul ignore next | ||
@@ -76,7 +76,7 @@ if (!e) { | ||
export function registerEnumeration(options: EnumerationDefinitionOptions): Enum { | ||
assert(Object.prototype.hasOwnProperty.call(options,"name")); | ||
assert(Object.prototype.hasOwnProperty.call(options,"enumValues")); | ||
assert(Object.prototype.hasOwnProperty.call(options, "name")); | ||
assert(Object.prototype.hasOwnProperty.call(options, "enumValues")); | ||
const name = options.name; | ||
if (_enumerations.hasOwnProperty(name)) { | ||
if (Object.prototype.hasOwnProperty.call(_enumerations, name)) { | ||
throw new Error("factories.registerEnumeration : Enumeration " + options.name + " has been already inserted"); | ||
@@ -83,0 +83,0 @@ } |
@@ -5,3 +5,2 @@ /** | ||
import * as chalk from "chalk"; | ||
import { CommonInterface, FieldCategory, FieldInterfaceOptions, FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types"; | ||
@@ -18,2 +17,3 @@ import { assert } from "node-opcua-assert"; | ||
import { DataTypeFactory } from "./datatype_factory"; | ||
import { CommonInterface, FieldCategory, FieldInterfaceOptions, FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types"; | ||
@@ -170,3 +170,3 @@ function figureOutFieldCategory(field: FieldInterfaceOptions): FieldCategory { | ||
} | ||
public toString() { | ||
public toString(): string { | ||
const str: string[] = []; | ||
@@ -205,3 +205,3 @@ str.push("name = " + this.name); | ||
*/ | ||
export function get_base_schema(schema: StructuredTypeSchema) { | ||
export function get_base_schema(schema: StructuredTypeSchema): StructuredTypeSchema | null { | ||
let baseSchema = schema._baseSchema; | ||
@@ -241,6 +241,5 @@ if (baseSchema) { | ||
* (by walking up the inheritance chain) | ||
* @method extract_all_fields | ||
* | ||
*/ | ||
export function extract_all_fields(schema: StructuredTypeSchema) { | ||
export function extract_all_fields(schema: StructuredTypeSchema): string[] { | ||
// returns cached result if any | ||
@@ -247,0 +246,0 @@ // istanbul ignore next |
@@ -128,8 +128,2 @@ /** | ||
// tslint:disable-next-line:no-empty | ||
function defaultEncode(value: any, stream: BinaryStream): void {} | ||
// tslint:disable-next-line:no-empty | ||
function defaultDecode(stream: BinaryStream): void {} | ||
/** | ||
@@ -170,3 +164,3 @@ * @class TypeSchemaBase | ||
*/ | ||
public computer_default_value(defaultValue: any): any { | ||
public computer_default_value(defaultValue: unknown): any { | ||
if (defaultValue === undefined) { | ||
@@ -173,0 +167,0 @@ defaultValue = this.defaultValue; |
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
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
236524
4390
+ Addednode-opcua-assert@2.52.0(transitive)
+ Addednode-opcua-basic-types@2.52.0(transitive)
+ Addednode-opcua-binary-stream@2.52.0(transitive)
+ Addednode-opcua-buffer-utils@2.52.0(transitive)
+ Addednode-opcua-constants@2.52.0(transitive)
+ Addednode-opcua-date-time@2.52.0(transitive)
+ Addednode-opcua-debug@2.52.0(transitive)
+ Addednode-opcua-enum@2.52.0(transitive)
+ Addednode-opcua-guid@2.52.0(transitive)
+ Addednode-opcua-nodeid@2.52.0(transitive)
+ Addednode-opcua-status-code@2.52.0(transitive)
+ Addednode-opcua-utils@2.52.0(transitive)
- Removednode-opcua-assert@2.51.0(transitive)
- Removednode-opcua-basic-types@2.51.0(transitive)
- Removednode-opcua-binary-stream@2.51.0(transitive)
- Removednode-opcua-buffer-utils@2.51.0(transitive)
- Removednode-opcua-constants@2.51.0(transitive)
- Removednode-opcua-date-time@2.51.0(transitive)
- Removednode-opcua-debug@2.51.0(transitive)
- Removednode-opcua-enum@2.51.0(transitive)
- Removednode-opcua-guid@2.51.0(transitive)
- Removednode-opcua-nodeid@2.51.0(transitive)
- Removednode-opcua-status-code@2.51.0(transitive)
- Removednode-opcua-utils@2.51.0(transitive)
Updatednode-opcua-assert@2.52.0
Updatednode-opcua-debug@2.52.0
Updatednode-opcua-enum@2.52.0
Updatednode-opcua-guid@2.52.0
Updatednode-opcua-nodeid@2.52.0
Updatednode-opcua-utils@2.52.0