node-opcua-factory
Advanced tools
Comparing version 2.6.1 to 2.6.5
@@ -16,4 +16,5 @@ import { ExpandedNodeId, NodeId } from "node-opcua-nodeid"; | ||
private _simpleTypes; | ||
private readonly baseDataFactories; | ||
private baseDataFactories; | ||
constructor(baseDataFactories: DataTypeFactory[]); | ||
repairBaseDataFactories(baseDataFactories: DataTypeFactory[]): void; | ||
registerSimpleType(name: string, dataTypeNodeId: NodeId, def: BasicTypeDefinition): void; | ||
@@ -20,0 +21,0 @@ hasSimpleType(name: string): boolean; |
@@ -30,2 +30,5 @@ "use strict"; | ||
} | ||
repairBaseDataFactories(baseDataFactories) { | ||
this.baseDataFactories = baseDataFactories; | ||
} | ||
// ----------------------------- | ||
@@ -67,2 +70,3 @@ registerSimpleType(name, dataTypeNodeId, def) { | ||
registerEnumeration(enumeration) { | ||
debugLog("Registering Enumeration ", enumeration.name); | ||
node_opcua_assert_1.assert(!this._enumerations[enumeration.name]); | ||
@@ -91,4 +95,5 @@ this._enumerations[enumeration.name] = enumeration; | ||
for (const factory of this.baseDataFactories) { | ||
const e = factory.getEnumeration(enumName); | ||
if (e !== null) { | ||
const hasEnum = factory.hasEnumeration(enumName); | ||
if (hasEnum) { | ||
const e = factory.getEnumeration(enumName); | ||
return e; | ||
@@ -115,3 +120,3 @@ } | ||
// ---------------------------------------------------------------------------------------------------- | ||
// Acces by typeName | ||
// Access by typeName | ||
// ---------------------------------------------------------------------------------------------------- | ||
@@ -174,3 +179,3 @@ structuredTypesNames() { | ||
// ---------------------------------------------------------------------------------------------------- | ||
// Acces by binaryEncodingNodeId | ||
// Access by binaryEncodingNodeId | ||
// ---------------------------------------------------------------------------------------------------- | ||
@@ -259,3 +264,3 @@ getConstructor(binaryEncodingNodeId) { | ||
} | ||
debugLog("registerning typeName ", typeName, dataTypeNodeId.toString()); | ||
debugLog("registering typeName ", typeName, dataTypeNodeId.toString()); | ||
this._structureTypeConstructorByNameMap[typeName] = constructor; | ||
@@ -262,0 +267,0 @@ this._structureTypeConstructorByDataTypeMap[dataTypeNodeId.toString()] = constructor; |
@@ -9,3 +9,3 @@ /** | ||
import { StructuredTypeSchema } from "./factories_structuredTypeSchema"; | ||
export declare function getStandartDataTypeFactory(): DataTypeFactory; | ||
export declare function getStandardDataTypeFactory(): DataTypeFactory; | ||
export declare function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema; | ||
@@ -12,0 +12,0 @@ export declare function hasStructuredType(typeName: string): boolean; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dump = exports.registerClassDefinition = exports.constructObject = exports.hasConstructor = exports.getConstructor = exports.getStructuredTypeSchema = exports.hasStructuredType = exports.getStructureTypeConstructor = exports.getStandartDataTypeFactory = void 0; | ||
exports.dump = exports.registerClassDefinition = exports.constructObject = exports.hasConstructor = exports.getConstructor = exports.getStructuredTypeSchema = exports.hasStructuredType = exports.getStructureTypeConstructor = exports.getStandardDataTypeFactory = void 0; | ||
const node_opcua_debug_1 = require("node-opcua-debug"); | ||
@@ -14,3 +14,3 @@ const datatype_factory_1 = require("./datatype_factory"); | ||
let globalFactory; | ||
function getStandartDataTypeFactory() { | ||
function getStandardDataTypeFactory() { | ||
if (!globalFactory) { | ||
@@ -22,29 +22,29 @@ globalFactory = new datatype_factory_1.DataTypeFactory([]); | ||
} | ||
exports.getStandartDataTypeFactory = getStandartDataTypeFactory; | ||
exports.getStandardDataTypeFactory = getStandardDataTypeFactory; | ||
function getStructureTypeConstructor(typeName) { | ||
return getStandartDataTypeFactory().getStructureTypeConstructor(typeName); | ||
return getStandardDataTypeFactory().getStructureTypeConstructor(typeName); | ||
} | ||
exports.getStructureTypeConstructor = getStructureTypeConstructor; | ||
function hasStructuredType(typeName) { | ||
return getStandartDataTypeFactory().hasStructuredType(typeName); | ||
return getStandardDataTypeFactory().hasStructuredType(typeName); | ||
} | ||
exports.hasStructuredType = hasStructuredType; | ||
function getStructuredTypeSchema(typeName) { | ||
return getStandartDataTypeFactory().getStructuredTypeSchema(typeName); | ||
return getStandardDataTypeFactory().getStructuredTypeSchema(typeName); | ||
} | ||
exports.getStructuredTypeSchema = getStructuredTypeSchema; | ||
function getConstructor(binaryEncodingNodeId) { | ||
return getStandartDataTypeFactory().getConstructor(binaryEncodingNodeId); | ||
return getStandardDataTypeFactory().getConstructor(binaryEncodingNodeId); | ||
} | ||
exports.getConstructor = getConstructor; | ||
function hasConstructor(binaryEncodingNodeId) { | ||
return getStandartDataTypeFactory().hasConstructor(binaryEncodingNodeId); | ||
return getStandardDataTypeFactory().hasConstructor(binaryEncodingNodeId); | ||
} | ||
exports.hasConstructor = hasConstructor; | ||
function constructObject(binaryEncodingNodeId) { | ||
return getStandartDataTypeFactory().constructObject(binaryEncodingNodeId); | ||
return getStandardDataTypeFactory().constructObject(binaryEncodingNodeId); | ||
} | ||
exports.constructObject = constructObject; | ||
function registerClassDefinition(dataTypeNodeId, className, classConstructor) { | ||
return getStandartDataTypeFactory().registerClassDefinition(dataTypeNodeId, className, classConstructor); | ||
return getStandardDataTypeFactory().registerClassDefinition(dataTypeNodeId, className, classConstructor); | ||
} | ||
@@ -54,5 +54,5 @@ exports.registerClassDefinition = registerClassDefinition; | ||
function dump() { | ||
getStandartDataTypeFactory().dump(); | ||
getStandardDataTypeFactory().dump(); | ||
} | ||
exports.dump = dump; | ||
//# sourceMappingURL=factories_factories.js.map |
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"; | ||
export declare class StructuredTypeSchema extends TypeSchemaBase { | ||
@@ -44,2 +45,3 @@ fields: FieldType[]; | ||
export declare function check_options_correctness_against_schema(obj: any, schema: StructuredTypeSchema, options: any): boolean; | ||
export declare function buildStructuredType2(dataTypeFactory: DataTypeFactory, schemaLight: StructuredTypeOptions): StructuredTypeSchema; | ||
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; | ||
exports.buildStructuredType = exports.buildStructuredType2 = exports.check_options_correctness_against_schema = exports.extract_all_fields = exports.get_base_schema = exports.StructuredTypeSchema = void 0; | ||
/** | ||
@@ -34,2 +34,3 @@ * @module node-opcua-factory | ||
} | ||
const regExp = /((ns[0-9]+:)?)(.*)/; | ||
function figureOutSchema(underConstructSchema, field, category) { | ||
@@ -43,21 +44,29 @@ if (field.schema) { | ||
let returnValue = null; | ||
// may be the field.type contains a ns<X>: prefix !! like the one found in Beckhoff PLC ! | ||
const m = field.fieldType.match(regExp); | ||
/* istanbul ignore next */ | ||
if (!m) { | ||
throw new Error("malformed fieldType ? : " + field.fieldType); | ||
} | ||
const fieldTypeWithoutNS = m[3]; | ||
switch (category) { | ||
case types_1.FieldCategory.complex: | ||
if (factories_factories_1.hasStructuredType(field.fieldType)) { | ||
returnValue = factories_factories_1.getStructuredTypeSchema(field.fieldType); | ||
returnValue = factories_factories_1.getStructuredTypeSchema(fieldTypeWithoutNS); | ||
} | ||
else { | ||
// LocalizedText etc ... | ||
returnValue = factories_builtin_types_1.getBuildInType(field.fieldType); | ||
returnValue = factories_builtin_types_1.getBuildInType(fieldTypeWithoutNS); | ||
} | ||
break; | ||
case types_1.FieldCategory.basic: | ||
returnValue = factories_builtin_types_1.getBuildInType(field.fieldType); | ||
returnValue = factories_builtin_types_1.getBuildInType(fieldTypeWithoutNS); | ||
break; | ||
case types_1.FieldCategory.enumeration: | ||
returnValue = factories_enumerations_1.getEnumeration(field.fieldType); | ||
returnValue = factories_enumerations_1.getEnumeration(fieldTypeWithoutNS); | ||
break; | ||
} | ||
if (null === returnValue || undefined === returnValue) { | ||
throw new Error("Cannot find Schema for field with name " + field.name + | ||
returnValue = factories_enumerations_1.getEnumeration(fieldTypeWithoutNS); | ||
throw new Error("Cannot find Schema for field with name " + field.name + " fieldTypeWithoutNS= " + fieldTypeWithoutNS + | ||
" with type " + field.fieldType + " category = " + category + JSON.stringify(field, null, "\t")); | ||
@@ -233,2 +242,6 @@ } | ||
exports.check_options_correctness_against_schema = check_options_correctness_against_schema; | ||
function buildStructuredType2(dataTypeFactory, schemaLight) { | ||
return new StructuredTypeSchema(schemaLight); | ||
} | ||
exports.buildStructuredType2 = buildStructuredType2; | ||
function buildStructuredType(schemaLight) { | ||
@@ -235,0 +248,0 @@ return new StructuredTypeSchema(schemaLight); |
{ | ||
"name": "node-opcua-factory", | ||
"version": "2.6.1", | ||
"version": "2.6.5", | ||
"description": "pure nodejs OPCUA SDK - module -factory", | ||
@@ -41,3 +41,3 @@ "main": "./dist/index.js", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b" | ||
"gitHead": "e5e38142a719ebe22afb9617dce34b985d407d9b" | ||
} |
@@ -47,3 +47,3 @@ /** | ||
private readonly baseDataFactories: DataTypeFactory[]; | ||
private baseDataFactories: DataTypeFactory[]; | ||
@@ -56,2 +56,5 @@ public constructor(baseDataFactories: DataTypeFactory[]) { | ||
public repairBaseDataFactories(baseDataFactories: DataTypeFactory[]): void { | ||
this.baseDataFactories = baseDataFactories; | ||
} | ||
// ----------------------------- | ||
@@ -94,2 +97,3 @@ public registerSimpleType(name: string, dataTypeNodeId: NodeId, def: BasicTypeDefinition) { | ||
public registerEnumeration(enumeration: EnumerationDefinitionSchema): void { | ||
debugLog("Registering Enumeration ", enumeration.name); | ||
assert(!this._enumerations[enumeration.name]); | ||
@@ -118,4 +122,5 @@ this._enumerations[enumeration.name] = enumeration; | ||
for (const factory of this.baseDataFactories) { | ||
const e = factory.getEnumeration(enumName); | ||
if (e !== null) { | ||
const hasEnum = factory.hasEnumeration(enumName); | ||
if (hasEnum) { | ||
const e = factory.getEnumeration(enumName); | ||
return e; | ||
@@ -143,3 +148,3 @@ } | ||
// ---------------------------------------------------------------------------------------------------- | ||
// Acces by typeName | ||
// Access by typeName | ||
// ---------------------------------------------------------------------------------------------------- | ||
@@ -206,3 +211,3 @@ public structuredTypesNames(): string[] { | ||
// ---------------------------------------------------------------------------------------------------- | ||
// Acces by binaryEncodingNodeId | ||
// Access by binaryEncodingNodeId | ||
// ---------------------------------------------------------------------------------------------------- | ||
@@ -301,3 +306,3 @@ public getConstructor(binaryEncodingNodeId: NodeId): ConstructorFunc | null { | ||
} | ||
debugLog("registerning typeName ", typeName, dataTypeNodeId.toString()); | ||
debugLog("registering typeName ", typeName, dataTypeNodeId.toString()); | ||
this._structureTypeConstructorByNameMap[typeName] = constructor; | ||
@@ -304,0 +309,0 @@ this._structureTypeConstructorByDataTypeMap[dataTypeNodeId.toString()] = constructor; |
@@ -28,3 +28,3 @@ /** | ||
let globalFactory: DataTypeFactory; | ||
export function getStandartDataTypeFactory(): DataTypeFactory { | ||
export function getStandardDataTypeFactory(): DataTypeFactory { | ||
if (!globalFactory) { | ||
@@ -37,26 +37,26 @@ globalFactory = new DataTypeFactory([]); | ||
export function getStructureTypeConstructor(typeName: string): ConstructorFuncWithSchema { | ||
return getStandartDataTypeFactory().getStructureTypeConstructor(typeName); | ||
return getStandardDataTypeFactory().getStructureTypeConstructor(typeName); | ||
} | ||
export function hasStructuredType(typeName: string): boolean { | ||
return getStandartDataTypeFactory().hasStructuredType(typeName); | ||
return getStandardDataTypeFactory().hasStructuredType(typeName); | ||
} | ||
export function getStructuredTypeSchema(typeName: string): StructuredTypeSchema { | ||
return getStandartDataTypeFactory().getStructuredTypeSchema(typeName); | ||
return getStandardDataTypeFactory().getStructuredTypeSchema(typeName); | ||
} | ||
export function getConstructor(binaryEncodingNodeId: ExpandedNodeId): ConstructorFunc | null { | ||
return getStandartDataTypeFactory().getConstructor(binaryEncodingNodeId); | ||
return getStandardDataTypeFactory().getConstructor(binaryEncodingNodeId); | ||
} | ||
export function hasConstructor(binaryEncodingNodeId: ExpandedNodeId): boolean { | ||
return getStandartDataTypeFactory().hasConstructor(binaryEncodingNodeId); | ||
return getStandardDataTypeFactory().hasConstructor(binaryEncodingNodeId); | ||
} | ||
export function constructObject(binaryEncodingNodeId: ExpandedNodeId): BaseUAObject { | ||
return getStandartDataTypeFactory().constructObject(binaryEncodingNodeId); | ||
return getStandardDataTypeFactory().constructObject(binaryEncodingNodeId); | ||
} | ||
export function registerClassDefinition(dataTypeNodeId: NodeId, className: string, classConstructor: ConstructorFuncWithSchema): void { | ||
return getStandartDataTypeFactory().registerClassDefinition(dataTypeNodeId, className, classConstructor); | ||
return getStandardDataTypeFactory().registerClassDefinition(dataTypeNodeId, className, classConstructor); | ||
} | ||
/* istanbul ignore next */ | ||
export function dump(): void { | ||
getStandartDataTypeFactory().dump(); | ||
getStandardDataTypeFactory().dump(); | ||
} |
@@ -25,4 +25,7 @@ /** | ||
import { parameters } from "./factories_schema_helpers"; | ||
import { DataTypeFactory } from "./datatype_factory"; | ||
function figureOutFieldCategory(field: FieldInterfaceOptions): FieldCategory { | ||
function figureOutFieldCategory( | ||
field: FieldInterfaceOptions | ||
): FieldCategory { | ||
const fieldType = field.fieldType; | ||
@@ -45,4 +48,10 @@ | ||
function figureOutSchema(underConstructSchema: StructuredTypeSchema, field: FieldInterfaceOptions, category: FieldCategory): CommonInterface { | ||
const regExp = /((ns[0-9]+:)?)(.*)/; | ||
function figureOutSchema( | ||
underConstructSchema: StructuredTypeSchema, | ||
field: FieldInterfaceOptions, | ||
category: FieldCategory | ||
): CommonInterface { | ||
if (field.schema) { | ||
@@ -58,20 +67,29 @@ return field.schema; | ||
// may be the field.type contains a ns<X>: prefix !! like the one found in Beckhoff PLC ! | ||
const m = field.fieldType.match(regExp); | ||
/* istanbul ignore next */ | ||
if (!m) { | ||
throw new Error("malformed fieldType ? : " + field.fieldType); | ||
} | ||
const fieldTypeWithoutNS = m[3]; | ||
switch (category) { | ||
case FieldCategory.complex: | ||
if (hasStructuredType(field.fieldType)) { | ||
returnValue = getStructuredTypeSchema(field.fieldType); | ||
returnValue = getStructuredTypeSchema(fieldTypeWithoutNS); | ||
} else { | ||
// LocalizedText etc ... | ||
returnValue = getBuildInType(field.fieldType); | ||
returnValue = getBuildInType(fieldTypeWithoutNS); | ||
} | ||
break; | ||
case FieldCategory.basic: | ||
returnValue = getBuildInType(field.fieldType); | ||
returnValue = getBuildInType(fieldTypeWithoutNS); | ||
break; | ||
case FieldCategory.enumeration: | ||
returnValue = getEnumeration(field.fieldType); | ||
returnValue = getEnumeration(fieldTypeWithoutNS); | ||
break; | ||
} | ||
if (null === returnValue || undefined === returnValue) { | ||
throw new Error("Cannot find Schema for field with name " + field.name + | ||
returnValue = getEnumeration(fieldTypeWithoutNS); | ||
throw new Error("Cannot find Schema for field with name " + field.name + " fieldTypeWithoutNS= " + fieldTypeWithoutNS + | ||
" with type " + field.fieldType + " category = " + category + JSON.stringify(field, null, "\t")); | ||
@@ -300,4 +318,8 @@ } | ||
export function buildStructuredType2(dataTypeFactory: DataTypeFactory, schemaLight: StructuredTypeOptions): StructuredTypeSchema { | ||
return new StructuredTypeSchema(schemaLight); | ||
} | ||
export function buildStructuredType(schemaLight: StructuredTypeOptions): StructuredTypeSchema { | ||
return new StructuredTypeSchema(schemaLight); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
232888
4264