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

node-opcua-factory

Package Overview
Dependencies
Maintainers
1
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-factory - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

dist/constructor_type.d.ts

16

dist/factories_baseobject.js

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

const factories_enumerations_1 = require("./factories_enumerations");
const datatype_factory_1 = require("./datatype_factory");
const factories_factories_1 = require("./factories_factories");

@@ -49,3 +50,3 @@ const factories_structuredTypeSchema_1 = require("./factories_structuredTypeSchema");

const constructor = field.fieldTypeConstructor;
value = factories_factories_1.callConstructor(constructor);
value = datatype_factory_1.callConstructor(constructor);
value.decodeDebug(stream, options);

@@ -57,2 +58,6 @@ }

function applyOnAllSchemaFields(self, schema, data, functor, args) {
const baseSchema = factories_structuredTypeSchema_1.get_base_schema(schema);
if (baseSchema) {
applyOnAllSchemaFields(self, baseSchema, data, functor, args);
}
for (const field of schema.fields) {

@@ -143,3 +148,3 @@ functor(self, field, data, args);

if (fieldType === "IntegerId" || fieldType === "UInt32") {
value = "" + value + " 0x" + value.toString(16);
value = "" + value + " " + ((value !== undefined) ? "0x" + value.toString(16) : "undefined");
}

@@ -165,3 +170,8 @@ else if (fieldType === "DateTime" || fieldType === "UtcTime") {

else {
field.fieldTypeConstructor = field.fieldTypeConstructor || factories_factories_1.getStructureTypeConstructor(fieldType);
const typeDictionary = self.schema.$typeDictionary;
if (!typeDictionary) {
console.log(" No typeDictionary for ", self.schema);
}
field.fieldTypeConstructor = field.fieldTypeConstructor ||
(typeDictionary.getStructureTypeConstructor(fieldType));
const fieldTypeConstructor = field.fieldTypeConstructor;

@@ -168,0 +178,0 @@ const _newDesc = fieldTypeConstructor.prototype.schema || fieldTypeConstructor.schema;

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

*/
const _ = require("underscore");
const util = require("util");
const node_opcua_assert_1 = require("node-opcua-assert");
const node_opcua_basic_types_1 = require("node-opcua-basic-types");
const _ = require("underscore");
const util = require("util");
const factories_builtin_types_1 = require("./factories_builtin_types");

@@ -40,2 +40,7 @@ /**

function registerBasicType(schema) {
const exists = factories_builtin_types_1.hasBuiltInType(schema.name);
if (exists) {
console.log(schema);
throw new Error(`Basic Type ${schema.name} already registered`);
}
const name = schema.name;

@@ -81,4 +86,4 @@ const t = factories_builtin_types_1.findSimpleType(schema.subType);

registerBasicType({ name: "UtcTime", subType: "DateTime" });
registerBasicType({ name: "Int8", subType: "SByte" });
registerBasicType({ name: "UInt8", subType: "Byte" });
// already ? registerBasicType({name: "Int8", subType: "SByte"});
// already ? registerBasicType({name: "UInt8", subType: "Byte"});
registerBasicType({ name: "Char", subType: "Byte" });

@@ -97,7 +102,38 @@ // xx registerBasicType({name:"XmlElement" ,subType:"String" });

registerBasicType({ name: "Image", subType: "ByteString" });
registerBasicType({ name: "ImageBMP", subType: "ByteString" });
registerBasicType({ name: "ImageJPG", subType: "ByteString" });
registerBasicType({ name: "ImagePNG", subType: "ByteString" });
registerBasicType({ name: "ImageGIF", subType: "ByteString" });
registerBasicType({ name: "NodeIdType", subType: "NodeId" });
registerBasicType({ name: "ImageBMP", subType: "Image" });
registerBasicType({ name: "ImageGIF", subType: "Image" });
registerBasicType({ name: "ImageJPG", subType: "Image" });
registerBasicType({ name: "ImagePNG", subType: "Image" });
registerBasicType({ name: "AudioDataType", subType: "ByteString" });
registerBasicType({ name: "BitFieldMaskDataType", subType: "UInt64" });
registerBasicType({ name: "DataSetFieldFlags", subType: "UInt16" });
registerBasicType({ name: "DataSetFieldContentMask", subType: "UInt32" });
registerBasicType({ name: "UadpNetworkMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "UadpDataSetMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "JsonNetworkMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "JsonDataSetMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "PermissionType", subType: "UInt32" });
registerBasicType({ name: "AccessLevelType", subType: "Byte" });
registerBasicType({ name: "AccessLevelExType", subType: "UInt32" });
registerBasicType({ name: "EventNotifierType", subType: "Byte" });
registerBasicType({ name: "AccessRestrictionType", subType: "UInt32" });
registerBasicType({ name: "NormalizedString", subType: "String" });
registerBasicType({ name: "DecimalString", subType: "String" });
registerBasicType({ name: "DurationString", subType: "String" });
registerBasicType({ name: "TimeString", subType: "String" });
registerBasicType({ name: "DateString", subType: "String" });
registerBasicType({ name: "Index", subType: "UInt32" });
registerBasicType({ name: "VersionTime", subType: "UInt32" });
registerBasicType({ name: "ApplicationInstanceCertificate", subType: "ByteString" });
registerBasicType({ name: "AttributeWriteMask", subType: "UInt32" });
registerBasicType({ name: "Date", subType: "DateTime" });
// registerBasicType({ name: "Counter", subType: "UInt32" });
// registerBasicType({ name: "IntegerId", subType: "UInt32" });
// registerBasicType({ name: "UtcTime", subType: "DateTime" });
// registerBasicType({ name: "Duration", subType: "Double" });
// registerBasicType({ name: "LocaleId", subType: "String" });
// registerBasicType({ name: "NumericRange", subType: "String" });
// registerBasicType({ name: "Time", subType: "String" });
// registerBasicType({ name: "SessionAuthenticationToken", subType: "NodeId" });
//# sourceMappingURL=factories_basic_type.js.map

2

dist/factories_builtin_types_special.d.ts

@@ -1,2 +0,2 @@

import { ConstructorFunc } from "./factories_factories";
import { ConstructorFunc } from "./constructor_type";
export declare function registerSpecialVariantEncoder(constructor: ConstructorFunc): void;

@@ -6,4 +6,4 @@ "use strict";

*/
const _ = require("underscore");
const node_opcua_assert_1 = require("node-opcua-assert");
const _ = require("underscore");
const factories_builtin_types_1 = require("./factories_builtin_types");

@@ -10,0 +10,0 @@ function _self_encode(constructor) {

@@ -224,3 +224,5 @@ "use strict";

const typeSchema = _defaultTypeMap.get(name);
node_opcua_assert_1.assert(typeSchema);
if (!typeSchema) {
throw new Error("Cannot find schema for simple type " + name);
}
node_opcua_assert_1.assert(typeSchema instanceof types_1.TypeSchemaBase);

@@ -227,0 +229,0 @@ return typeSchema;

@@ -5,12 +5,7 @@ /**

import { ExpandedNodeId } from "node-opcua-nodeid";
import { DataTypeFactory } from "./datatype_factory";
import { ConstructorFuncWithSchema, ConstructorFunc } from "./constructor_type";
import { BaseUAObject } from "./factories_baseobject";
import { StructuredTypeSchema } from "./factories_structuredTypeSchema";
declare type BaseUAObjectConstructable = new (options?: any) => BaseUAObject;
export declare type ConstructorFunc = BaseUAObjectConstructable;
export interface ConstructorFuncWithSchema extends ConstructorFunc {
schema: StructuredTypeSchema;
possibleFields: string[];
encodingDefaultBinary: ExpandedNodeId;
encodingDefaultXml: ExpandedNodeId;
}
export declare function getStandartDataTypeFactory(): DataTypeFactory;
export declare function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema;

@@ -20,4 +15,2 @@ export declare function hasStructuredType(typeName: string): boolean;

export declare function registerFactory(typeName: string, constructor: ConstructorFuncWithSchema): void;
export declare function dump(): void;
export declare function callConstructor(constructor: ConstructorFunc): BaseUAObject;
export declare function getConstructor(expandedNodeId: ExpandedNodeId): ConstructorFunc | null;

@@ -27,2 +20,2 @@ export declare function hasConstructor(expandedNodeId: ExpandedNodeId): boolean;

export declare function registerClassDefinition(className: string, classConstructor: ConstructorFuncWithSchema): void;
export {};
export declare function dump(): void;

@@ -7,127 +7,52 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = require("chalk");
const _ = require("underscore");
const node_opcua_assert_1 = require("node-opcua-assert");
const node_opcua_debug_1 = require("node-opcua-debug");
const factories_baseobject_1 = require("./factories_baseobject");
const datatype_factory_1 = require("./datatype_factory");
const debugLog = node_opcua_debug_1.make_debugLog(__filename);
const doDebug = node_opcua_debug_1.checkDebugFlag(__filename);
const constructorMap = {};
const _globalStructuredTypeConstructors = {};
let globalFactory;
function getStandartDataTypeFactory() {
if (!globalFactory) {
globalFactory = new datatype_factory_1.DataTypeFactory([]);
globalFactory.targetNamespace = "http://opcfoundation.org/UA/";
}
return globalFactory;
}
exports.getStandartDataTypeFactory = getStandartDataTypeFactory;
function getStructureTypeConstructor(typeName) {
return _globalStructuredTypeConstructors[typeName];
return getStandartDataTypeFactory().getStructureTypeConstructor(typeName);
}
exports.getStructureTypeConstructor = getStructureTypeConstructor;
function hasStructuredType(typeName) {
return !!_globalStructuredTypeConstructors[typeName];
return getStandartDataTypeFactory().hasStructuredType(typeName);
}
exports.hasStructuredType = hasStructuredType;
function getStructuredTypeSchema(typeName) {
const struct = _globalStructuredTypeConstructors[typeName];
if (!struct) {
throw new Error("cannot find structured type for " + typeName);
}
return struct.schema;
return getStandartDataTypeFactory().getStructuredTypeSchema(typeName);
}
exports.getStructuredTypeSchema = getStructuredTypeSchema;
function registerFactory(typeName, constructor) {
/* istanbul ignore next */
if (getStructureTypeConstructor(typeName)) {
console.log(getStructureTypeConstructor(typeName));
throw new Error(" registerFactory : " + typeName + " already registered");
}
_globalStructuredTypeConstructors[typeName] = constructor;
return getStandartDataTypeFactory().registerFactory(typeName, constructor);
}
exports.registerFactory = registerFactory;
/* istanbul ignore next */
function dump() {
console.log(" dumping registered factories");
console.log(" Factory ", Object.keys(_globalStructuredTypeConstructors).sort().forEach((e) => e));
console.log(" done");
}
exports.dump = dump;
function callConstructor(constructor) {
node_opcua_assert_1.assert(_.isFunction(constructor));
const constructorFunc = constructor.bind.apply(constructor, arguments);
return new constructorFunc();
}
exports.callConstructor = callConstructor;
function getConstructor(expandedNodeId) {
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
if (!(expandedNodeId && (expandedNodeIdKey in constructorMap))) {
debugLog(chalk_1.default.red("#getConstructor : cannot find constructor for expandedId "), expandedNodeId.toString());
return null;
}
return constructorMap[expandedNodeIdKey];
return getStandartDataTypeFactory().getConstructor(expandedNodeId);
}
exports.getConstructor = getConstructor;
function hasConstructor(expandedNodeId) {
if (!expandedNodeId) {
return false;
}
/* istanbul ignore next */
if (!verifyExpandedNodeId(expandedNodeId)) {
console.log("Invalid expandedNodeId");
return false;
}
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
return !!constructorMap[expandedNodeIdKey];
return getStandartDataTypeFactory().hasConstructor(expandedNodeId);
}
exports.hasConstructor = hasConstructor;
function constructObject(expandedNodeId) {
if (!verifyExpandedNodeId(expandedNodeId)) {
throw new Error(" constructObject : invalid expandedNodeId provided " + expandedNodeId.toString());
}
const constructor = getConstructor(expandedNodeId);
if (!constructor) {
debugLog("Cannot find constructor for " + expandedNodeId.toString());
return new factories_baseobject_1.BaseUAObject();
// throw new Error("Cannot find constructor for " + expandedNodeId.toString());
}
return callConstructor(constructor);
return getStandartDataTypeFactory().constructObject(expandedNodeId);
}
exports.constructObject = constructObject;
function verifyExpandedNodeId(expandedNodeId) {
/* istanbul ignore next */
if (expandedNodeId.value instanceof Buffer) {
throw new Error("getConstructor not implemented for opaque nodeid");
}
if (expandedNodeId.namespace === 0) {
if (expandedNodeId.namespaceUri === "http://opcfoundation.org/UA/" || !expandedNodeId.namespaceUri) {
return true;
}
// When namespace is ZERO, namepaceUri must be "http://opcfoundation.org/UA/" or nothing
return false;
}
else {
// expandedNodeId.namespace !==0
// in this case a valid expandedNodeId.namespaceUri must be provided
return !!expandedNodeId.namespaceUri && expandedNodeId.namespaceUri.length > 2;
}
}
function makeExpandedNodeIdKey(expandedNodeId) {
if (expandedNodeId.namespace === 0) {
return expandedNodeId.value.toString();
}
return expandedNodeId.namespaceUri + "@" + expandedNodeId.value.toString();
}
function registerClassDefinition(className, classConstructor) {
registerFactory(className, classConstructor);
const expandedNodeId = classConstructor.encodingDefaultBinary;
if (doDebug) {
debugLog(" registering ", className, expandedNodeId.toString());
}
/* istanbul ignore next */
if (!verifyExpandedNodeId(expandedNodeId)) {
throw new Error("Invalid expandedNodeId");
}
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
/* istanbul ignore next */
if (expandedNodeIdKey in constructorMap) {
throw new Error(" Class " + className + " with ID " + expandedNodeId +
" already in constructorMap for " + constructorMap[expandedNodeIdKey].name);
}
constructorMap[expandedNodeIdKey] = classConstructor;
return getStandartDataTypeFactory().registerClassDefinition(className, classConstructor);
}
exports.registerClassDefinition = registerClassDefinition;
/* istanbul ignore next */
function dump() {
getStandartDataTypeFactory().dump();
}
exports.dump = dump;
//# sourceMappingURL=factories_factories.js.map

@@ -16,20 +16,2 @@ "use strict";

const factories_schema_helpers_1 = require("./factories_schema_helpers");
// export interface StructuredTypeSchemaInterface extends CommonInterface {
//
// fields: FieldType[];
//
// baseType?: string;
// documentation?: string;
//
// id: number | NodeId;
//
// // caches
// _possibleFields?: any[];
// _baseSchema?: StructuredTypeSchemaInterface;
// _resolved?: boolean;
//
// isValid?: (options: any) => boolean;
// decodeDebug?: (stream: BinaryStream, options: any) => any;
// constructHook?: (options: any) => any;
// }
function figureOutFieldCategory(field) {

@@ -134,2 +116,5 @@ const fieldType = field.fieldType;

}
if (schema.baseType === "Union") {
return null;
}
if (schema.baseType && schema.baseType !== "BaseUAObject") {

@@ -217,3 +202,7 @@ const baseType = factories_factories_1.getStructureTypeConstructor(schema.baseType);

}
/* istanbul ignore next */
if (invalidOptionsFields.length !== 0) {
// tslint:disable:no-console
console.log(chalk_1.default.yellow("possible fields= "), possibleFields.sort().join(" "));
console.log(chalk_1.default.red("current fields= "), currentFields.sort().join(" "));
throw new Error(" invalid field found in option :" + JSON.stringify(invalidOptionsFields));

@@ -220,0 +209,0 @@ }

/**
* @module node-opcua-factory
*/
export * from "./constructor_type";
export * from "./datatype_factory";
export * from "./factories_id_generator";

@@ -5,0 +7,0 @@ export * from "./factories_enumerations";

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

Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module node-opcua-factory
*/
__export(require("./datatype_factory"));
__export(require("./factories_id_generator"));

@@ -11,0 +9,0 @@ __export(require("./factories_enumerations"));

import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import { Enum } from "node-opcua-enum";
import { NodeId } from "node-opcua-nodeid";
import { ConstructorFunc } from "./factories_factories";
import { ConstructorFunc } from "./constructor_type";
import { FieldInterfaceOptions } from "./types";

@@ -6,0 +6,0 @@ export interface CommonInterface {

{
"name": "node-opcua-factory",
"version": "2.1.2",
"version": "2.1.3",
"description": "pure nodejs OPCUA SDK - module -factory",

@@ -15,9 +15,9 @@ "main": "./dist/index.js",

"node-opcua-assert": "^2.0.0",
"node-opcua-basic-types": "^2.1.2",
"node-opcua-basic-types": "^2.1.3",
"node-opcua-binary-stream": "^2.1.0",
"node-opcua-enum": "^2.1.0",
"node-opcua-guid": "^2.1.0",
"node-opcua-nodeid": "^2.1.0",
"node-opcua-status-code": "^2.1.1",
"node-opcua-utils": "^2.1.2",
"node-opcua-nodeid": "^2.1.3",
"node-opcua-status-code": "^2.1.3",
"node-opcua-utils": "^2.1.3",
"underscore": "^1.9.1"

@@ -43,3 +43,3 @@ },

"homepage": "http://node-opcua.github.io/",
"gitHead": "46c4676f5623126ee95c60c25bcdedd8091ba342"
"gitHead": "a47d959488b88d80c6d4d339d08c80ccc5490ffd"
}

@@ -11,5 +11,7 @@ /**

import * as _ from "underscore";
import { getBuildInType } from "./factories_builtin_types";
import { getEnumeration, hasEnumeration } from "./factories_enumerations";
import { callConstructor, getStructureTypeConstructor } from "./factories_factories";
import { callConstructor, DataTypeFactory } from "./datatype_factory";
import { getStructureTypeConstructor } from "./factories_factories";
import { get_base_schema, StructuredTypeSchema } from "./factories_structuredTypeSchema";

@@ -63,3 +65,3 @@ import { EnumerationDefinition, FieldCategory, StructuredTypeField } from "./types";

function applyOnAllSchemaFields(
self: any,
self: BaseUAObject,
schema: StructuredTypeSchema,

@@ -70,2 +72,8 @@ data: any,

) {
const baseSchema = get_base_schema(schema);
if (baseSchema) {
applyOnAllSchemaFields(self, baseSchema, data, functor, args);
}
for (const field of schema.fields) {

@@ -100,3 +108,3 @@ functor(self, field, data, args);

function _exploreObject(self: any, field: StructuredTypeField, data: any, args: any) {
function _exploreObject(self: BaseUAObject, field: StructuredTypeField, data: any, args: any) {

@@ -115,3 +123,3 @@ if (!self) {

let value = self[fieldName];
let value = (self as any)[fieldName];

@@ -161,3 +169,3 @@ let str;

function _dump_simple_value(self: any, field: StructuredTypeField, data: any, value: any, fieldType: string) {
function _dump_simple_value(self: BaseUAObject, field: StructuredTypeField, data: any, value: any, fieldType: string) {

@@ -176,3 +184,3 @@ let str = "";

if (fieldType === "IntegerId" || fieldType === "UInt32") {
value = "" + value + " 0x" + value.toString(16);
value = "" + value + " " + ((value !== undefined ) ? "0x"+value.toString(16) : "undefined");
} else if (fieldType === "DateTime" || fieldType === "UtcTime") {

@@ -190,3 +198,3 @@ value = (value && value.toISOString) ? value.toISOString() : value;

function _dump_complex_value(self: any, field: StructuredTypeField, data: any, value: any, fieldType: string) {
function _dump_complex_value(self: BaseUAObject, field: StructuredTypeField, data: any, value: any, fieldType: string) {
if (field.subType) {

@@ -199,3 +207,8 @@ // this is a synonymous

field.fieldTypeConstructor = field.fieldTypeConstructor || getStructureTypeConstructor(fieldType);
const typeDictionary = (self.schema as any).$typeDictionary as DataTypeFactory;
if (!typeDictionary) {
console.log(" No typeDictionary for ", self.schema);
}
field.fieldTypeConstructor = field.fieldTypeConstructor ||
(typeDictionary.getStructureTypeConstructor(fieldType));
const fieldTypeConstructor = field.fieldTypeConstructor;

@@ -202,0 +215,0 @@

/**
* @module node-opcua-factory
*/
import * as _ from "underscore";
import * as util from "util";
import { assert } from "node-opcua-assert";
import { decodeLocaleId, encodeLocaleId, validateLocaleId } from "node-opcua-basic-types";
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import * as _ from "underscore";
import * as util from "util";
import { findSimpleType, registerType } from "./factories_builtin_types";
import { findSimpleType, registerType, hasBuiltInType } from "./factories_builtin_types";
import { BasicTypeDefinition, BasicTypeDefinitionOptions } from "./types";

@@ -52,2 +54,8 @@

const exists: boolean = hasBuiltInType(schema.name);
if (exists) {
console.log(schema);
throw new Error(`Basic Type ${schema.name} already registered`);
}
const name = schema.name;

@@ -107,4 +115,4 @@

registerBasicType({name: "UtcTime", subType: "DateTime"});
registerBasicType({name: "Int8", subType: "SByte"});
registerBasicType({name: "UInt8", subType: "Byte"});
// already ? registerBasicType({name: "Int8", subType: "SByte"});
// already ? registerBasicType({name: "UInt8", subType: "Byte"});
registerBasicType({name: "Char", subType: "Byte"});

@@ -127,6 +135,38 @@ // xx registerBasicType({name:"XmlElement" ,subType:"String" });

registerBasicType({name: "Image", subType: "ByteString"});
registerBasicType({name: "ImageBMP", subType: "ByteString"});
registerBasicType({name: "ImageJPG", subType: "ByteString"});
registerBasicType({name: "ImagePNG", subType: "ByteString"});
registerBasicType({name: "ImageGIF", subType: "ByteString"});
registerBasicType({name: "NodeIdType", subType: "NodeId"});
registerBasicType({ name: "ImageBMP", subType: "Image" });
registerBasicType({ name: "ImageGIF", subType: "Image" });
registerBasicType({ name: "ImageJPG", subType: "Image" });
registerBasicType({ name: "ImagePNG", subType: "Image" });
registerBasicType({ name: "AudioDataType", subType: "ByteString" });
registerBasicType({ name: "BitFieldMaskDataType", subType: "UInt64" });
registerBasicType({ name: "DataSetFieldFlags", subType: "UInt16" });
registerBasicType({ name: "DataSetFieldContentMask", subType: "UInt32" });
registerBasicType({ name: "UadpNetworkMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "UadpDataSetMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "JsonNetworkMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "JsonDataSetMessageContentMask", subType: "UInt32" });
registerBasicType({ name: "PermissionType", subType: "UInt32" });
registerBasicType({ name: "AccessLevelType", subType: "Byte" });
registerBasicType({ name: "AccessLevelExType", subType: "UInt32" });
registerBasicType({ name: "EventNotifierType", subType: "Byte" });
registerBasicType({ name: "AccessRestrictionType", subType: "UInt32" });
registerBasicType({ name: "NormalizedString", subType: "String" });
registerBasicType({ name: "DecimalString", subType: "String" });
registerBasicType({ name: "DurationString", subType: "String" });
registerBasicType({ name: "TimeString", subType: "String" });
registerBasicType({ name: "DateString", subType: "String" });
registerBasicType({ name: "Index", subType: "UInt32" });
registerBasicType({ name: "VersionTime", subType: "UInt32" });
registerBasicType({ name: "ApplicationInstanceCertificate", subType: "ByteString" });
registerBasicType({ name: "AttributeWriteMask", subType: "UInt32" });
registerBasicType({ name: "Date", subType: "DateTime" });
// registerBasicType({ name: "Counter", subType: "UInt32" });
// registerBasicType({ name: "IntegerId", subType: "UInt32" });
// registerBasicType({ name: "UtcTime", subType: "DateTime" });
// registerBasicType({ name: "Duration", subType: "Double" });
// registerBasicType({ name: "LocaleId", subType: "String" });
// registerBasicType({ name: "NumericRange", subType: "String" });
// registerBasicType({ name: "Time", subType: "String" });
// registerBasicType({ name: "SessionAuthenticationToken", subType: "NodeId" });
/**
* @module node-opcua-factory
*/
import * as _ from "underscore";
import { assert } from "node-opcua-assert";
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
import * as _ from "underscore";
import { registerType } from "./factories_builtin_types";
import { ConstructorFunc } from "./factories_factories";
import { ConstructorFunc } from "./constructor_type";

@@ -11,0 +12,0 @@ function _self_encode(constructor: any) {

@@ -314,3 +314,5 @@ /**

const typeSchema = _defaultTypeMap.get(name);
assert(typeSchema);
if(!typeSchema) {
throw new Error("Cannot find schema for simple type "+ name);
}
assert(typeSchema instanceof TypeSchemaBase);

@@ -317,0 +319,0 @@ return typeSchema as BasicTypeDefinition;

@@ -13,2 +13,10 @@ /**

import {
DataTypeFactory,
} from "./datatype_factory";
import {
ConstructorFuncWithSchema,
ConstructorFunc
} from "./constructor_type";
import { BaseUAObject } from "./factories_baseobject";

@@ -20,140 +28,37 @@ import { StructuredTypeSchema } from "./factories_structuredTypeSchema";

const constructorMap: any = {};
type BaseUAObjectConstructable = new(options?: any) => BaseUAObject;
export type ConstructorFunc = BaseUAObjectConstructable;
// new (...args: any[]) => BaseUAObjectConstructable;
export interface ConstructorFuncWithSchema extends ConstructorFunc {
schema: StructuredTypeSchema;
possibleFields: string[];
encodingDefaultBinary: ExpandedNodeId;
encodingDefaultXml: ExpandedNodeId;
let globalFactory: DataTypeFactory;
export function getStandartDataTypeFactory(): DataTypeFactory {
if (!globalFactory) {
globalFactory = new DataTypeFactory([]);
globalFactory.targetNamespace = "http://opcfoundation.org/UA/";
}
return globalFactory;
}
const _globalStructuredTypeConstructors: { [ key: string ]: ConstructorFuncWithSchema } = {};
export function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema {
return _globalStructuredTypeConstructors[typeName];
return getStandartDataTypeFactory().getStructureTypeConstructor(typeName);
}
export function hasStructuredType(typeName: string): boolean {
return !!_globalStructuredTypeConstructors[typeName];
return getStandartDataTypeFactory().hasStructuredType(typeName);
}
export function getStructuredTypeSchema(typeName: string): StructuredTypeSchema {
const struct = _globalStructuredTypeConstructors[typeName];
if (!struct) {
throw new Error("cannot find structured type for " + typeName);
}
return struct.schema;
return getStandartDataTypeFactory().getStructuredTypeSchema(typeName);
}
export function registerFactory(typeName: string, constructor: ConstructorFuncWithSchema): void {
/* istanbul ignore next */
if (getStructureTypeConstructor(typeName)) {
console.log(getStructureTypeConstructor(typeName));
throw new Error(" registerFactory : " + typeName + " already registered");
}
_globalStructuredTypeConstructors[typeName] = constructor;
export function registerFactory(typeName: string, constructor: ConstructorFuncWithSchema): void {
return getStandartDataTypeFactory().registerFactory(typeName, constructor);
}
/* istanbul ignore next */
export function dump(): void {
console.log(" dumping registered factories");
console.log(" Factory ", Object.keys(_globalStructuredTypeConstructors).sort().forEach((e) => e));
console.log(" done");
}
export function callConstructor(constructor: ConstructorFunc): BaseUAObject {
assert(_.isFunction(constructor));
const constructorFunc: any = constructor.bind.apply(constructor, arguments as any);
return new constructorFunc();
}
export function getConstructor(expandedNodeId: ExpandedNodeId): ConstructorFunc | null {
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
if (!(expandedNodeId && (expandedNodeIdKey in constructorMap))) {
debugLog(chalk.red("#getConstructor : cannot find constructor for expandedId "), expandedNodeId.toString());
return null;
}
return constructorMap[expandedNodeIdKey];
return getStandartDataTypeFactory().getConstructor(expandedNodeId);
}
export function hasConstructor(expandedNodeId: ExpandedNodeId): boolean {
if (!expandedNodeId) {
return false;
}
/* istanbul ignore next */
if (!verifyExpandedNodeId(expandedNodeId)) {
console.log("Invalid expandedNodeId");
return false;
}
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
return !!constructorMap[expandedNodeIdKey];
return getStandartDataTypeFactory().hasConstructor(expandedNodeId);
}
export function constructObject(expandedNodeId: ExpandedNodeId): BaseUAObject {
if (!verifyExpandedNodeId(expandedNodeId)) {
throw new Error(" constructObject : invalid expandedNodeId provided " + expandedNodeId.toString());
}
const constructor = getConstructor(expandedNodeId);
if (!constructor) {
debugLog("Cannot find constructor for " + expandedNodeId.toString());
return new BaseUAObject();
// throw new Error("Cannot find constructor for " + expandedNodeId.toString());
}
return callConstructor(constructor);
return getStandartDataTypeFactory().constructObject(expandedNodeId);
}
function verifyExpandedNodeId(expandedNodeId: ExpandedNodeId): boolean {
/* istanbul ignore next */
if (expandedNodeId.value instanceof Buffer) {
throw new Error("getConstructor not implemented for opaque nodeid");
}
if (expandedNodeId.namespace === 0) {
if (expandedNodeId.namespaceUri === "http://opcfoundation.org/UA/" || !expandedNodeId.namespaceUri ) {
return true;
}
// When namespace is ZERO, namepaceUri must be "http://opcfoundation.org/UA/" or nothing
return false;
} else {
// expandedNodeId.namespace !==0
// in this case a valid expandedNodeId.namespaceUri must be provided
return !!expandedNodeId.namespaceUri && expandedNodeId.namespaceUri.length > 2;
}
}
function makeExpandedNodeIdKey(expandedNodeId: ExpandedNodeId): string {
if (expandedNodeId.namespace === 0) {
return expandedNodeId.value.toString();
}
return expandedNodeId.namespaceUri + "@" + expandedNodeId.value.toString();
}
export function registerClassDefinition(className: string, classConstructor: ConstructorFuncWithSchema): void {
registerFactory(className, classConstructor);
const expandedNodeId = classConstructor.encodingDefaultBinary;
if (doDebug) {
debugLog(" registering ", className, expandedNodeId.toString());
}
/* istanbul ignore next */
if (!verifyExpandedNodeId(expandedNodeId)) {
throw new Error("Invalid expandedNodeId");
}
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId);
/* istanbul ignore next */
if (expandedNodeIdKey in constructorMap) {
throw new Error(" Class " + className + " with ID " + expandedNodeId +
" already in constructorMap for " + constructorMap[expandedNodeIdKey].name);
}
constructorMap[expandedNodeIdKey] = classConstructor;
return getStandartDataTypeFactory().registerClassDefinition(className,classConstructor);
}
/* istanbul ignore next */
export function dump(): void {
getStandartDataTypeFactory().dump();
}

@@ -25,20 +25,3 @@ /**

import { parameters } from "./factories_schema_helpers";
// export interface StructuredTypeSchemaInterface extends CommonInterface {
//
// fields: FieldType[];
//
// baseType?: string;
// documentation?: string;
//
// id: number | NodeId;
//
// // caches
// _possibleFields?: any[];
// _baseSchema?: StructuredTypeSchemaInterface;
// _resolved?: boolean;
//
// isValid?: (options: any) => boolean;
// decodeDebug?: (stream: BinaryStream, options: any) => any;
// constructHook?: (options: any) => any;
// }
function figureOutFieldCategory(field: FieldInterfaceOptions): FieldCategory {

@@ -181,2 +164,5 @@ const fieldType = field.fieldType;

}
if (schema.baseType === "Union") {
return null;
}

@@ -278,3 +264,7 @@ if (schema.baseType && schema.baseType !== "BaseUAObject") {

}
/* istanbul ignore next */
if (invalidOptionsFields.length !== 0) {
// tslint:disable:no-console
console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" "));
console.log(chalk.red("current fields= "), currentFields.sort().join(" "));
throw new Error(" invalid field found in option :" + JSON.stringify(invalidOptionsFields));

@@ -281,0 +271,0 @@ }

/**
* @module node-opcua-factory
*/
export * from "./constructor_type";
export * from "./datatype_factory";
export * from "./factories_id_generator";

@@ -5,0 +7,0 @@ export * from "./factories_enumerations";

@@ -9,3 +9,3 @@ /**

import * as _ from "underscore";
import { ConstructorFunc } from "./factories_factories";
import { ConstructorFunc } from "./constructor_type";
import { FieldInterfaceOptions } from "./types";

@@ -12,0 +12,0 @@

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

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