Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function _findDataType(dataTypeName) {
const builtInDataTypeName = findBuiltInType(dataTypeName);
const dataType = DataType[builtInDataTypeName.name];
// istanbul ignore next
if (!dataType) {
throw new Error(" dataType " + dataTypeName + " must exists");
}
return dataType;
}
import { registerEnumeration } from "node-opcua-factory";
export enum ResultMask {
ReferenceType= 0x01,
IsForward= 0x02,
NodeClass= 0x04,
BrowseName= 0x08,
DisplayName= 0x10,
TypeDefinition= 0x20
}
export const schemaResultMask = {
name: "ResultMask",
enumValues: ResultMask
};
export const _enumerationResultMask: Enum = registerEnumeration(schemaResultMask);
// The ReferenceDescription type is defined in 7.24.
// @example
// makeNodeClassMask("Method | Object").should.eql(5);
export function makeResultMask(str: string): ResultMask {
const flags = str.split(" | ");
let r = 0;
for (const flag of flags) {
r |= (ResultMask as any)[flag];
}
return r as ResultMask;
}
return new LocalizedText({ locale: null, text: value });
}
if (value instanceof LocalizedText) {
return value;
}
if (!value.hasOwnProperty("text")) {
// tslint:disable:no-console
console.log("value = ", value);
throw new Error("cannot coerce to coerceLocalizedText");
}
return new LocalizedText(value);
}
// --------------------------------------------------------------------------------------------
// see Part 3 - $8.5 page 63
const schemaLocalizedText = buildStructuredType({
name: "LocalizedText",
baseType: "BaseUAObject",
fields: [
{
name: "locale",
fieldType: "LocaleId"
},
{
name: "text",
fieldType: "UAString",
defaultValue: () => null
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
field.fieldType = "NumericRange";
// xx console.log(" NumericRange detected here !");
} else {
field.fieldType = fieldTypeName;
}
if (!hasBuiltInType(fieldTypeName)) {
throw new Error("Unknown basic type " + fieldTypeName);
}
field.category = FieldCategory.basic;
break;
}
}
}
structuredTypeSchema = buildStructuredType(structuredType as StructuredTypeOptions);
typeDictionary.structuredTypes[name] = structuredTypeSchema;
return structuredTypeSchema;
}
} else if (hasStructuredType(fieldTypeName)) {
field.category = FieldCategory.complex;
field.schema = getStructuredTypeSchema(fieldTypeName);
} else {
field.category = FieldCategory.basic;
// try in this
field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
if (!field.schema) {
// tslint:disable-next-line:no-console
console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
} else {
if (hasBuiltInType(fieldTypeName)) {
field.category = FieldCategory.basic;
} else {
field.category = FieldCategory.complex;
}
}
}
break;
case "opc":
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
field.fieldType = "NumericRange";
// xx console.log(" NumericRange detected here !");
} else {
field.fieldType = fieldTypeName;
}
if (!hasBuiltInType(fieldTypeName)) {
throw new Error("Unknown basic type " + fieldTypeName);
}
field.category = FieldCategory.basic;
break;
const prefix = getNamespacePart(fieldType);
const fieldTypeName = adjustFieldTypeName(removeNamespacePart(fieldType)!);
switch (prefix) {
case "tns":
field.fieldType = fieldTypeName;
const enumeratedType = typeDictionary.enumeratedTypes[fieldTypeName];
if (enumeratedType) {
field.category = FieldCategory.enumeration;
field.schema = enumeratedType;
} else {
// must be a structure then ....
field.category = FieldCategory.complex;
field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
if (!field.schema) {
// tslint:disable-next-line:no-console
console.log("cannot find schema for ", fieldTypeName);
}
}
break;
case "ua":
field.fieldType = fieldTypeName;
if (hasBuiltInType(fieldTypeName)) {
field.category = FieldCategory.basic;
field.schema = getBuildInType(fieldTypeName);
} else if (hasStructuredType(fieldTypeName)) {
field.category = FieldCategory.complex;
field.schema = getStructuredTypeSchema(fieldTypeName);
assert(value instanceof Variant);
const dataTypeNode = addressSpace.findNode(node.dataType);
if (!dataTypeNode) {
return;
}
const dataTypeName = dataTypeNode.browseName.toString();
const baseDataTypeName = (DataType as any)[DataType[value.dataType]];
// console.log("nodeset_to_xml #_dumpValue Cannot find ", dataTypeName,node.dataType.toString());
if (!hasStructuredType(dataTypeName)) {
return;
} // this is not a extension object
const schema = getStructuredTypeSchema(dataTypeName);
function encodeXml(value1: any) {
_dumpVariantExtensionObjectValue_Body(xw, schema, value1);
}
xw.startElement("Value");
// determine if dataTypeName is a ExtensionObject
const isExtensionObject = dataTypeName === "LocalizedText" ? false : true;
if (isExtensionObject) {
if (value.arrayType === VariantArrayType.Array) {
xw.startElement("ListOf" + baseDataTypeName);
value.value.forEach(_dumpVariantExtensionObjectValue.bind(null, xw, schema));
xw.endElement();
field.category = FieldCategory.complex;
field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
if (!field.schema) {
// tslint:disable-next-line:no-console
console.log("cannot find schema for ", fieldTypeName);
}
}
break;
case "ua":
field.fieldType = fieldTypeName;
if (hasBuiltInType(fieldTypeName)) {
field.category = FieldCategory.basic;
field.schema = getBuildInType(fieldTypeName);
} else if (hasStructuredType(fieldTypeName)) {
field.category = FieldCategory.complex;
field.schema = getStructuredTypeSchema(fieldTypeName);
} else {
field.category = FieldCategory.basic;
// try in this
field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
if (!field.schema) {
// tslint:disable-next-line:no-console
console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
} else {
if (hasBuiltInType(fieldTypeName)) {
field.category = FieldCategory.basic;
} else {
field.category = FieldCategory.complex;
}
}
}
} else {
// must be a structure then ....
field.category = FieldCategory.complex;
field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
if (!field.schema) {
// tslint:disable-next-line:no-console
console.log("cannot find schema for ", fieldTypeName);
}
}
break;
case "ua":
field.fieldType = fieldTypeName;
if (hasBuiltInType(fieldTypeName)) {
field.category = FieldCategory.basic;
field.schema = getBuildInType(fieldTypeName);
} else if (hasStructuredType(fieldTypeName)) {
field.category = FieldCategory.complex;
field.schema = getStructuredTypeSchema(fieldTypeName);
} else {
field.category = FieldCategory.basic;
// try in this
field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
if (!field.schema) {
// tslint:disable-next-line:no-console
console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
} else {
if (hasBuiltInType(fieldTypeName)) {
field.category = FieldCategory.basic;
} else {
field.category = FieldCategory.complex;
}
if (!value) {
return;
}
assert(value instanceof Variant);
const dataTypeNode = addressSpace.findNode(node.dataType);
if (!dataTypeNode) {
return;
}
const dataTypeName = dataTypeNode.browseName.toString();
const baseDataTypeName = (DataType as any)[DataType[value.dataType]];
// console.log("nodeset_to_xml #_dumpValue Cannot find ", dataTypeName,node.dataType.toString());
if (!hasStructuredType(dataTypeName)) {
return;
} // this is not a extension object
const schema = getStructuredTypeSchema(dataTypeName);
function encodeXml(value1: any) {
_dumpVariantExtensionObjectValue_Body(xw, schema, value1);
}
xw.startElement("Value");
// determine if dataTypeName is a ExtensionObject
const isExtensionObject = dataTypeName === "LocalizedText" ? false : true;
if (isExtensionObject) {