node-opcua-client-dynamic-extension-object
Advanced tools
Comparing version 2.6.0-alpha.7 to 2.6.1
@@ -6,2 +6,8 @@ import { DataTypeFactory, FieldCategory, StructuredTypeSchema, TypeDefinition } from "node-opcua-factory"; | ||
import { ExtraDataTypeManager } from "./extra_data_type_manager"; | ||
/** | ||
* Extract all custom dataType | ||
* @param session | ||
* @param dataTypeManager | ||
* @async | ||
*/ | ||
export declare function populateDataTypeManager(session: IBasicSession, dataTypeManager: ExtraDataTypeManager): Promise<void>; | ||
@@ -8,0 +14,0 @@ export declare function getDataTypeDefinition(session: IBasicSession, dataTypeNodeId: NodeId, dataTypeManager: ExtraDataTypeManager): Promise<StructuredTypeSchema>; |
@@ -13,2 +13,6 @@ "use strict"; | ||
exports.convertDataTypeDefinitionToStructureTypeSchema = exports.getDataTypeDefinition = exports.populateDataTypeManager = void 0; | ||
// tslint:disable: no-console | ||
/** | ||
* @module node-opcua-client-dynamic-extension-object | ||
*/ | ||
const chalk = require("chalk"); | ||
@@ -34,2 +38,3 @@ const _ = require("underscore"); | ||
const a = yield session.translateBrowsePath(browsePath); | ||
/* istanbul ignore next */ | ||
if (!a.targets || a.targets.length === 0) { | ||
@@ -47,2 +52,3 @@ debugLog("Cannot find Deprecated property for dataTypeDictionary " + dataTypeDictionary.toString()); | ||
const a = yield session.translateBrowsePath(node_opcua_service_translate_browse_path_1.makeBrowsePath(dataTypeDictionary, ".NamespaceUri")); | ||
/* istanbul ignore next */ | ||
if (!a.targets || a.targets.length === 0) { | ||
@@ -64,2 +70,3 @@ return "??dataTypeDictionary doesn't expose NamespaceUri property??"; | ||
referenceTypeId: node_opcua_nodeid_1.resolveNodeId("HasComponent"), | ||
// resultMask: makeResultMask("NodeId | ReferenceType | BrowseName | NodeClass | TypeDefinition") | ||
resultMask: node_opcua_data_model_1.makeResultMask("NodeId | BrowseName") | ||
@@ -83,2 +90,3 @@ }; | ||
referenceTypeId: node_opcua_nodeid_1.resolveNodeId("HasDescription"), | ||
// resultMask: makeResultMask("NodeId | ReferenceType | BrowseName | NodeClass | TypeDefinition") | ||
resultMask: node_opcua_data_model_1.makeResultMask("NodeId") | ||
@@ -111,2 +119,3 @@ }); | ||
referenceTypeId: node_opcua_nodeid_1.resolveNodeId("HasEncoding"), | ||
// resultMask: makeResultMask("NodeId | ReferenceType | BrowseName | NodeClass | TypeDefinition") | ||
resultMask: node_opcua_data_model_1.makeResultMask("NodeId | BrowseName") | ||
@@ -121,2 +130,3 @@ }); | ||
result4.references = result4.references || []; | ||
/* istanbul ignore next */ | ||
if (result4.references.length !== 1) { | ||
@@ -148,2 +158,3 @@ console.log("What's going on ?", result4.toString()); | ||
if (references.length === 0) { | ||
//xx throw new Error("Cannot find encodings on type " + dataTypeNodeId.toString() + " statusCode " + result.statusCode.toString()); | ||
} | ||
@@ -210,2 +221,3 @@ const encodings = { | ||
const dataTypeNodeIds = yield _enrichWithDescriptionOf(session, dataTypeDescriptions); | ||
// now read DataTypeDefition attributes of all the dataTypeNodeIds, this will only contains concrete structure | ||
const nodesToRead = dataTypeNodeIds.map((nodeId) => ({ | ||
@@ -222,2 +234,3 @@ attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition, nodeId, | ||
const dataTypeDescription = dataTypeDescriptions[index]; | ||
/* istanbul ignore else */ | ||
if (dataValue.statusCode === node_opcua_status_code_1.StatusCodes.Good) { | ||
@@ -235,2 +248,3 @@ const dataTypeDefinition = dataValue.value.value; | ||
} | ||
// to do put in logicial order | ||
const dataTypeDefinitionsSorted = sortStructure(dataTypeDefinitions); | ||
@@ -241,2 +255,3 @@ if (doDebug) { | ||
for (const { className, dataTypeNodeId, dataTypeDefinition } of dataTypeDefinitionsSorted) { | ||
// istanbul ignore next | ||
if (doDebug) { | ||
@@ -246,6 +261,8 @@ console.log(chalk.yellow("--------------------------------------- "), className, dataTypeNodeId.toString()); | ||
if (dataTypeFactory.hasStructuredType(className)) { | ||
continue; | ||
continue; // this structure has already been seen | ||
} | ||
// now fill typeDictionary | ||
try { | ||
const schema = yield convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, className, dataTypeDefinition, dataTypeFactory, cache); | ||
// istanbul ignore next | ||
if (doDebug) { | ||
@@ -269,2 +286,3 @@ debugLog(chalk.red("Registering "), chalk.cyan(className.padEnd(30, " ")), schema.dataTypeNodeId.toString()); | ||
const dataTypeDescriptions = yield _getDataTypeDescriptions(session, dataTypeDictionaryNodeId); | ||
/* const dataTypeNodeIds = */ | ||
yield _enrichWithDescriptionOf(session, dataTypeDescriptions); | ||
@@ -290,2 +308,3 @@ for (const dataTypeDescription of dataTypeDescriptions) { | ||
debugLog("lets use the new way (1.04) and let's crawl all dataTypes exposed by this name space"); | ||
// dataType definition in store directily in UADataType under the $definition property | ||
const dataTypeFactory2 = dataTypeManager.getDataTypeFactory(dataTypeDictionaryNodeId.namespace); | ||
@@ -300,3 +319,6 @@ if (!dataTypeFactory2) { | ||
debugLog(" ----- Using old method for extracting schema => with BSD files"); | ||
// old method ( until 1.03 ) | ||
// one need to read the schema file store in the dataTypeDictionary node and parse it ! | ||
const rawSchema = rawSchemaDataValue.value.value.toString(); | ||
/* istanbul ignore next */ | ||
if (doDebug) { | ||
@@ -325,5 +347,7 @@ debugLog("---------------------------------------------"); | ||
const references = result.references || []; | ||
/* istanbul ignore next */ | ||
if (references.length === 0) { | ||
return; | ||
} | ||
// request the Definition of each nodes | ||
const nodesToBrowse2 = references.map((ref) => { | ||
@@ -342,2 +366,3 @@ return { | ||
const defaultBin = br.references.filter((r) => r.browseName.toString() === "Default Binary"); | ||
/* istanbul ignore next */ | ||
if (defaultBin.length < 1) { | ||
@@ -348,2 +373,4 @@ return node_opcua_nodeid_1.ExpandedNodeId; | ||
}); | ||
// follow now Default Binary <= [Has Encoding] = [DataType] | ||
/* istanbul ignore next */ | ||
if (doDebug) { | ||
@@ -357,4 +384,6 @@ console.log(chalk.bgWhite.red("testing new constructors")); | ||
} | ||
// let's verify that constructor is operational | ||
try { | ||
const constructor = dataTypeFactory.getStructureTypeConstructor(name); | ||
// xx const constructor = getOrCreateConstructor(name, dataTypeFactory, defaultBinary); | ||
const testObject = new constructor(); | ||
@@ -371,2 +400,8 @@ debugLog(testObject.toString()); | ||
} | ||
/** | ||
* Extract all custom dataType | ||
* @param session | ||
* @param dataTypeManager | ||
* @async | ||
*/ | ||
function populateDataTypeManager(session, dataTypeManager) { | ||
@@ -376,2 +411,3 @@ var _a; | ||
debugLog("in ... populateDataTypeManager"); | ||
// read namespace array | ||
const dataValueNamespaceArray = yield session.read({ | ||
@@ -392,2 +428,3 @@ attributeId: node_opcua_data_model_1.AttributeIds.Value, | ||
} | ||
/// to do :: may be not useful | ||
if (!dataValueNamespaceArray.value.value && dataTypeManager.namespaceArray.length === 0) { | ||
@@ -397,4 +434,8 @@ dataTypeManager.setNamespaceArray([]); | ||
const dataTypeDictionaryType = node_opcua_nodeid_1.resolveNodeId("DataTypeDictionaryType"); | ||
// DataType/OPCBinary => i=93 [OPCBinarySchema_TypeSystem] | ||
// "OPC Binary"[DataSystemType] | ||
const opcBinaryNodeId = node_opcua_nodeid_1.resolveNodeId("OPCBinarySchema_TypeSystem"); | ||
debugLog(opcBinaryNodeId.toString()); | ||
// let find all DataType dictionary node corresponding to a given namespace | ||
// (have DataTypeDictionaryType) | ||
const nodeToBrowse = { | ||
@@ -413,5 +454,9 @@ browseDirection: node_opcua_service_browse_1.BrowseDirection.Forward, | ||
} | ||
// filter nodes that have the expected namespace Index | ||
// ( more specifically we want to filter out DataStructure from namespace 0) | ||
// we also want to keep only object of type DataTypeDictionaryType | ||
const references = result.references.filter((e) => e.nodeId.namespace !== 0 && | ||
node_opcua_nodeid_1.sameNodeId(e.typeDefinition, dataTypeDictionaryType)); | ||
debugLog(`found ${references.length} dictionnary`); | ||
// now investigate DataTypeDescriptionType | ||
yield (() => __awaiter(this, void 0, void 0, function* () { | ||
@@ -421,3 +466,5 @@ function processReference2(ref) { | ||
const dataTypeDicitionaryNodeId = ref.nodeId; | ||
// xx const dataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(dataTypeDicitionaryNodeId.namespace); | ||
yield _extractDataTypeDictionary(session, dataTypeDicitionaryNodeId, dataTypeManager); | ||
/* istanbul ignore next */ | ||
if (doDebug) { | ||
@@ -452,5 +499,9 @@ debugLog(chalk.bgWhite(" => "), ref.browseName.toString(), ref.nodeId.toString()); | ||
if (result1.references && result1.references.length > 1) { | ||
// we have more than one possible Encoding .... only keep "Default Binary" | ||
result1.references = result1.references.filter((r) => r.browseName.toString() === "Default Binary"); | ||
} | ||
/* istanbul ignore next */ | ||
if (!(result1.references && result1.references.length === 1)) { | ||
// may be dataTypeNodeId is not a dataType, | ||
// let's verify this. | ||
const nodeClass = yield session.read({ | ||
@@ -464,2 +515,3 @@ attributeId: node_opcua_data_model_1.AttributeIds.NodeClass, | ||
}); | ||
// tslint:disable:no-console | ||
console.log("node-id :", dataTypeNodeId ? dataTypeNodeId.toString() : null); | ||
@@ -473,2 +525,3 @@ console.log("nodeClass :", node_opcua_data_model_1.NodeClass[nodeClass.value.value]); | ||
node_opcua_assert_1.assert(encodingReference.browseName.toString() === "Default Binary"); | ||
/* istanbul ignore next */ | ||
if (doDebug) { | ||
@@ -504,2 +557,9 @@ const browseName = yield session.read({ | ||
} | ||
/* | ||
const name = nameDataValue.value.value as string; | ||
if (!name) { | ||
console.log(nameDataValue.toString()); | ||
throw new Error("Cannot find ... " + name + " " + definitionRef.nodeId.toString()); | ||
} | ||
*/ | ||
return definitionRef.nodeId; | ||
@@ -510,2 +570,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// find parent node to access the xsd File | ||
const nodeToBrowse3 = { | ||
@@ -525,4 +586,24 @@ browseDirection: node_opcua_service_browse_1.BrowseDirection.Inverse, | ||
} | ||
function getDataTypeDefinition(session, dataTypeNodeId, dataTypeManager) { | ||
function getDataTypeDefinition(session, dataTypeNodeId, | ||
// tslint:disable-next-line: no-shadowed-variable | ||
dataTypeManager) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// DataType | ||
// | 1 | ||
// | n | ||
// +- HasEncoding-> "Default Binary" (O)[DataTypeEncodingType] | ||
// | | ||
// +-- HasDescription -> "MyItemType" (V)[DataTypeDescriptionType] | ||
// | | ||
// +- ComponentOf -> Schema(V) [] | ||
// | | ||
// +- ComponentOf -> OPC Binary(V)[DataTypeSystemType] | ||
// | ||
// Note that in 1.04 compliant server, DataType definition might be available | ||
// in a DataTypeDefinition attributes of the DataType object | ||
// However this is a brand new aspect of the specification and is not widely implemented | ||
// it is also optional | ||
// It will takes time for old opcua server to be refurbished and we may have to | ||
// keep the current method to access type definition from embedded xsd. | ||
// | ||
const defaultBinaryEncodingNodeId = yield getHasEncodingDefaultBinary(session, dataTypeNodeId); | ||
@@ -532,2 +613,3 @@ const definitionRefNodeId = yield getDefinition(session, defaultBinaryEncodingNodeId); | ||
const dataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(schemaNode.namespace); | ||
/* istanbul ignore next */ | ||
if (!dataTypeFactory) { | ||
@@ -553,2 +635,3 @@ throw new Error(" cannot find typeDictionary for " + schemaNode.toString()); | ||
const result3 = yield session.browse(nodeToBrowse3); | ||
/* istanbul ignore next */ | ||
if (result3.statusCode !== node_opcua_status_code_1.StatusCodes.Good) { | ||
@@ -558,2 +641,3 @@ throw new Error("Cannot find superType for " + dataTypeNodeId.toString()); | ||
result3.references = result3.references || []; | ||
/* istanbul ignore next */ | ||
if (result3.references.length !== 1) { | ||
@@ -576,7 +660,8 @@ console.log(result3.toString()); | ||
if (subTypeNodeId.namespace === 0 && subTypeNodeId.value <= 29) { | ||
// well knwow node ID ! | ||
switch (subTypeNodeId.value) { | ||
case 22: | ||
case 22: /* Structure */ | ||
category = node_opcua_factory_1.FieldCategory.complex; | ||
break; | ||
case 29: | ||
case 29: /* Enumeration */ | ||
category = node_opcua_factory_1.FieldCategory.enumeration; | ||
@@ -590,2 +675,3 @@ break; | ||
} | ||
// must drill down ... | ||
return yield findDataTypeCategory(session, cache, subTypeNodeId); | ||
@@ -604,4 +690,4 @@ }); | ||
switch (subTypeNodeId.value) { | ||
case 22: | ||
case 29: | ||
case 22: /* Structure */ | ||
case 29: /* Enumeration */ | ||
throw new Error("Not expecting Structure or Enumeration"); | ||
@@ -615,2 +701,3 @@ default: | ||
} | ||
// must drill down ... | ||
return yield findDataTypeBasicType(session, cache, subTypeNodeId); | ||
@@ -633,2 +720,5 @@ }); | ||
if ((dataTypeNodeId.namespace === 0 && dataTypeNodeId.value === 22)) { | ||
// this is the default Structure ! | ||
// throw new Error("invalid nodeId " + dataTypeNodeId.toString()); | ||
/* istanbul ignore next */ | ||
if (doDebug) { | ||
@@ -678,2 +768,3 @@ console.log("resolveFieldType: Invalid NodeId ", dataTypeNodeId.toString()); | ||
schema = yield findDataTypeBasicType(session, cache, dataTypeNodeId); | ||
/* istanbul ignore next */ | ||
if (!schema) { | ||
@@ -690,2 +781,3 @@ console.log("Cannot find basic type " + fieldTypeName); | ||
}); | ||
/* istanbul ignore next */ | ||
if (dataTypeDefinitionDataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) { | ||
@@ -708,5 +800,7 @@ throw new Error(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString()); | ||
} | ||
// xx const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName); | ||
break; | ||
} | ||
} | ||
/* istanbul ignore next */ | ||
if (!schema) { | ||
@@ -726,2 +820,3 @@ throw new Error("expecting a schema here fieldTypeName=" + fieldTypeName + " " + dataTypeNodeId.toString() + " category = " + category); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// read abstract flag | ||
const isAbstractDV = yield session.read({ nodeId: dataTypeNodeId, attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract }); | ||
@@ -746,2 +841,3 @@ schema.dataTypeNodeId = dataTypeNodeId; | ||
case node_opcua_types_1.StructureType.Union: | ||
//xx console.log("Union Found : ", name); | ||
fields.push({ | ||
@@ -748,0 +844,0 @@ name: "SwitchField", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ExtraDataTypeManager = void 0; | ||
/** | ||
* @module node-opcua-client-dynamic-extension-object | ||
*/ | ||
const util = require("util"); | ||
@@ -11,2 +14,3 @@ const node_opcua_assert_1 = require("node-opcua-assert"); | ||
this.dataTypeFactoryMapByNamespace = {}; | ||
/* */ | ||
} | ||
@@ -20,2 +24,3 @@ setNamespaceArray(namespaceArray) { | ||
registerDataTypeFactory(namespaceIndex, dataTypeFactory) { | ||
/* istanbul ignore next */ | ||
node_opcua_assert_1.default(namespaceIndex !== 0, "registerTypeDictionary cannot be used for namespace 0"); | ||
@@ -39,2 +44,3 @@ if (this.hasDataTypeFactory(namespaceIndex)) { | ||
const dataTypeFactory = this.getDataTypeFactory(dataTypeNodeId.namespace); | ||
// find schema corresponding to dataTypeNodeId in typeDictionary | ||
const Constructor = dataTypeFactory.findConstructorForDataType(dataTypeNodeId); | ||
@@ -41,0 +47,0 @@ return Constructor; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-client-dynamic-extension-object | ||
*/ | ||
export * from "./client_dynamic_extension_object"; | ||
@@ -2,0 +5,0 @@ export * from "./extra_data_type_manager"; |
@@ -13,2 +13,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @module node-opcua-client-dynamic-extension-object | ||
*/ | ||
__exportStar(require("./client_dynamic_extension_object"), exports); | ||
@@ -15,0 +18,0 @@ __exportStar(require("./extra_data_type_manager"), exports); |
@@ -32,2 +32,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// count number of Opaque Structures | ||
const dataValuesToFix = dataValues.filter((dataValue) => dataValue.value && dataValue.value.dataType === node_opcua_variant_1.DataType.ExtensionObject && | ||
@@ -43,2 +44,3 @@ ((dataValue.value.arrayType === node_opcua_variant_1.VariantArrayType.Scalar | ||
} | ||
// construct dataTypeManager if not already present | ||
const extraDataTypeManager = yield getExtraDataTypeManager(session); | ||
@@ -45,0 +47,0 @@ const promises = dataValuesToFix.map((dataValue) => __awaiter(this, void 0, void 0, function* () { |
@@ -26,7 +26,13 @@ "use strict"; | ||
catch (err) { | ||
// tslint:disable-next-line:no-console | ||
console.log("Constructor = ", Constructor.name); | ||
// tslint:disable-next-line:no-console | ||
console.log("opaqueStructure = ", opaque.nodeId.toString()); | ||
// tslint:disable-next-line:no-console | ||
console.log("opaqueStructure = ", "0x" + opaque.buffer.toString("hex")); | ||
// tslint:disable-next-line: no-console | ||
console.log(node_opcua_debug_1.hexDump(opaque.buffer)); | ||
// tslint:disable-next-line:no-console | ||
console.log("resolveDynamicExtensionObjectV err = ", err); | ||
// try again for debugging | ||
object.decode(stream); | ||
@@ -33,0 +39,0 @@ return opaque; |
{ | ||
"name": "node-opcua-client-dynamic-extension-object", | ||
"version": "2.6.0-alpha.7", | ||
"version": "2.6.1", | ||
"description": "pure nodejs OPCUA SDK - module client-dynamic-extension-object", | ||
@@ -14,17 +14,17 @@ "main": "./dist/index.js", | ||
"chalk": "^4.0.0", | ||
"node-opcua-assert": "^2.6.0-alpha.1", | ||
"node-opcua-binary-stream": "^2.6.0-alpha.1", | ||
"node-opcua-data-model": "^2.6.0-alpha.7", | ||
"node-opcua-data-value": "^2.6.0-alpha.7", | ||
"node-opcua-debug": "^2.6.0-alpha.1", | ||
"node-opcua-extension-object": "^2.6.0-alpha.7", | ||
"node-opcua-factory": "^2.6.0-alpha.7", | ||
"node-opcua-nodeid": "^2.6.0-alpha.1", | ||
"node-opcua-pseudo-session": "^2.6.0-alpha.7", | ||
"node-opcua-schemas": "^2.6.0-alpha.7", | ||
"node-opcua-service-browse": "^2.6.0-alpha.7", | ||
"node-opcua-service-translate-browse-path": "^2.6.0-alpha.7", | ||
"node-opcua-status-code": "^2.6.0-alpha.1", | ||
"node-opcua-types": "^2.6.0-alpha.7", | ||
"node-opcua-variant": "^2.6.0-alpha.7" | ||
"node-opcua-assert": "^2.6.1", | ||
"node-opcua-binary-stream": "^2.6.1", | ||
"node-opcua-data-model": "^2.6.1", | ||
"node-opcua-data-value": "^2.6.1", | ||
"node-opcua-debug": "^2.6.1", | ||
"node-opcua-extension-object": "^2.6.1", | ||
"node-opcua-factory": "^2.6.1", | ||
"node-opcua-nodeid": "^2.6.1", | ||
"node-opcua-pseudo-session": "^2.6.1", | ||
"node-opcua-schemas": "^2.6.1", | ||
"node-opcua-service-browse": "^2.6.1", | ||
"node-opcua-service-translate-browse-path": "^2.6.1", | ||
"node-opcua-status-code": "^2.6.1", | ||
"node-opcua-types": "^2.6.1", | ||
"node-opcua-variant": "^2.6.1" | ||
}, | ||
@@ -46,3 +46,3 @@ "author": "Etienne Rossignon", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
144076
2219
1
Updatednode-opcua-assert@^2.6.1
Updatednode-opcua-data-model@^2.6.1
Updatednode-opcua-data-value@^2.6.1
Updatednode-opcua-debug@^2.6.1
Updatednode-opcua-factory@^2.6.1
Updatednode-opcua-nodeid@^2.6.1
Updatednode-opcua-schemas@^2.6.1
Updatednode-opcua-types@^2.6.1
Updatednode-opcua-variant@^2.6.1