node-opcua-factory
Advanced tools
Comparing version 2.6.0-alpha.7 to 2.6.1
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
import { ExpandedNodeId } from "node-opcua-nodeid"; | ||
@@ -2,0 +5,0 @@ import { BaseUAObject } from "./factories_baseobject"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.callConstructor = exports.DataTypeFactory = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
// tslint:disable:no-console | ||
const chalk = require("chalk"); | ||
@@ -26,2 +30,3 @@ const _ = require("underscore"); | ||
} | ||
// ----------------------------- | ||
registerSimpleType(name, dataTypeNodeId, def) { | ||
@@ -59,2 +64,4 @@ if (this._simpleTypes[name]) { | ||
} | ||
// ----------------------------- | ||
// EnumerationDefinitionSchema | ||
registerEnumeration(enumeration) { | ||
@@ -92,2 +99,3 @@ node_opcua_assert_1.assert(!this._enumerations[enumeration.name]); | ||
} | ||
// ---------------------------- | ||
findConstructorForDataType(dataTypeNodeId) { | ||
@@ -106,2 +114,5 @@ const constructor = this._structureTypeConstructorByDataTypeMap[dataTypeNodeId.toString()]; | ||
} | ||
// ---------------------------------------------------------------------------------------------------- | ||
// Acces by typeName | ||
// ---------------------------------------------------------------------------------------------------- | ||
structuredTypesNames() { | ||
@@ -158,5 +169,9 @@ return Object.keys(this._structureTypeConstructorByNameMap); | ||
else { | ||
// for instance in DI FetchResultDataType should be abstract but is not | ||
debugLog("warning ", dataTypeNodeId.toString(), "name=", className, " do not have binary encoding"); | ||
} | ||
} | ||
// ---------------------------------------------------------------------------------------------------- | ||
// Acces by binaryEncodingNodeId | ||
// ---------------------------------------------------------------------------------------------------- | ||
getConstructor(binaryEncodingNodeId) { | ||
@@ -181,2 +196,3 @@ const expandedNodeIdKey = makeExpandedNodeIdKey(binaryEncodingNodeId); | ||
} | ||
/* istanbul ignore next */ | ||
if (!verifyExpandedNodeId(binaryEncodingNodeId)) { | ||
@@ -207,2 +223,3 @@ console.log("Invalid expandedNodeId"); | ||
return new factories_baseobject_1.BaseUAObject(); | ||
// throw new Error("Cannot find constructor for " + expandedNodeId.toString()); | ||
} | ||
@@ -216,2 +233,3 @@ return callConstructor(constructor); | ||
} | ||
/* istanbul ignore next */ | ||
if (!verifyExpandedNodeId(expandedNodeId)) { | ||
@@ -221,2 +239,3 @@ throw new Error("Invalid expandedNodeId " + expandedNodeId.toString() + " className = " + className); | ||
const expandedNodeIdKey = makeExpandedNodeIdKey(expandedNodeId); | ||
/* istanbul ignore next */ | ||
if (expandedNodeIdKey in this._structureTypeConstructorByEncodingNodeIdMap) { | ||
@@ -238,2 +257,3 @@ throw new Error(" Class " + className + " with ID " + expandedNodeId + | ||
node_opcua_assert_1.assert(dataTypeNodeId.value !== 0, "dataTypeNodeId cannot be null"); | ||
/* istanbul ignore next */ | ||
if (this.hasStructuredType(typeName)) { | ||
@@ -279,2 +299,4 @@ console.log(this.getStructureTypeConstructor(typeName)); | ||
console.log("schema", schema.encodingDefaultXml ? schema.encodingDefaultXml.toString() : " "); | ||
// return; | ||
// throw new Error("Not in Binary Encoding Map!!!!! " + schema.encodingDefaultBinary); | ||
} | ||
@@ -286,2 +308,3 @@ } | ||
function verifyExpandedNodeId(expandedNodeId) { | ||
/* istanbul ignore next */ | ||
if (expandedNodeId.value instanceof Buffer) { | ||
@@ -288,0 +311,0 @@ throw new Error("getConstructor not implemented for opaque nodeid"); |
@@ -10,9 +10,44 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
} | ||
/** | ||
* @class BaseUAObject | ||
* @constructor | ||
*/ | ||
export declare class BaseUAObject { | ||
constructor(); | ||
/** | ||
* Encode the object to the binary stream. | ||
* @class BaseUAObject | ||
* @method encode | ||
* @param stream {BinaryStream} | ||
*/ | ||
encode(stream: OutputBinaryStream): void; | ||
/** | ||
* Decode the object from the binary stream. | ||
* @class BaseUAObject | ||
* @method decode | ||
* @param stream {BinaryStream} | ||
*/ | ||
decode(stream: BinaryStream): void; | ||
/** | ||
* Calculate the required size to store this object in a binary stream. | ||
* @method binaryStoreSize | ||
* @return number | ||
*/ | ||
binaryStoreSize(): number; | ||
/** | ||
* @method toString | ||
* @return {String} | ||
*/ | ||
toString(...args: any[]): string; | ||
/** | ||
* | ||
* verify that all object attributes values are valid according to schema | ||
* @method isValid | ||
* @return boolean | ||
*/ | ||
isValid(): boolean; | ||
/** | ||
* @method decodeDebug | ||
* | ||
*/ | ||
decodeDebug(stream: BinaryStream, options: DecodeDebugOptions): void; | ||
@@ -19,0 +54,0 @@ explore(): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseUAObject = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
// tslint:disable:no-shadowed-variable | ||
const chalk = require("chalk"); | ||
@@ -46,2 +50,3 @@ const node_opcua_assert_1 = require("node-opcua-assert"); | ||
} | ||
// assert(_.isFunction(field.fieldTypeConstructor)); | ||
const constructor = field.fieldTypeConstructor; | ||
@@ -123,2 +128,3 @@ value = datatype_factory_1.callConstructor(constructor); | ||
let str; | ||
// decorate the field name with ?# if the field is optional | ||
let opt = " "; | ||
@@ -133,2 +139,3 @@ if (field.switchBit !== undefined) { | ||
const fieldTypeF = chalk.cyan(("/* " + r(fieldType + opt, 17) + (field.isArray ? "[]" : " ") + " */")); | ||
// detected when optional field is not specified in value | ||
if (field.switchBit !== undefined && value === undefined) { | ||
@@ -139,2 +146,3 @@ str = fieldNameF + " " + fieldTypeF + ": " + chalk.italic.grey("undefined") + " /* optional field not specified */"; | ||
} | ||
// detected when union field is not specified in value | ||
if (field.switchValue !== undefined && value === undefined) { | ||
@@ -145,2 +153,3 @@ str = fieldNameF + " " + fieldTypeF + ": " + chalk.italic.grey("undefined") + " /* union field not specified */"; | ||
} | ||
// compact version of very usual objects | ||
if (fieldType === "QualifiedName" && !field.isArray && value) { | ||
@@ -202,2 +211,3 @@ value = value.toString() || "<null>"; | ||
if (field.subType) { | ||
// this is a synonymous | ||
fieldType = field.subType; | ||
@@ -208,3 +218,5 @@ _dump_simple_value(self, field, data, value, fieldType); | ||
const typeDictionary = self.schema.$$factory; | ||
// istanbul ignore next | ||
if (!typeDictionary) { | ||
// tslint:disable-next-line: no-console | ||
console.log(" No typeDictionary for ", self.schema); | ||
@@ -255,3 +267,5 @@ } | ||
const s = field.schema; | ||
// istanbul ignore next | ||
if (!s.typedEnum) { | ||
// tslint:disable:no-console | ||
console.log("xxxx cannot find typeEnum", s); | ||
@@ -287,2 +301,3 @@ } | ||
function _JSONify(self, schema, pojo) { | ||
/* jshint validthis: true */ | ||
for (const field of schema.fields) { | ||
@@ -313,9 +328,30 @@ const f = self[field.name]; | ||
} | ||
/** | ||
* @class BaseUAObject | ||
* @constructor | ||
*/ | ||
class BaseUAObject { | ||
constructor() { | ||
} | ||
/** | ||
* Encode the object to the binary stream. | ||
* @class BaseUAObject | ||
* @method encode | ||
* @param stream {BinaryStream} | ||
*/ | ||
encode(stream) { | ||
} | ||
/** | ||
* Decode the object from the binary stream. | ||
* @class BaseUAObject | ||
* @method decode | ||
* @param stream {BinaryStream} | ||
*/ | ||
decode(stream) { | ||
} | ||
/** | ||
* Calculate the required size to store this object in a binary stream. | ||
* @method binaryStoreSize | ||
* @return number | ||
*/ | ||
binaryStoreSize() { | ||
@@ -326,2 +362,6 @@ const stream = new node_opcua_binary_stream_1.BinaryStreamSizeCalculator(); | ||
} | ||
/** | ||
* @method toString | ||
* @return {String} | ||
*/ | ||
toString(...args) { | ||
@@ -333,2 +373,3 @@ if (this.schema && this.schema.hasOwnProperty("toString")) { | ||
if (!this.explore) { | ||
// xx console.log(util.inspect(this)); | ||
return Object.prototype.toString.apply(this, arguments); | ||
@@ -339,2 +380,8 @@ } | ||
} | ||
/** | ||
* | ||
* verify that all object attributes values are valid according to schema | ||
* @method isValid | ||
* @return boolean | ||
*/ | ||
isValid() { | ||
@@ -349,2 +396,6 @@ node_opcua_assert_1.assert(this.schema); | ||
} | ||
/** | ||
* @method decodeDebug | ||
* | ||
*/ | ||
decodeDebug(stream, options) { | ||
@@ -405,3 +456,3 @@ const tracer = options.tracer; | ||
} | ||
clone() { | ||
clone( /*options,optionalFilter,extraInfo*/) { | ||
const self = this; | ||
@@ -430,2 +481,3 @@ const params = {}; | ||
node_opcua_assert_1.assert(_.isFunction(func)); | ||
// apply also construct to baseType schema first | ||
const baseSchema = factories_structuredTypeSchema_1.get_base_schema(schema); | ||
@@ -432,0 +484,0 @@ if (baseSchema) { |
@@ -13,2 +13,29 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
} | ||
/** | ||
* register a Basic Type , | ||
* A basic type is new entity type that resolved to a SubType | ||
* @example: | ||
* | ||
* | ||
* registerBasicType({name:"Duration" ,subType:"Double"}); | ||
* | ||
* @method registerBasicType | ||
* @param schema | ||
* @param schema.name {String} | ||
* @param schema.subType {String} mandatory, the basic type from which the new type derives. | ||
* | ||
* @param [schema.encode] {Function} optional,a specific encoder function to encode an instance of this type. | ||
* @param schema.encode.value {*} | ||
* @param schema.encode.stream {BinaryStream} | ||
* | ||
* @param [schema.decode] optional,a specific decoder function that returns the decode value out of the stream. | ||
* @param [schema.decode.stream] {BinaryStream} | ||
* | ||
* @param [schema.coerce] optional, a method to convert a value into the request type. | ||
* @param schema.coerce.value {*} the value to coerce. | ||
* | ||
* @param [schema.random] optional, a method to construct a random object of this type | ||
* | ||
* @param [schema.toJSON]optional, a method to convert a value into the request type. | ||
*/ | ||
export declare function registerBasicType(schema: BasicTypeOptions): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.registerBasicType = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const _ = require("underscore"); | ||
@@ -9,5 +12,34 @@ const util = require("util"); | ||
const factories_builtin_types_1 = require("./factories_builtin_types"); | ||
/** | ||
* register a Basic Type , | ||
* A basic type is new entity type that resolved to a SubType | ||
* @example: | ||
* | ||
* | ||
* registerBasicType({name:"Duration" ,subType:"Double"}); | ||
* | ||
* @method registerBasicType | ||
* @param schema | ||
* @param schema.name {String} | ||
* @param schema.subType {String} mandatory, the basic type from which the new type derives. | ||
* | ||
* @param [schema.encode] {Function} optional,a specific encoder function to encode an instance of this type. | ||
* @param schema.encode.value {*} | ||
* @param schema.encode.stream {BinaryStream} | ||
* | ||
* @param [schema.decode] optional,a specific decoder function that returns the decode value out of the stream. | ||
* @param [schema.decode.stream] {BinaryStream} | ||
* | ||
* @param [schema.coerce] optional, a method to convert a value into the request type. | ||
* @param schema.coerce.value {*} the value to coerce. | ||
* | ||
* @param [schema.random] optional, a method to construct a random object of this type | ||
* | ||
* @param [schema.toJSON]optional, a method to convert a value into the request type. | ||
*/ | ||
function registerBasicType(schema) { | ||
const exists = factories_builtin_types_1.hasBuiltInType(schema.name); | ||
/* istanbul ignore next */ | ||
if (exists) { | ||
// tslint:disable-next-line: no-console | ||
console.log("registerBasicType:", schema); | ||
@@ -18,3 +50,5 @@ throw new Error(`Basic Type ${schema.name} already registered`); | ||
const t = factories_builtin_types_1.findSimpleType(schema.subType); | ||
/* istanbul ignore next */ | ||
if (!t) { | ||
// tslint:disable-next-line:no-console | ||
console.log(util.inspect(schema, { colors: true })); | ||
@@ -29,2 +63,3 @@ throw new Error(" cannot find subtype " + schema.subType); | ||
const defaultValue = (schema.defaultValue === undefined) ? t.defaultValue : schema.defaultValue; | ||
// assert(_.isFunction(defaultValue)); | ||
const coerceFunc = schema.coerce || t.coerce; | ||
@@ -46,3 +81,7 @@ const toJSONFunc = schema.toJSON || t.toJSON; | ||
exports.registerBasicType = registerBasicType; | ||
// ============================================================================================= | ||
// Registering the Basic Type already defined int the OPC-UA Specification | ||
// ============================================================================================= | ||
registerBasicType({ name: "Counter", subType: "UInt32" }); | ||
// OPC Unified Architecture, part 3.0 $8.13 page 65 | ||
registerBasicType({ name: "Duration", subType: "Double" }); | ||
@@ -52,4 +91,8 @@ registerBasicType({ name: "UAString", subType: "String" }); | ||
registerBasicType({ name: "UtcTime", subType: "DateTime" }); | ||
// already ? registerBasicType({name: "Int8", subType: "SByte"}); | ||
// already ? registerBasicType({name: "UInt8", subType: "Byte"}); | ||
registerBasicType({ name: "Char", subType: "Byte" }); | ||
// xx registerBasicType({name:"XmlElement" ,subType:"String" }); | ||
registerBasicType({ name: "Time", subType: "String" }); | ||
// string in the form "en-US" or "de-DE" or "fr" etc... | ||
registerBasicType({ | ||
@@ -93,2 +136,10 @@ name: "LocaleId", | ||
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 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.registerSpecialVariantEncoder = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const _ = require("underscore"); | ||
@@ -5,0 +8,0 @@ const node_opcua_assert_1 = require("node-opcua-assert"); |
@@ -10,9 +10,24 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
export declare const minDate: Date; | ||
/** | ||
* @method registerType | ||
* @param schema {TypeSchemaBase} | ||
*/ | ||
export declare function registerType(schema: BasicTypeDefinitionOptions): void; | ||
export declare const registerBuiltInType: typeof registerType; | ||
export declare function unregisterType(typeName: string): void; | ||
/** | ||
* @method findSimpleType | ||
* @param name | ||
* @return {TypeSchemaBase|null} | ||
*/ | ||
export declare function findSimpleType(name: string): BasicTypeDefinition; | ||
export declare function hasBuiltInType(name: string): boolean; | ||
export declare function getBuildInType(name: string): BasicTypeDefinition; | ||
/** | ||
* @method findBuiltInType | ||
* find the Builtin Type that this | ||
* @param dataTypeName | ||
* @return {*} | ||
*/ | ||
export declare function findBuiltInType(dataTypeName: string): BasicTypeDefinition; | ||
export declare function getTypeMap(): Map<string, BasicTypeSchema>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTypeMap = exports.findBuiltInType = exports.getBuildInType = exports.hasBuiltInType = exports.findSimpleType = exports.unregisterType = exports.registerBuiltInType = exports.registerType = exports.minDate = exports.BasicTypeSchema = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -11,2 +14,4 @@ const node_opcua_basic_types_1 = require("node-opcua-basic-types"); | ||
const types_1 = require("./types"); | ||
// tslint:disable:no-empty | ||
// tslint:enable:no-unused-variable | ||
function defaultEncode(value, stream) { | ||
@@ -48,4 +53,11 @@ } | ||
} | ||
// there are 4 types of DataTypes in opcua: | ||
// Built-In DataType | ||
// Simple DataType | ||
// Complex DataType | ||
// Enumeration | ||
const defaultXmlElement = ""; | ||
// Built-In Type | ||
const _defaultType = [ | ||
// Built-in DataTypes ( see OPCUA Part III v1.02 - $5.8.2 ) | ||
{ | ||
@@ -111,2 +123,3 @@ name: "Null", | ||
}, | ||
// OPC Unified Architecture, part 3.0 $8.26 page 67 | ||
{ | ||
@@ -139,2 +152,3 @@ name: "DateTime", | ||
}, | ||
// see OPCUA Part 3 - V1.02 $8.2.1 | ||
{ | ||
@@ -154,2 +168,16 @@ name: "NodeId", | ||
}, | ||
// ---------------------------------------------------------------------------------------- | ||
// Simple DataTypes | ||
// ( see OPCUA Part III v1.02 - $5.8.2 ) | ||
// Simple DataTypes are subtypes of the Built-in DataTypes. They are handled on the wire like the | ||
// Built-in DataType, i.e. they cannot be distinguished on the wire from their Built-in supertypes. | ||
// Since they are handled like Built-in DataTypes regarding the encoding they cannot have encodings | ||
// defined in the AddressSpace. Clients can read the DataType Attribute of a Variable or VariableType to | ||
// identify the Simple DataType of the Value Attribute. An example of a Simple DataType is Duration. It | ||
// is handled on the wire as a Double but the Client can read the DataType Attribute and thus interpret | ||
// the value as defined by Duration | ||
// | ||
// OPC Unified Architecture, part 4.0 $7.13 | ||
// IntegerID: This primitive data type is an UInt32 that is used as an identifier, such as a handle. All values, | ||
// except for 0, are valid. | ||
{ | ||
@@ -161,2 +189,6 @@ name: "IntegerId", | ||
}, | ||
// The StatusCode is a 32-bit unsigned integer. The top 16 bits represent the numeric value of the | ||
// code that shall be used for detecting specific errors or conditions. The bottom 16 bits are bit flags | ||
// that contain additional information but do not affect the meaning of the StatusCode. | ||
// 7.33 Part 4 - P 143 | ||
{ | ||
@@ -170,2 +202,6 @@ name: "StatusCode", | ||
]; | ||
/** | ||
* @method registerType | ||
* @param schema {TypeSchemaBase} | ||
*/ | ||
function registerType(schema) { | ||
@@ -189,2 +225,7 @@ node_opcua_assert_1.assert(typeof schema.name === "string"); | ||
exports.unregisterType = unregisterType; | ||
/** | ||
* @method findSimpleType | ||
* @param name | ||
* @return {TypeSchemaBase|null} | ||
*/ | ||
function findSimpleType(name) { | ||
@@ -199,2 +240,3 @@ const typeSchema = _defaultTypeMap.get(name); | ||
exports.findSimpleType = findSimpleType; | ||
// populate the default type map | ||
const _defaultTypeMap = new Map(); | ||
@@ -210,2 +252,8 @@ _defaultType.forEach(registerType); | ||
exports.getBuildInType = getBuildInType; | ||
/** | ||
* @method findBuiltInType | ||
* find the Builtin Type that this | ||
* @param dataTypeName | ||
* @return {*} | ||
*/ | ||
function findBuiltInType(dataTypeName) { | ||
@@ -217,3 +265,3 @@ node_opcua_assert_1.assert(typeof dataTypeName === "string", "findBuiltInType : expecting a string " + dataTypeName); | ||
} | ||
if (t.subType && t.subType !== t.name) { | ||
if (t.subType && t.subType !== t.name /* avoid infinite recursion */) { | ||
return findBuiltInType(t.subType); | ||
@@ -220,0 +268,0 @@ } |
@@ -16,4 +16,15 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
} | ||
/** | ||
* @method registerEnumeration | ||
* @param options | ||
* @param options.name {string} | ||
* @param options.enumValues [{key:Name, value:values}] | ||
* @param options.encode | ||
* @param options.decode | ||
* @param options.typedEnum | ||
* @param options.defaultValue | ||
* @return {Enum} | ||
*/ | ||
export declare function registerEnumeration(options: EnumerationDefinitionOptions): Enum; | ||
export declare function hasEnumeration(enumerationName: string): boolean; | ||
export declare function getEnumeration(enumerationName: string): EnumerationDefinitionSchema; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEnumeration = exports.hasEnumeration = exports.registerEnumeration = exports.EnumerationDefinitionSchema = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -16,2 +19,3 @@ const _ = require("underscore"); | ||
const e = typedEnum.get(value); | ||
// istanbul ignore next | ||
if (!e) { | ||
@@ -23,4 +27,7 @@ throw new Error("cannot coerce value=" + value + " to " + typedEnum.constructor.name); | ||
class EnumerationDefinitionSchema extends types_1.TypeSchemaBase { | ||
// xx encode: (value: EnumItem, stream: OutputBinaryStream) => void; | ||
// xx decode: (stream: BinaryStream) => EnumItem; | ||
constructor(options) { | ||
super(options); | ||
// create a new Enum | ||
const typedEnum = new node_opcua_enum_1.Enum(options.enumValues); | ||
@@ -38,2 +45,13 @@ options.typedEnum = typedEnum; | ||
const _enumerations = new Map(); | ||
/** | ||
* @method registerEnumeration | ||
* @param options | ||
* @param options.name {string} | ||
* @param options.enumValues [{key:Name, value:values}] | ||
* @param options.encode | ||
* @param options.decode | ||
* @param options.typedEnum | ||
* @param options.defaultValue | ||
* @return {Enum} | ||
*/ | ||
function registerEnumeration(options) { | ||
@@ -40,0 +58,0 @@ node_opcua_assert_1.assert(options.hasOwnProperty("name")); |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
import { ExpandedNodeId, NodeId } from "node-opcua-nodeid"; | ||
@@ -2,0 +5,0 @@ import { DataTypeFactory } from "./datatype_factory"; |
"use strict"; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
// tslint:disable:no-console | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -45,2 +49,3 @@ exports.dump = exports.registerClassDefinition = exports.constructObject = exports.hasConstructor = exports.getConstructor = exports.getStructuredTypeSchema = exports.hasStructuredType = exports.getStructureTypeConstructor = exports.getStandartDataTypeFactory = void 0; | ||
exports.registerClassDefinition = registerClassDefinition; | ||
/* istanbul ignore next */ | ||
function dump() { | ||
@@ -47,0 +52,0 @@ getStandartDataTypeFactory().dump(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.is_internal_id = exports.next_available_id = exports.generate_new_id = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const _FIRST_INTERNAL_ID = 0xFFFE0000; | ||
@@ -5,0 +8,0 @@ let _nextAvailableId = _FIRST_INTERNAL_ID; |
@@ -5,4 +5,23 @@ import { FieldType, StructuredTypeField } from "./types"; | ||
}; | ||
/** | ||
* ensure correctness of a schema object. | ||
* | ||
* @method check_schema_correctness | ||
* @param schema | ||
* | ||
*/ | ||
export declare function check_schema_correctness(schema: any): void; | ||
/** | ||
* @method initialize_field | ||
* @param field | ||
* @param value | ||
* @return {*} | ||
*/ | ||
export declare function initialize_field(field: StructuredTypeField, value: any): any; | ||
/** | ||
* @method initialize_field_array | ||
* @param field | ||
* @param valueArray | ||
* @return | ||
*/ | ||
export declare function initialize_field_array(field: FieldType, valueArray: any): any[] | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initialize_field_array = exports.initialize_field = exports.check_schema_correctness = exports.parameters = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -12,2 +15,9 @@ const node_opcua_debug_1 = require("node-opcua-debug"); | ||
}; | ||
/** | ||
* ensure correctness of a schema object. | ||
* | ||
* @method check_schema_correctness | ||
* @param schema | ||
* | ||
*/ | ||
function check_schema_correctness(schema) { | ||
@@ -19,2 +29,8 @@ node_opcua_assert_1.assert(typeof schema.name === "string", " expecting schema to have a name"); | ||
exports.check_schema_correctness = check_schema_correctness; | ||
/** | ||
* @method initialize_field | ||
* @param field | ||
* @param value | ||
* @return {*} | ||
*/ | ||
function initialize_field(field, value) { | ||
@@ -45,2 +61,8 @@ const _t = field.schema; | ||
exports.initialize_field = initialize_field; | ||
/** | ||
* @method initialize_field_array | ||
* @param field | ||
* @param valueArray | ||
* @return | ||
*/ | ||
function initialize_field_array(field, valueArray) { | ||
@@ -47,0 +69,0 @@ const _t = field.schema; |
@@ -22,5 +22,24 @@ import { FieldType, StructuredTypeOptions, TypeSchemaBase } from "./types"; | ||
} | ||
/** | ||
* | ||
* @method get_base_schema | ||
* @param schema | ||
* @return {*} | ||
* | ||
*/ | ||
export declare function get_base_schema(schema: StructuredTypeSchema): StructuredTypeSchema | null; | ||
/** | ||
* extract a list of all possible fields for a schema | ||
* (by walking up the inheritance chain) | ||
* @method extract_all_fields | ||
* | ||
*/ | ||
export declare function extract_all_fields(schema: StructuredTypeSchema): string[]; | ||
/** | ||
* check correctness of option fields against scheme | ||
* | ||
* @method check_options_correctness_against_schema | ||
* | ||
*/ | ||
export declare function check_options_correctness_against_schema(obj: any, schema: StructuredTypeSchema, options: any): boolean; | ||
export declare function buildStructuredType(schemaLight: StructuredTypeOptions): StructuredTypeSchema; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildStructuredType = exports.check_options_correctness_against_schema = exports.extract_all_fields = exports.get_base_schema = exports.StructuredTypeSchema = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const chalk = require("chalk"); | ||
@@ -26,3 +29,3 @@ const _ = require("underscore"); | ||
else if (factories_factories_1.hasStructuredType(fieldType)) { | ||
node_opcua_assert_1.assert(fieldType !== "LocalizedText"); | ||
node_opcua_assert_1.assert(fieldType !== "LocalizedText"); // LocalizedText should be treated as BasicType!!! | ||
return types_1.FieldCategory.complex; | ||
@@ -46,2 +49,3 @@ } | ||
else { | ||
// LocalizedText etc ... | ||
returnValue = factories_builtin_types_1.getBuildInType(field.fieldType); | ||
@@ -66,2 +70,3 @@ } | ||
const schema = figureOutSchema(underConstructSchema, fieldLight, category); | ||
/* istanbul ignore next */ | ||
if (!schema) { | ||
@@ -119,2 +124,9 @@ throw new Error("expecting a valid schema for field with name " + | ||
exports.StructuredTypeSchema = StructuredTypeSchema; | ||
/** | ||
* | ||
* @method get_base_schema | ||
* @param schema | ||
* @return {*} | ||
* | ||
*/ | ||
function get_base_schema(schema) { | ||
@@ -133,2 +145,3 @@ let baseSchema = schema._baseSchema; | ||
const baseType = factories_factories_1.getStructureTypeConstructor(schema.baseType); | ||
// istanbul ignore next | ||
if (!baseType) { | ||
@@ -141,2 +154,3 @@ throw new Error(" cannot find factory for " + schema.baseType); | ||
} | ||
// put in cache for speedup | ||
schema._baseSchema = baseSchema; | ||
@@ -146,8 +160,18 @@ return baseSchema; | ||
exports.get_base_schema = get_base_schema; | ||
/** | ||
* extract a list of all possible fields for a schema | ||
* (by walking up the inheritance chain) | ||
* @method extract_all_fields | ||
* | ||
*/ | ||
function extract_all_fields(schema) { | ||
// returns cached result if any | ||
// istanbul ignore next | ||
if (schema._possibleFields) { | ||
return schema._possibleFields; | ||
} | ||
// extract the possible fields from the schema. | ||
let possibleFields = schema.fields.map((field) => field.name); | ||
const baseSchema = get_base_schema(schema); | ||
// istanbul ignore next | ||
if (baseSchema) { | ||
@@ -157,2 +181,3 @@ const fields = extract_all_fields(baseSchema); | ||
} | ||
// put in cache to speed up | ||
schema._possibleFields = possibleFields; | ||
@@ -162,7 +187,14 @@ return possibleFields; | ||
exports.extract_all_fields = extract_all_fields; | ||
/** | ||
* check correctness of option fields against scheme | ||
* | ||
* @method check_options_correctness_against_schema | ||
* | ||
*/ | ||
function check_options_correctness_against_schema(obj, schema, options) { | ||
if (!factories_schema_helpers_1.parameters.debugSchemaHelper) { | ||
return true; | ||
return true; // ignoring set | ||
} | ||
options = options || {}; | ||
// istanbul ignore next | ||
if (!_.isObject(options) && !(typeof (options) === "object")) { | ||
@@ -175,11 +207,19 @@ let message = chalk.red(" Invalid options specified while trying to construct a ") | ||
message += chalk.red(" and got a ") + chalk.yellow((typeof options)) + chalk.red(" instead "); | ||
// console.log(" Schema = ", schema); | ||
// console.log(" options = ", options); | ||
throw new Error(message); | ||
} | ||
// istanbul ignore next | ||
if (options instanceof obj.constructor) { | ||
return true; | ||
} | ||
// extract the possible fields from the schema. | ||
const possibleFields = obj.constructor.possibleFields || schema._possibleFields; | ||
// extracts the fields exposed by the option object | ||
const currentFields = Object.keys(options); | ||
// get a list of field that are in the 'options' object but not in schema | ||
const invalidOptionsFields = _.difference(currentFields, possibleFields); | ||
/* istanbul ignore next */ | ||
if (invalidOptionsFields.length > 0) { | ||
// tslint:disable:no-console | ||
console.log("expected schema", schema.name); | ||
@@ -191,3 +231,5 @@ console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" ")); | ||
} | ||
/* istanbul ignore next */ | ||
if (invalidOptionsFields.length !== 0) { | ||
// tslint:disable:no-console | ||
console.log(chalk.yellow("possible fields= "), possibleFields.sort().join(" ")); | ||
@@ -194,0 +236,0 @@ console.log(chalk.red("current fields= "), currentFields.sort().join(" ")); |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
export * from "./constructor_type"; | ||
@@ -2,0 +5,0 @@ export * from "./datatype_factory"; |
@@ -13,2 +13,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
__exportStar(require("./constructor_type"), exports); | ||
@@ -15,0 +18,0 @@ __exportStar(require("./datatype_factory"), exports); |
@@ -91,2 +91,8 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream"; | ||
export declare type TypeDefinition = BuiltInTypeDefinition | EnumerationDefinition | BasicTypeDefinition | TypeSchemaBase; | ||
/** | ||
* @class TypeSchemaBase | ||
* @param options {Object} | ||
* @constructor | ||
* create a new type Schema | ||
*/ | ||
export declare class TypeSchemaBase implements CommonInterface { | ||
@@ -101,4 +107,15 @@ name: string; | ||
constructor(options: TypeSchemaConstructorOptions); | ||
/** | ||
* @method computer_default_value | ||
* @param defaultValue {*} the default value | ||
* @return {*} | ||
*/ | ||
computer_default_value(defaultValue: any): any; | ||
/** | ||
* @method initialize_value | ||
* @param value | ||
* @param defaultValue | ||
* @return {*} | ||
*/ | ||
initialize_value(value: any, defaultValue: any): any; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TypeSchemaBase = exports.FieldCategory = void 0; | ||
/** | ||
* @module node-opcua-factory | ||
*/ | ||
const node_opcua_assert_1 = require("node-opcua-assert"); | ||
@@ -12,6 +15,14 @@ const _ = require("underscore"); | ||
})(FieldCategory = exports.FieldCategory || (exports.FieldCategory = {})); | ||
// tslint:disable-next-line:no-empty | ||
function defaultEncode(value, stream) { | ||
} | ||
// tslint:disable-next-line:no-empty | ||
function defaultDecode(stream) { | ||
} | ||
/** | ||
* @class TypeSchemaBase | ||
* @param options {Object} | ||
* @constructor | ||
* create a new type Schema | ||
*/ | ||
class TypeSchemaBase { | ||
@@ -31,2 +42,7 @@ constructor(options) { | ||
} | ||
/** | ||
* @method computer_default_value | ||
* @param defaultValue {*} the default value | ||
* @return {*} | ||
*/ | ||
computer_default_value(defaultValue) { | ||
@@ -37,2 +53,4 @@ if (defaultValue === undefined) { | ||
if (_.isFunction(defaultValue)) { | ||
// be careful not to cache this value , it must be call each time to make sure | ||
// we do not end up with the same value/instance twice. | ||
defaultValue = defaultValue(); | ||
@@ -42,2 +60,8 @@ } | ||
} | ||
/** | ||
* @method initialize_value | ||
* @param value | ||
* @param defaultValue | ||
* @return {*} | ||
*/ | ||
initialize_value(value, defaultValue) { | ||
@@ -44,0 +68,0 @@ if (value === undefined) { |
{ | ||
"name": "node-opcua-factory", | ||
"version": "2.6.0-alpha.7", | ||
"version": "2.6.1", | ||
"description": "pure nodejs OPCUA SDK - module -factory", | ||
@@ -15,11 +15,11 @@ "main": "./dist/index.js", | ||
"chalk": "^4.0.0", | ||
"node-opcua-assert": "^2.6.0-alpha.1", | ||
"node-opcua-basic-types": "^2.6.0-alpha.1", | ||
"node-opcua-binary-stream": "^2.6.0-alpha.1", | ||
"node-opcua-debug": "^2.6.0-alpha.1", | ||
"node-opcua-enum": "^2.6.0-alpha.1", | ||
"node-opcua-guid": "^2.6.0-alpha.1", | ||
"node-opcua-nodeid": "^2.6.0-alpha.1", | ||
"node-opcua-status-code": "^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-binary-stream": "^2.6.1", | ||
"node-opcua-debug": "^2.6.1", | ||
"node-opcua-enum": "^2.6.1", | ||
"node-opcua-guid": "^2.6.1", | ||
"node-opcua-nodeid": "^2.6.1", | ||
"node-opcua-status-code": "^2.6.1", | ||
"node-opcua-utils": "^2.6.1", | ||
"underscore": "^1.10.2" | ||
@@ -42,3 +42,3 @@ }, | ||
"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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
230116
4219
1
Updatednode-opcua-assert@^2.6.1
Updatednode-opcua-debug@^2.6.1
Updatednode-opcua-enum@^2.6.1
Updatednode-opcua-guid@^2.6.1
Updatednode-opcua-nodeid@^2.6.1
Updatednode-opcua-utils@^2.6.1