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

node-opcua-client-dynamic-extension-object

Package Overview
Dependencies
Maintainers
1
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-client-dynamic-extension-object - npm Package Compare versions

Comparing version 2.76.2 to 2.77.0

6

dist/convert_data_type_definition_to_structuretype_schema.d.ts

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

import { DataTypeFactory, FieldCategory, StructuredTypeSchema, TypeDefinition } from "node-opcua-factory";
import { DataTypeFactory, FieldCategory, IStructuredTypeSchema, TypeDefinition } from "node-opcua-factory";
import { NodeId } from "node-opcua-nodeid";

@@ -12,4 +12,4 @@ import { IBasicSession } from "node-opcua-pseudo-session";

}
export declare function convertDataTypeDefinitionToStructureTypeSchema(session: IBasicSession, dataTypeNodeId: NodeId, name: string, definition: DataTypeDefinition, dataTypeFactory: DataTypeFactory, cache: {
export declare function convertDataTypeDefinitionToStructureTypeSchema(session: IBasicSession, dataTypeNodeId: NodeId, name: string, definition: DataTypeDefinition, dataTypeFactory: DataTypeFactory, isAbstract: boolean, cache: {
[key: string]: CacheForFieldResolution;
}): Promise<StructuredTypeSchema>;
}): Promise<IStructuredTypeSchema>;

@@ -165,3 +165,4 @@ "use strict";

else {
schema = yield convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, fieldTypeName, definition, dataTypeFactory, cache);
const isAbstract = false;
schema = yield convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, fieldTypeName, definition, dataTypeFactory, isAbstract, cache);
}

@@ -250,3 +251,3 @@ // xx const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);

let category = node_opcua_factory_1.FieldCategory.enumeration;
if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
if (dataTypeFactory.hasStructureByTypeName(fieldTypeName)) {
schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);

@@ -287,3 +288,2 @@ category = node_opcua_factory_1.FieldCategory.complex;

schema.dataTypeNodeId = dataTypeNodeId;
schema.id = dataTypeNodeId;
if (isAbstractDV.statusCode === node_opcua_status_code_1.StatusCodes.Good && isAbstractDV.value.value === false) {

@@ -299,12 +299,16 @@ const encodings = yield (0, find_encodings_1._findEncodings)(session, dataTypeNodeId);

// eslint-disable-next-line max-statements
function convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, name, definition, dataTypeFactory, cache) {
var _a;
function convertDataTypeDefinitionToStructureTypeSchema(session, dataTypeNodeId, name, definition, dataTypeFactory, isAbstract, cache) {
return __awaiter(this, void 0, void 0, function* () {
if (definition instanceof node_opcua_types_1.StructureDefinition) {
let fieldCountToIgnore = 0;
let base = (_a = dataTypeFactory.getConstructorForDataType(definition.baseDataType)) === null || _a === void 0 ? void 0 : _a.schema;
while (base && !(base.dataTypeNodeId.value === node_opcua_variant_1.DataType.ExtensionObject && base.dataTypeNodeId.namespace === 0)) {
fieldCountToIgnore += base._possibleFields.length;
base = base._baseSchema;
const structureInfo = dataTypeFactory.getStructureInfoForDataType(definition.baseDataType);
const baseSchema = structureInfo === null || structureInfo === void 0 ? void 0 : structureInfo.schema;
if (baseSchema) {
const possibleFields = (0, node_opcua_factory_1.extractAllPossibleFields)(baseSchema);
fieldCountToIgnore += possibleFields.length;
}
// while (base && !(base.dataTypeNodeId.value === DataType.ExtensionObject && base.dataTypeNodeId.namespace === 0)) {
// fieldCountToIgnore += base..length;
// base = base.getBaseSchema();
// }
const fields = [];

@@ -367,4 +371,4 @@ const isUnion = definition.structureType === node_opcua_types_1.StructureType.Union;

fields,
id: 0,
name
name,
dataTypeFactory
});

@@ -371,0 +375,0 @@ const structuredTypeSchema = yield _setupEncodings(session, dataTypeNodeId, os);

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

// find schema corresponding to dataTypeNodeId in typeDictionary
const Constructor = dataTypeFactory.findConstructorForDataType(dataTypeNodeId);
const Constructor = dataTypeFactory.findStructureInfoForDataType(dataTypeNodeId).constructor;
if (!Constructor) {
throw new Error("Cannot find Extension Object Constructor for Abstract dataType");
}
return Constructor;

@@ -49,0 +52,0 @@ }

@@ -24,5 +24,5 @@ "use strict";

const dataTypeFactory = extraDataTypeManager.getDataTypeFactory(dataTypeNodeId.namespace);
const Constructor = dataTypeFactory.getConstructorForDataType(dataTypeNodeId);
if (Constructor) {
return Constructor;
const structureInfo = dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId);
if (structureInfo) {
return structureInfo.constructor;
}

@@ -29,0 +29,0 @@ const dataValue = yield session.read({

@@ -122,4 +122,9 @@ "use strict";

result3.references = result3.references || [];
if (result3.references.length === 0) {
// may be the dataType is abstract and as no need for DescriptionOF
continue;
}
if (result3.references.length !== 1) {
warningLog("_enrichWithDescriptionOf : expecting 1 reference for ", dataTypeDescription.browseName.toString());
warningLog(result3.toString());
continue;

@@ -224,3 +229,3 @@ }

const className = dataTypeDescription.browseName.name;
dataTypeDefinitions.push({ className, dataTypeNodeId, dataTypeDefinition });
dataTypeDefinitions.push({ className, dataTypeNodeId, dataTypeDefinition, isAbstract: false });
}

@@ -238,3 +243,3 @@ }

}
for (const { className, dataTypeNodeId, dataTypeDefinition } of dataTypeDefinitionsSorted) {
for (const { className, dataTypeNodeId, dataTypeDefinition, isAbstract } of dataTypeDefinitionsSorted) {
// istanbul ignore next

@@ -244,3 +249,3 @@ if (doDebug) {

}
if (dataTypeFactory.hasStructuredType(className)) {
if (dataTypeFactory.hasStructureByTypeName(className)) {
continue; // this structure has already been seen

@@ -250,3 +255,3 @@ }

try {
const schema = yield (0, convert_data_type_definition_to_structuretype_schema_1.convertDataTypeDefinitionToStructureTypeSchema)(session, dataTypeNodeId, className, dataTypeDefinition, dataTypeFactory, cache);
const schema = yield (0, convert_data_type_definition_to_structuretype_schema_1.convertDataTypeDefinitionToStructureTypeSchema)(session, dataTypeNodeId, className, dataTypeDefinition, dataTypeFactory, isAbstract, cache);
// istanbul ignore next

@@ -366,5 +371,8 @@ if (doDebug) {

try {
const constructor = dataTypeFactory.getStructureTypeConstructor(name);
const Constructor = dataTypeFactory.getStructureInfoByTypeName(name).constructor;
if (!Constructor) {
throw new Error(`Cannot instantiate abstract DataType(name=${name})`);
}
// xx const constructor = getOrCreateConstructor(name, dataTypeFactory, defaultBinary);
const testObject = new constructor();
const testObject = new Constructor();
debugLog(testObject.toString());

@@ -371,0 +379,0 @@ }

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

exports.populateDataTypeManager104 = exports.readDataTypeDefinitionAndBuildType = void 0;
const node_opcua_assert_1 = require("node-opcua-assert");
const node_opcua_data_model_1 = require("node-opcua-data-model");

@@ -26,7 +25,18 @@ const node_opcua_debug_1 = require("node-opcua-debug");

try {
const dataTypeDefinitionDataValue = yield session.read({
attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition,
nodeId: dataTypeNodeId
});
const [isAbstractDataValue, dataTypeDefinitionDataValue] = yield session.read([
{
attributeId: node_opcua_data_model_1.AttributeIds.IsAbstract,
nodeId: dataTypeNodeId
},
{
attributeId: node_opcua_data_model_1.AttributeIds.DataTypeDefinition,
nodeId: dataTypeNodeId
}
]);
/* istanbul ignore next */
if (isAbstractDataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
throw new Error(" Cannot find dataType isAbstract ! with nodeId =" + dataTypeNodeId.toString());
}
const isAbstract = isAbstractDataValue.value.value;
/* istanbul ignore next */
if (dataTypeDefinitionDataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {

@@ -36,4 +46,10 @@ throw new Error(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString());

const dataTypeDefinition = dataTypeDefinitionDataValue.value.value;
const schema = yield (0, convert_data_type_definition_to_structuretype_schema_1.convertDataTypeDefinitionToStructureTypeSchema)(session, dataTypeNodeId, name, dataTypeDefinition, dataTypeFactory, cache);
(0, node_opcua_schemas_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
const schema = yield (0, convert_data_type_definition_to_structuretype_schema_1.convertDataTypeDefinitionToStructureTypeSchema)(session, dataTypeNodeId, name, dataTypeDefinition, dataTypeFactory, isAbstract, cache);
if (isAbstract) {
// cannot construct an abstract structure
dataTypeFactory.registerAbstractStructure(dataTypeNodeId, name, schema);
}
else {
const Constructor = (0, node_opcua_schemas_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
}
}

@@ -160,3 +176,3 @@ catch (err) {

// if not found already
if (dataTypeFactory.getConstructorForDataType(dataTypeNodeId)) {
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
// already known !

@@ -168,3 +184,2 @@ return;

yield readDataTypeDefinitionAndBuildType(session, dataTypeNodeId, r.browseName.name, dataTypeFactory, cache);
(0, node_opcua_assert_1.assert)(dataTypeFactory.getConstructorForDataType(dataTypeNodeId));
}

@@ -171,0 +186,0 @@ catch (err) {

@@ -0,4 +1,6 @@

import { ExtensionObject } from "node-opcua-extension-object";
import { Variant } from "node-opcua-variant";
import { IBasicSession } from "node-opcua-pseudo-session";
import { ExtraDataTypeManager } from "./extra_data_type_manager";
export declare function resolveOpaqueStructureInExtentionObject(session: IBasicSession, dataTypeManager: ExtraDataTypeManager, object: ExtensionObject): Promise<void>;
export declare function resolveDynamicExtensionObject(session: IBasicSession, variant: Variant, dataTypeManager: ExtraDataTypeManager): Promise<void>;

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveDynamicExtensionObject = void 0;
exports.resolveDynamicExtensionObject = exports.resolveOpaqueStructureInExtentionObject = void 0;
const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");

@@ -46,11 +46,83 @@ const node_opcua_extension_object_1 = require("node-opcua-extension-object");

const dataTypeNodeId = r.nodeId;
if (dataTypeFactory.getConstructorForDataType(dataTypeNodeId)) {
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
throw new Error("Internal Error: we are not expecting this dataType to be processed already");
}
yield (0, populate_data_type_manager_104_1.readDataTypeDefinitionAndBuildType)(session, dataTypeNodeId, r.browseName.name, dataTypeFactory, {});
return dataTypeFactory.getConstructorForDataType(dataTypeNodeId);
const structureInfo = dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId);
if (!structureInfo.constructor) {
throw new Error("Cannot find constructor for abstract DataType");
}
return structureInfo.constructor;
});
}
function resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object) {
return __awaiter(this, void 0, void 0, function* () {
const schema = object.schema;
function fixOpaqueStructureOnElement(element, field, data, args) {
return __awaiter(this, void 0, void 0, function* () {
if (element instanceof node_opcua_variant_1.Variant) {
yield resolveDynamicExtensionObject(session, element, dataTypeManager);
return element;
}
if (!(element instanceof node_opcua_extension_object_1.OpaqueStructure)) {
return element;
}
const variant = new node_opcua_variant_1.Variant({ dataType: node_opcua_variant_1.DataType.ExtensionObject, value: element });
yield resolveDynamicExtensionObject(session, variant, dataTypeManager);
return variant.value;
});
}
function fixOpaqueStructure(object, field, data, args) {
if (field.category === "complex" && !field.allowSubType) {
return;
}
if (field.category === "basic" && field.fieldType !== "Variant") {
return;
}
console.log("field", field.name, field.category, field.fieldType);
const a = object[field.name];
if (!a) {
return;
}
if (field.isArray) {
for (let i = 0; i < a.length; i++) {
const x = a[i];
promises.push((() => __awaiter(this, void 0, void 0, function* () {
a[i] = yield fixOpaqueStructureOnElement(x, field, data, args);
}))());
}
}
else {
promises.push((() => __awaiter(this, void 0, void 0, function* () {
object[field.name] = yield fixOpaqueStructureOnElement(a, field, data, args);
}))());
}
}
const promises = [];
object.applyOnAllFields(fixOpaqueStructure, { dataTypeManager, promises });
yield Promise.all(promises);
});
}
exports.resolveOpaqueStructureInExtentionObject = resolveOpaqueStructureInExtentionObject;
// async function resolveInnerVariantType(session: IBasicSession, object: ExtensionObject, dataTypeManager: ExtraDataTypeManager) {
// console.log("object = ", object.constructor.name);
// const fields = object.schema.fields;
// const _object = object as unknown as Record<string, unknown>;
// for (const field of fields) {
// console.log("field = ", field.name);
// if (field.category !== "complex") continue;
// const p = _object[field.name];
// if (p === undefined || p === null) continue;
// console.log("=>", field.name, (p as any).toString());
// if (p instanceof ExtensionObject) {
// resolveInnerVariantType(session, p, dataTypeManager);
// }
// if (p instanceof Variant && p.value instanceof OpaqueStructure) {
// console.log("§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§");
// p.value = resolveDynamicExtensionObjectV(session, p.value, dataTypeManager);
// }
// }
// }
function resolveDynamicExtensionObjectV(session, opaque, dataTypeManager) {
var _a, _b;
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -63,2 +135,3 @@ try {

object.decode(stream);
yield resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object);
return object;

@@ -69,3 +142,3 @@ }

warningLog("opaqueStructure = ", (_a = opaque === null || opaque === void 0 ? void 0 : opaque.nodeId) === null || _a === void 0 ? void 0 : _a.toString());
warningLog("opaqueStructure = ", "0x" + ((_b = opaque === null || opaque === void 0 ? void 0 : opaque.buffer) === null || _b === void 0 ? void 0 : _b.toString("hex")));
warningLog("opaqueStructure = ", (0, node_opcua_debug_1.hexDump)(opaque.buffer, 132, 100));
warningLog((0, node_opcua_debug_1.hexDump)(opaque.buffer));

@@ -81,3 +154,3 @@ warningLog("resolveDynamicExtensionObjectV err = ", err);

warningLog("opaqueStructure = ", opaque.nodeId.toString());
warningLog("opaqueStructure = ", "0x" + opaque.buffer.toString("hex"));
warningLog("opaqueStructure = ", "0x" + (0, node_opcua_debug_1.hexDump)(opaque.buffer, 132, 100));
warningLog((0, node_opcua_debug_1.hexDump)(opaque.buffer));

@@ -84,0 +157,0 @@ warningLog(dataTypeManager.toString());

{
"name": "node-opcua-client-dynamic-extension-object",
"version": "2.76.2",
"version": "2.77.0",
"description": "pure nodejs OPCUA SDK - module client-dynamic-extension-object",

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

"build": "tsc -b",
"clean": "npx rimraf dist *.tsbuildinfo",
"clean": "npx rimraf node_modules dist *.tsbuildinfo",
"test": "echo no test"

@@ -15,17 +15,17 @@ },

"chalk": "4.1.2",
"node-opcua-assert": "2.76.0",
"node-opcua-binary-stream": "2.76.2",
"node-opcua-data-model": "2.76.2",
"node-opcua-data-value": "2.76.2",
"node-opcua-debug": "2.76.2",
"node-opcua-extension-object": "2.76.2",
"node-opcua-factory": "2.76.2",
"node-opcua-nodeid": "2.76.2",
"node-opcua-pseudo-session": "2.76.2",
"node-opcua-schemas": "2.76.2",
"node-opcua-service-browse": "2.76.2",
"node-opcua-service-translate-browse-path": "2.76.2",
"node-opcua-status-code": "2.76.2",
"node-opcua-types": "2.76.2",
"node-opcua-variant": "2.76.2"
"node-opcua-assert": "2.77.0",
"node-opcua-binary-stream": "2.77.0",
"node-opcua-data-model": "2.77.0",
"node-opcua-data-value": "2.77.0",
"node-opcua-debug": "2.77.0",
"node-opcua-extension-object": "2.77.0",
"node-opcua-factory": "2.77.0",
"node-opcua-nodeid": "2.77.0",
"node-opcua-pseudo-session": "2.77.0",
"node-opcua-schemas": "2.77.0",
"node-opcua-service-browse": "2.77.0",
"node-opcua-service-translate-browse-path": "2.77.0",
"node-opcua-status-code": "2.77.0",
"node-opcua-types": "2.77.0",
"node-opcua-variant": "2.77.0"
},

@@ -47,3 +47,3 @@ "author": "Etienne Rossignon",

"homepage": "http://node-opcua.github.io/",
"gitHead": "acb5ecaf1e1c71af3b63e80909d58447f3f298e7"
"gitHead": "5c8d45772d786fa4ba59369dd26679353ab5482b"
}

@@ -6,7 +6,11 @@ import { assert } from "node-opcua-assert";

import {
BitField,
ConstructorFuncWithSchema,
DataTypeFactory,
EnumerationDefinitionSchema,
extractAllPossibleFields,
FieldCategory,
FieldInterfaceOptions,
getBuiltInType,
IStructuredTypeSchema,
StructuredTypeSchema,

@@ -200,2 +204,3 @@ TypeDefinition

} else {
const isAbstract = false;
schema = await convertDataTypeDefinitionToStructureTypeSchema(

@@ -207,2 +212,3 @@ session,

dataTypeFactory,
isAbstract,
cache

@@ -304,3 +310,3 @@ );

if (dataTypeFactory.hasStructuredType(fieldTypeName!)) {
if (dataTypeFactory.hasStructureByTypeName(fieldTypeName!)) {
schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);

@@ -340,8 +346,7 @@ category = FieldCategory.complex;

dataTypeNodeId: NodeId,
schema: StructuredTypeSchema
): Promise<StructuredTypeSchema> {
schema: IStructuredTypeSchema
): Promise<IStructuredTypeSchema> {
// read abstract flag
const isAbstractDV = await session.read({ nodeId: dataTypeNodeId, attributeId: AttributeIds.IsAbstract });
schema.dataTypeNodeId = dataTypeNodeId;
schema.id = dataTypeNodeId;

@@ -364,11 +369,18 @@ if (isAbstractDV.statusCode === StatusCodes.Good && isAbstractDV.value.value === false) {

dataTypeFactory: DataTypeFactory,
isAbstract: boolean,
cache: { [key: string]: CacheForFieldResolution }
): Promise<StructuredTypeSchema> {
): Promise<IStructuredTypeSchema> {
if (definition instanceof StructureDefinition) {
let fieldCountToIgnore = 0;
let base: undefined | any = dataTypeFactory.getConstructorForDataType(definition.baseDataType)?.schema;
while (base && !(base.dataTypeNodeId.value === DataType.ExtensionObject && base.dataTypeNodeId.namespace === 0)) {
fieldCountToIgnore += base._possibleFields.length;
base = base._baseSchema;
const structureInfo = dataTypeFactory.getStructureInfoForDataType(definition.baseDataType);
const baseSchema: IStructuredTypeSchema | undefined | null = structureInfo?.schema;
if (baseSchema) {
const possibleFields = extractAllPossibleFields(baseSchema);
fieldCountToIgnore += possibleFields.length;
}
// while (base && !(base.dataTypeNodeId.value === DataType.ExtensionObject && base.dataTypeNodeId.namespace === 0)) {
// fieldCountToIgnore += base..length;
// base = base.getBaseSchema();
// }

@@ -395,5 +407,5 @@ const fields: FieldInterfaceOptions[] = [];

const bitFields: { name: string; length?: number }[] | undefined = isUnion ? undefined : [];
const bitFields: BitField[] | undefined = isUnion ? undefined : [];
const postActions: ((schema: StructuredTypeSchema) => void)[] = [];
const postActions: ((schema: IStructuredTypeSchema) => void)[] = [];

@@ -415,3 +427,3 @@ if (definition.fields) {

const capturedField = field;
postActions.push((schema: StructuredTypeSchema) => {
postActions.push((schema: IStructuredTypeSchema) => {
capturedField.schema = schema;

@@ -450,4 +462,4 @@ });

fields,
id: 0,
name
name,
dataTypeFactory
});

@@ -465,3 +477,3 @@ const structuredTypeSchema = await _setupEncodings(session, dataTypeNodeId, os);

switchBit: number,
bitFields: { name: string; length?: number | undefined }[] | undefined,
bitFields: BitField[] | undefined,
isUnion: boolean,

@@ -468,0 +480,0 @@ switchValue: number

@@ -54,3 +54,6 @@ /**

// find schema corresponding to dataTypeNodeId in typeDictionary
const Constructor = dataTypeFactory.findConstructorForDataType(dataTypeNodeId);
const Constructor = dataTypeFactory.findStructureInfoForDataType(dataTypeNodeId).constructor;
if (!Constructor) {
throw new Error("Cannot find Extension Object Constructor for Abstract dataType");
}
return Constructor;

@@ -57,0 +60,0 @@ }

@@ -16,5 +16,5 @@ import { QualifiedName, AttributeIds } from "node-opcua-data-model";

const dataTypeFactory = extraDataTypeManager.getDataTypeFactory(dataTypeNodeId.namespace);
const Constructor = dataTypeFactory.getConstructorForDataType(dataTypeNodeId);
if (Constructor) {
return Constructor as unknown as AnyConstructorFunc;
const structureInfo = dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId);
if (structureInfo) {
return structureInfo.constructor as unknown as AnyConstructorFunc;
}

@@ -21,0 +21,0 @@ const dataValue = await session.read({

@@ -10,3 +10,3 @@ /* eslint-disable max-statements */

import { AttributeIds, makeNodeClassMask, makeResultMask, QualifiedName } from "node-opcua-data-model";
import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog} from "node-opcua-debug";
import { checkDebugFlag, make_debugLog, make_errorLog, make_warningLog } from "node-opcua-debug";
import { ConstructorFuncWithSchema, DataTypeFactory, getStandardDataTypeFactory } from "node-opcua-factory";

@@ -131,4 +131,10 @@ import { ExpandedNodeId, NodeId, resolveNodeId, sameNodeId } from "node-opcua-nodeid";

result3.references = result3.references || [];
if (result3.references.length === 0) {
// may be the dataType is abstract and as no need for DescriptionOF
continue;
}
if (result3.references.length !== 1) {
warningLog("_enrichWithDescriptionOf : expecting 1 reference for ", dataTypeDescription.browseName.toString());
warningLog(result3.toString());
continue;

@@ -186,2 +192,3 @@ }

dataTypeDefinition: StructureDefinition;
isAbstract: boolean;
}

@@ -217,3 +224,3 @@ type DataTypeDefinitions = IDataTypeDefInfo[];

}
dataTypeDefinitionsSorted.push(d);

@@ -262,3 +269,3 @@ }

const className = dataTypeDescription.browseName.name!;
dataTypeDefinitions.push({ className, dataTypeNodeId, dataTypeDefinition });
dataTypeDefinitions.push({ className, dataTypeNodeId, dataTypeDefinition, isAbstract: false });
}

@@ -280,3 +287,3 @@ } else {

}
for (const { className, dataTypeNodeId, dataTypeDefinition } of dataTypeDefinitionsSorted) {
for (const { className, dataTypeNodeId, dataTypeDefinition, isAbstract } of dataTypeDefinitionsSorted) {
// istanbul ignore next

@@ -286,3 +293,3 @@ if (doDebug) {

}
if (dataTypeFactory.hasStructuredType(className)) {
if (dataTypeFactory.hasStructureByTypeName(className)) {
continue; // this structure has already been seen

@@ -298,2 +305,3 @@ }

dataTypeFactory,
isAbstract,
cache

@@ -451,5 +459,8 @@ );

try {
const constructor = dataTypeFactory.getStructureTypeConstructor(name);
const Constructor = dataTypeFactory.getStructureInfoByTypeName(name).constructor;
if (!Constructor) {
throw new Error(`Cannot instantiate abstract DataType(name=${name})`);
}
// xx const constructor = getOrCreateConstructor(name, dataTypeFactory, defaultBinary);
const testObject = new constructor();
const testObject = new Constructor();
debugLog(testObject.toString());

@@ -456,0 +467,0 @@ } catch (err) {

@@ -7,3 +7,3 @@ import { assert } from "node-opcua-assert";

import { IBasicSession, BrowseDescriptionLike } from "node-opcua-pseudo-session";
import { createDynamicObjectConstructor } from "node-opcua-schemas";
import { createDynamicObjectConstructor as createDynamicObjectConstructorAndRegister } from "node-opcua-schemas";
import { StatusCodes } from "node-opcua-status-code";

@@ -29,7 +29,19 @@ import { ReferenceDescription, BrowseResult, BrowseDescriptionOptions } from "node-opcua-types";

try {
const dataTypeDefinitionDataValue = await session.read({
attributeId: AttributeIds.DataTypeDefinition,
nodeId: dataTypeNodeId
});
const [isAbstractDataValue, dataTypeDefinitionDataValue] = await session.read([
{
attributeId: AttributeIds.IsAbstract,
nodeId: dataTypeNodeId
},
{
attributeId: AttributeIds.DataTypeDefinition,
nodeId: dataTypeNodeId
}
]);
/* istanbul ignore next */
if (isAbstractDataValue.statusCode !== StatusCodes.Good) {
throw new Error(" Cannot find dataType isAbstract ! with nodeId =" + dataTypeNodeId.toString());
}
const isAbstract = isAbstractDataValue.value.value as boolean;
/* istanbul ignore next */
if (dataTypeDefinitionDataValue.statusCode !== StatusCodes.Good) {

@@ -46,7 +58,12 @@ throw new Error(" Cannot find dataType Definition ! with nodeId =" + dataTypeNodeId.toString());

dataTypeFactory,
isAbstract,
cache
);
createDynamicObjectConstructor(schema, dataTypeFactory);
if (isAbstract) {
// cannot construct an abstract structure
dataTypeFactory.registerAbstractStructure(dataTypeNodeId, name, schema);
} else {
const Constructor = createDynamicObjectConstructorAndRegister(schema, dataTypeFactory);
}
} catch (err) {

@@ -171,3 +188,3 @@ errorLog("Error", err);

// if not found already
if (dataTypeFactory.getConstructorForDataType(dataTypeNodeId)) {
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
// already known !

@@ -179,3 +196,2 @@ return;

await readDataTypeDefinitionAndBuildType(session, dataTypeNodeId, r.browseName.name!, dataTypeFactory, cache);
assert(dataTypeFactory.getConstructorForDataType(dataTypeNodeId));
} catch (err) {

@@ -182,0 +198,0 @@ errorLog("err=", err);

@@ -7,3 +7,3 @@ import { BinaryStream } from "node-opcua-binary-stream";

import { NodeId } from "node-opcua-nodeid";
import { ConstructorFunc } from "node-opcua-factory";
import { ConstructorFunc, StructuredTypeField } from "node-opcua-factory";
import { BrowseDirection, NodeClassMask, ResultMask } from "node-opcua-data-model";

@@ -23,2 +23,4 @@ import { StatusCodes } from "node-opcua-status-code";

const dataTypeFactory = dataTypeManager.getDataTypeFactoryForNamespace(binaryEncodingNodeId.namespace);
const Constructor = dataTypeFactory.getConstructor(binaryEncodingNodeId);

@@ -46,3 +48,3 @@ if (Constructor) {

if (dataTypeFactory.getConstructorForDataType(dataTypeNodeId)) {
if (dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)) {
throw new Error("Internal Error: we are not expecting this dataType to be processed already");

@@ -52,5 +54,90 @@ }

return dataTypeFactory.getConstructorForDataType(dataTypeNodeId)!;
const structureInfo = dataTypeFactory.getStructureInfoForDataType(dataTypeNodeId)!;
if (!structureInfo.constructor) {
throw new Error("Cannot find constructor for abstract DataType");
}
return structureInfo.constructor;
}
export async function resolveOpaqueStructureInExtentionObject(
session: IBasicSession,
dataTypeManager: ExtraDataTypeManager,
object: ExtensionObject
) {
const schema = object.schema;
interface D {
dataTypeManager: ExtraDataTypeManager;
promises: Promise<void>[];
}
async function fixOpaqueStructureOnElement(
element: Record<string, unknown>,
field: StructuredTypeField,
data: D,
args?: any
): Promise<unknown> {
if (element instanceof Variant) {
await resolveDynamicExtensionObject(session, element, dataTypeManager);
return element;
}
if (!(element instanceof OpaqueStructure)) {
return element;
}
const variant = new Variant({ dataType: DataType.ExtensionObject, value: element });
await resolveDynamicExtensionObject(session, variant, dataTypeManager);
return variant.value as unknown;
}
function fixOpaqueStructure(object: any, field: StructuredTypeField, data: D, args?: any) {
if (field.category === "complex" && !field.allowSubType) {
return;
}
if (field.category === "basic" && field.fieldType !== "Variant") {
return;
}
console.log("field", field.name, field.category, field.fieldType);
const a = object[field.name];
if (!a) {
return;
}
if (field.isArray) {
for (let i = 0; i < a.length; i++) {
const x = a[i];
promises.push(
(async () => {
a[i] = await fixOpaqueStructureOnElement(x, field, data, args);
})()
);
}
} else {
promises.push(
(async () => {
object[field.name] = await fixOpaqueStructureOnElement(a, field, data, args);
})()
);
}
}
const promises: Promise<void>[] = [];
object.applyOnAllFields<D>(fixOpaqueStructure, { dataTypeManager, promises });
await Promise.all(promises);
}
// async function resolveInnerVariantType(session: IBasicSession, object: ExtensionObject, dataTypeManager: ExtraDataTypeManager) {
// console.log("object = ", object.constructor.name);
// const fields = object.schema.fields;
// const _object = object as unknown as Record<string, unknown>;
// for (const field of fields) {
// console.log("field = ", field.name);
// if (field.category !== "complex") continue;
// const p = _object[field.name];
// if (p === undefined || p === null) continue;
// console.log("=>", field.name, (p as any).toString());
// if (p instanceof ExtensionObject) {
// resolveInnerVariantType(session, p, dataTypeManager);
// }
// if (p instanceof Variant && p.value instanceof OpaqueStructure) {
// console.log("§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§");
// p.value = resolveDynamicExtensionObjectV(session, p.value, dataTypeManager);
// }
// }
// }
async function resolveDynamicExtensionObjectV(

@@ -67,7 +154,8 @@ session: IBasicSession,

object.decode(stream);
return object as ExtensionObject;
await resolveOpaqueStructureInExtentionObject(session, dataTypeManager, object);
return object;
} catch (err) {
warningLog("Constructor = ", Constructor.name);
warningLog("opaqueStructure = ", opaque?.nodeId?.toString());
warningLog("opaqueStructure = ", "0x" + opaque?.buffer?.toString("hex"));
warningLog("opaqueStructure = ", hexDump(opaque.buffer,132,100));
warningLog(hexDump(opaque.buffer));

@@ -82,3 +170,3 @@ warningLog("resolveDynamicExtensionObjectV err = ", err);

warningLog("opaqueStructure = ", opaque.nodeId.toString());
warningLog("opaqueStructure = ", "0x" + opaque.buffer.toString("hex"));
warningLog("opaqueStructure = ", "0x" + hexDump(opaque.buffer,132,100));
warningLog(hexDump(opaque.buffer));

@@ -85,0 +173,0 @@ warningLog(dataTypeManager.toString());

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