How to use the node-opcua-factory.FieldCategory.complex function in node-opcua-factory

To help you get started, we’ve selected a few node-opcua-factory examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
} 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;
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
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);
github node-opcua / node-opcua / packages / node-opcua-schemas / source / dynamic_extension_object.ts View on Github external
function initializeField(
    field: FieldType,
    thisAny: any,
    options: any,
    schema: StructuredTypeSchema,
    typeDictionary: TypeDictionary
) {

    const name = field.name;

    switch (field.category) {
        case FieldCategory.complex: {
            const constuctor = getOrCreateConstructor(field.fieldType, typeDictionary) || BaseUAObject;
            if (field.isArray) {
                (thisAny)[name] = (options[name] || []).map((x: any) =>
                    constuctor ? new constuctor(x) : null
                );
            } else {
                (thisAny)[name] = constuctor ? new constuctor(options[name]) : null;
            }
            // xx processStructuredType(fieldSchema);
            break;
        }
        case FieldCategory.enumeration:
        case FieldCategory.basic:
            if (field.isArray) {
                (thisAny)[name] = initialize_field_array(field, options[name]);
            } else {
github node-opcua / node-opcua / packages / node-opcua-schemas / source / dynamic_extension_object.ts View on Github external
if (typeof switchValue !== "number") {
            throw new Error("Invalid switchValue  " + switchValue);
        }

        pojo[switchFieldName] = switchValue;

        for (const field of this.schema.fields) {
            if (field.switchValue === undefined || field.switchValue !== switchValue) {
                continue;
            }

            if ((this as any)[field.name] === undefined) {
                continue;
            }
            switch (field.category) {
                case FieldCategory.complex:
                    pojo[field.name] = (this as any)[field.name].toJSON();
                    break;
                case FieldCategory.enumeration:
                case FieldCategory.basic:
                    pojo[field.name] = (this as any)[field.name].toJSON ? (this as any)[field.name].toJSON() : (this as any)[field.name];
                    break;
                default:
                    /* istanbul ignore next*/
                    throw new Error("Invalid category " + field.category + " " + FieldCategory[field.category]);
            }
            break;
        }
        return pojo;
    }
github node-opcua / node-opcua / packages / node-opcua-generator / source / generate_extension_object_code.ts View on Github external
function processStructuredType(structuredType: StructuredTypeSchema): void {
            if (alreadyDone[structuredType.name]) {
                return;
            }
            alreadyDone[structuredType.name] = structuredType;
            // make sure
            if (typeDictionary.structuredTypes[structuredType.baseType]) {
                processStructuredType(typeDictionary.structuredTypes[structuredType.baseType]);
            }

            for (const field of structuredType.fields) {
                if (field.category === FieldCategory.complex) {
                    const fieldSchema = typeDictionary.structuredTypes[field.fieldType];
                    processStructuredType(fieldSchema);
                }
                if (field.category === FieldCategory.enumeration) {
                    const fieldSchema = typeDictionary.enumeratedTypes[field.fieldType];
                    processEnumeratedType(fieldSchema);
                }
            }
            writeStructuredTypeWithSchema(structuredType);
        }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / extension_object_array_node.ts View on Github external
field.$$func_decode$$ = decode_array.bind(null, field.$$func_decode$$);
        }
    }

    // reconstruct _schema form
    const fields = [];
    for (const field of dataType.definition) {
        const data: any = {
            fieldType: field.$$dataType$$.browseName.name,
            isArray: (field.valueRank === 1),
            name: field.$$name$$
        };
        if (field.$$isEnum$$) {
            data.category = FieldCategory.enumeration;
        } else if (field.$$isStructure$$) {
            data.category = FieldCategory.complex;
            data.fieldTypeConstructor = field.$$Constructor$$;
        } else {
            data.category = FieldCategory.basic;
        }
        fields.push(data);
    }

    Constructor.prototype.schema = {
        fields,
        id: -1,
        name: className
    };
    return Constructor;
}
github node-opcua / node-opcua / packages / node-opcua-generator / source / factory_code_generator.ts View on Github external
const n = schema.fields.length;
    const done: any = {};
    for (let i = 0; i < n; i++) {
        const field = schema.fields[i];
        const fieldType = field.fieldType;
        if (!(fieldType in done)) {
            done[fieldType] = field;
            switch (field.category) {
                case FieldCategory.basic:
                    break;
                case FieldCategory.enumeration:
                    write("const _enumeration" + field.fieldType + " = " + "getEnumeration(\"" + field.fieldType + "\");");
                    write("const encode" + field.fieldType + ": (value: any, stream: OutputBinaryStream) => void = getEnumeration(\"" + field.fieldType + "\").encode;");
                    write("const decode" + field.fieldType + ": (stream: BinaryStream) => void = getEnumeration(\"" + field.fieldType + "\").decode;");
                    break;
                case FieldCategory.complex:
                    write("const encode" + field.fieldType + ": (value: any, stream: OutputBinaryStream) => void = getBuildInType(\"" + field.fieldType + "\").encode;");
                    write("const decode" + field.fieldType + ": (stream: BinaryStream) => void  = getBuildInType(\"" + field.fieldType + "\").decode;");
                    break;
            }
        }
    }
}
github node-opcua / node-opcua / packages / node-opcua-generator / source / factory_code_generator.ts View on Github external
function hasComplex(schema: StructuredTypeSchema): boolean {
    for (const field of schema.fields) {
        if (field.category === FieldCategory.complex) {
            return true;
        }
    }
    return false;
}