node-opcua-generator
Advanced tools
Comparing version 2.4.2 to 2.5.0-alpha.0
@@ -0,0 +0,0 @@ /** |
@@ -538,4 +538,6 @@ "use strict"; | ||
const baseClass = schema.baseType; | ||
const dataTypeNodeId = getDataTypeNodeId(schema); | ||
const encodingBinaryNodeId = getEncodingBinaryId(schema); | ||
const encodingXmlNodeId = getEncodingXmlId(schema); | ||
const encodingJsonNodeId = getEncodingJsonId(schema); | ||
const needRegistration = encodingBinaryNodeId.value !== 0; | ||
@@ -561,2 +563,3 @@ // ----------------------------------------------- Options | ||
// ------------------------------------------------------------------------- | ||
write(` public static dataTypeNodeId = makeExpandedNodeId(${dataTypeNodeId.value}, ${dataTypeNodeId.namespace});`); | ||
if (encodingBinaryNodeId) { | ||
@@ -571,2 +574,8 @@ write(` public static encodingDefaultBinary = makeExpandedNodeId(${encodingBinaryNodeId.value}, ${encodingBinaryNodeId.namespace});`); | ||
} | ||
if (encodingJsonNodeId) { | ||
write(` public static encodingDefaultJson = makeExpandedNodeId(${encodingJsonNodeId.value}, ${encodingJsonNodeId.namespace});`); | ||
} | ||
else { | ||
write(" public static encodingDefaultJson = null;"); | ||
} | ||
// xx write(` static schema = schema${className};`); | ||
@@ -582,2 +591,5 @@ write_declare_class_member(write, schema); | ||
write("}"); | ||
if (dataTypeNodeId) { | ||
write(`${className}.schema.dataTypeNodeId = ${className}.dataTypeNodeId;`); | ||
} | ||
if (encodingBinaryNodeId) { | ||
@@ -589,7 +601,15 @@ write(`${className}.schema.encodingDefaultBinary = ${className}.encodingDefaultBinary;`); | ||
} | ||
if (encodingJsonNodeId) { | ||
write(`${className}.schema.encodingDefaultJson = ${className}.encodingDefaultJson;`); | ||
} | ||
if (needRegistration) { | ||
write(`registerClassDefinition("${className}", ${className});`); | ||
write(`registerClassDefinition( ${className}.dataTypeNodeId, "${className}", ${className});`); | ||
} | ||
} | ||
exports.writeStructuredType = writeStructuredType; | ||
function getDataTypeNodeId(schema) { | ||
const className = schema.name; | ||
const encodingBinarylId = node_opcua_constants_1.DataTypeIds[className]; | ||
return node_opcua_nodeid_1.coerceNodeId(encodingBinarylId); | ||
} | ||
function getEncodingBinaryId(schema) { | ||
@@ -605,2 +625,7 @@ const className = schema.name; | ||
} | ||
function getEncodingJsonId(schema) { | ||
const className = schema.name; | ||
const encodingXmlId = node_opcua_constants_1.ObjectIds[className + "_Encoding_DefaultJson"]; | ||
return node_opcua_nodeid_1.coerceNodeId(encodingXmlId); | ||
} | ||
/* eslint complexity:[0,50], max-statements: [1, 254]*/ | ||
@@ -607,0 +632,0 @@ function produce_tscript_code(schema, localSchemaFile, generatedTypescriptFilename) { |
export declare function generate(filename: string, generatedTypescriptFilename: string): Promise<void>; |
@@ -19,3 +19,6 @@ "use strict"; | ||
// | ||
const chalk = require("chalk"); | ||
const fs = require("fs"); | ||
const node_opcua_constants_1 = require("node-opcua-constants"); | ||
const node_opcua_debug_1 = require("node-opcua-debug"); | ||
const node_opcua_factory_1 = require("node-opcua-factory"); | ||
@@ -26,5 +29,7 @@ const node_opcua_schemas_1 = require("node-opcua-schemas"); | ||
const factory_code_generator_1 = require("./factory_code_generator"); | ||
const node_opcua_nodeid_1 = require("node-opcua-nodeid"); | ||
const doDebug = node_opcua_debug_1.checkDebugFlag(__filename); | ||
const debugLog = node_opcua_debug_1.make_debugLog(__filename); | ||
// Xx import * as prettier from "prettier"; | ||
const readFile = util_1.promisify(fs.readFile); | ||
const parseBinaryXSD2 = util_1.promisify(node_opcua_schemas_1.parseBinaryXSD); | ||
const f = new node_opcua_utils_1.LineFile(); | ||
@@ -38,3 +43,2 @@ function write(...args) { | ||
if (!hasInvalid) { | ||
// xx console.log("Adding Invalid Enum entry on ", enumeratedType.name); | ||
enumerationSchema.enumValues[enumerationSchema.enumValues.Invalid = 0xFFFFFFFF] = "Invalid"; | ||
@@ -115,21 +119,29 @@ } | ||
const content = yield readFile(filename, "ascii"); | ||
const typeDictionary = yield parseBinaryXSD2(content, [node_opcua_factory_1.getStandartDataTypeFactory()]); | ||
for (const key in typeDictionary.structuredTypes) { | ||
if (!typeDictionary.structuredTypes.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
const structuredType = typeDictionary.structuredTypes[key]; | ||
/* | ||
prepareStructureType(structuredType, typeDictionary); | ||
const structuredTypeSchema: StructuredTypeSchema = buildStructuredType(structuredType); | ||
typeDictionary.structuredTypes[key] = structuredTypeSchema; | ||
*/ | ||
// reapply recursive schema on field | ||
for (const field of structuredType.fields) { | ||
if (field.category === node_opcua_factory_1.FieldCategory.complex && field.fieldType === structuredType.name) { | ||
field.schema = structuredType; | ||
const idProvider = { | ||
getDataTypeAndEncodingId(name) { | ||
const dataType = node_opcua_constants_1.DataTypeIds[name] || 0; | ||
const binEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultBinary"] || 0; | ||
const xmlEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultXml"] || 0; | ||
const jsonEncoding = node_opcua_constants_1.ObjectIds[name + "_Encoding_DefaultJson"] || 0; | ||
if (dataType === undefined) { | ||
throw new Error("Cannot find " + name); | ||
} | ||
const dataTypeNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, dataType, 0); | ||
const binaryEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, binEncoding, 0); | ||
const xmlEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, xmlEncoding, 0); | ||
const jsonEncodingNodeId = new node_opcua_nodeid_1.NodeId(node_opcua_nodeid_1.NodeId.NodeIdType.NUMERIC, jsonEncoding, 0); | ||
const data = { | ||
binaryEncodingNodeId, | ||
dataTypeNodeId, | ||
jsonEncodingNodeId, | ||
xmlEncodingNodeId, | ||
}; | ||
if (doDebug) { | ||
debugLog("xxdata=", chalk.cyan(name.padEnd(43, " ")), data.dataTypeNodeId.toString().padEnd(43, " "), data.binaryEncodingNodeId.toString().padEnd(43, " ")); | ||
} | ||
return data; | ||
} | ||
} | ||
}; | ||
const dataTypeFactory = new node_opcua_factory_1.DataTypeFactory([node_opcua_factory_1.getStandartDataTypeFactory()]); | ||
yield node_opcua_schemas_1.parseBinaryXSDAsync(content, idProvider, dataTypeFactory); | ||
write(`// tslint:disable:no-this-assignment | ||
@@ -156,5 +168,7 @@ // tslint:disable:max-classes-per-file | ||
decodeUInt32, decodeUInt64, | ||
decodeUInt8, Double, | ||
decodeUInt8, | ||
decodeSByte, | ||
Double, | ||
encodeArray, encodeBoolean, | ||
encodeByte, encodeByteString, | ||
encodeSByte, encodeByte, encodeByteString, | ||
encodeDateTime, encodeDouble, | ||
@@ -257,12 +271,12 @@ encodeExpandedNodeId, encodeFloat, | ||
// make sure | ||
if (typeDictionary.structuredTypes[structuredType.baseType]) { | ||
processStructuredType(typeDictionary.structuredTypes[structuredType.baseType]); | ||
if (dataTypeFactory.hasStructuredType(structuredType.baseType)) { | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType)); | ||
} | ||
for (const field of structuredType.fields) { | ||
if (field.category === node_opcua_factory_1.FieldCategory.complex) { | ||
const fieldSchema = typeDictionary.structuredTypes[field.fieldType]; | ||
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType); | ||
processStructuredType(fieldSchema); | ||
} | ||
if (field.category === node_opcua_factory_1.FieldCategory.enumeration) { | ||
const fieldSchema = typeDictionary.enumeratedTypes[field.fieldType]; | ||
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType); | ||
processEnumeratedType(fieldSchema); | ||
@@ -273,11 +287,11 @@ } | ||
} | ||
processStructuredType(typeDictionary.structuredTypes["LocalizedText"]); | ||
processStructuredType(typeDictionary.structuredTypes["AxisInformation"]); | ||
processStructuredType(typeDictionary.structuredTypes["DiagnosticInfo"]); | ||
processStructuredType(typeDictionary.structuredTypes["SimpleAttributeOperand"]); | ||
for (const structureType in typeDictionary.structuredTypes) { | ||
if (!typeDictionary.structuredTypes.hasOwnProperty(structureType)) { | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText")); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation")); | ||
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo")); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand")); | ||
for (const structureType of dataTypeFactory.structuredTypesNames().sort()) { | ||
if (!dataTypeFactory.hasStructuredType(structureType)) { | ||
continue; | ||
} | ||
processStructuredType(typeDictionary.structuredTypes[structureType]); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType)); | ||
// if (++i > 250) { break; } | ||
@@ -284,0 +298,0 @@ } |
@@ -0,0 +0,0 @@ import { ConstructorFunc } from "node-opcua-factory"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ "use strict"; |
export {}; |
@@ -0,0 +0,0 @@ "use strict"; |
108
package.json
{ | ||
"name": "node-opcua-generator", | ||
"version": "2.4.2", | ||
"description": "pure nodejs OPCUA SDK - module -generator", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "mocha test" | ||
}, | ||
"dependencies": { | ||
"chalk": "^3.0.0", | ||
"node-opcua-assert": "^2.3.0", | ||
"node-opcua-basic-types": "^2.4.2", | ||
"node-opcua-buffer-utils": "^2.4.2", | ||
"node-opcua-constants": "^2.1.6", | ||
"node-opcua-date-time": "^2.4.2", | ||
"node-opcua-debug": "^2.4.2", | ||
"node-opcua-enum": "^2.4.2", | ||
"node-opcua-factory": "^2.4.2", | ||
"node-opcua-guid": "^2.3.0", | ||
"node-opcua-nodeid": "^2.4.2", | ||
"node-opcua-numeric-range": "^2.4.2", | ||
"node-opcua-schemas": "^2.4.2", | ||
"node-opcua-status-code": "^2.4.2", | ||
"node-opcua-utils": "^2.4.2", | ||
"node-opcua-xml2json": "^2.4.2", | ||
"prettier": "^1.19.1", | ||
"typescript": "^3.7.4", | ||
"underscore": "^1.9.2" | ||
}, | ||
"devDependencies": { | ||
"@types/prettier": "^1.19.0", | ||
"node-opcua-binary-stream": "^2.4.2", | ||
"node-opcua-extension-object": "^2.4.2", | ||
"node-opcua-packet-analyzer": "^2.4.2", | ||
"should": "13.2.3", | ||
"source-map-support": "^0.5.16" | ||
}, | ||
"author": "Etienne Rossignon", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/node-opcua/node-opcua.git" | ||
}, | ||
"keywords": [ | ||
"OPCUA", | ||
"opcua", | ||
"m2m", | ||
"iot", | ||
"opc ua", | ||
"internet of things" | ||
], | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "6e4967fd20a09317ddd00098bcfe93e92c1df510" | ||
"name": "node-opcua-generator", | ||
"version": "2.5.0-alpha.0", | ||
"description": "pure nodejs OPCUA SDK - module -generator", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"test": "mocha test" | ||
}, | ||
"dependencies": { | ||
"chalk": "^3.0.0", | ||
"node-opcua-assert": "^2.5.0-alpha.0", | ||
"node-opcua-basic-types": "^2.5.0-alpha.0", | ||
"node-opcua-buffer-utils": "^2.5.0-alpha.0", | ||
"node-opcua-constants": "^2.5.0-alpha.0", | ||
"node-opcua-date-time": "^2.5.0-alpha.0", | ||
"node-opcua-debug": "^2.5.0-alpha.0", | ||
"node-opcua-enum": "^2.5.0-alpha.0", | ||
"node-opcua-factory": "^2.5.0-alpha.0", | ||
"node-opcua-guid": "^2.5.0-alpha.0", | ||
"node-opcua-nodeid": "^2.5.0-alpha.0", | ||
"node-opcua-numeric-range": "^2.5.0-alpha.0", | ||
"node-opcua-schemas": "^2.5.0-alpha.0", | ||
"node-opcua-status-code": "^2.5.0-alpha.0", | ||
"node-opcua-utils": "^2.5.0-alpha.0", | ||
"node-opcua-xml2json": "^2.5.0-alpha.0", | ||
"prettier": "^1.19.1", | ||
"typescript": "^3.7.4", | ||
"underscore": "^1.9.2" | ||
}, | ||
"devDependencies": { | ||
"@types/prettier": "^1.19.0", | ||
"node-opcua-binary-stream": "^2.5.0-alpha.0", | ||
"node-opcua-extension-object": "^2.5.0-alpha.0", | ||
"node-opcua-packet-analyzer": "^2.5.0-alpha.0", | ||
"should": "13.2.3", | ||
"source-map-support": "^0.5.16" | ||
}, | ||
"author": "Etienne Rossignon", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/node-opcua/node-opcua.git" | ||
}, | ||
"keywords": [ | ||
"OPCUA", | ||
"opcua", | ||
"m2m", | ||
"iot", | ||
"opc ua", | ||
"internet of things" | ||
], | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "341ac6292b30304bb028ab10971dc8552ff1a35a" | ||
} |
@@ -24,3 +24,6 @@ /* istanbul ignore file */ | ||
import { ObjectIds } from "node-opcua-constants"; | ||
import { | ||
DataTypeIds, | ||
ObjectIds | ||
} from "node-opcua-constants"; | ||
import { make_debugLog } from "node-opcua-debug"; | ||
@@ -117,5 +120,5 @@ import { coerceNodeId, makeExpandedNodeId, NodeId } from "node-opcua-nodeid"; | ||
function write_enumeration_setter( | ||
write: WriteFunc, | ||
schema: StructuredTypeSchema, | ||
field: FieldType, member: string | ||
write: WriteFunc, | ||
schema: StructuredTypeSchema, | ||
field: FieldType, member: string | ||
): void { | ||
@@ -135,7 +138,7 @@ const capMember = capitalizeFirstLetter(member); | ||
function write_enumeration( | ||
write: WriteFunc, | ||
schema: StructuredTypeSchema, | ||
field: FieldType, | ||
member: string, | ||
i: number | ||
write: WriteFunc, | ||
schema: StructuredTypeSchema, | ||
field: FieldType, | ||
member: string, | ||
i: number | ||
): void { | ||
@@ -145,3 +148,3 @@ assert(!field.isArray); // would not work in this case | ||
write( | ||
` this.${field.name} = this.set${capMember}(initialize_field(schema.fields[${i}], options.${field.name}));` | ||
` this.${field.name} = this.set${capMember}(initialize_field(schema.fields[${i}], options.${field.name}));` | ||
); | ||
@@ -385,3 +388,3 @@ } | ||
write( | ||
` encodeArray(this.${member}, stream, (obj, stream1) => { obj.encode(stream1); });`); | ||
` encodeArray(this.${member}, stream, (obj, stream1) => { obj.encode(stream1); });`); | ||
} else { | ||
@@ -432,3 +435,3 @@ write(` this.${member}.encode(stream);`); | ||
// --------------------------------------------------------------- | ||
// --------------------------------------------------------------- | ||
if (_.isFunction(schema.decode)) { | ||
@@ -515,6 +518,6 @@ | ||
} else if ( | ||
field.fieldType === "Variant" || | ||
field.fieldType === "DataValue" || | ||
field.fieldType === "NodeId" || | ||
field.fieldType === "QualifiedName" || | ||
field.fieldType === "Variant" || | ||
field.fieldType === "DataValue" || | ||
field.fieldType === "NodeId" || | ||
field.fieldType === "QualifiedName" || | ||
field.fieldType === "LocalizedText" | ||
@@ -620,4 +623,6 @@ ) { | ||
const dataTypeNodeId = getDataTypeNodeId(schema); | ||
const encodingBinaryNodeId = getEncodingBinaryId(schema); | ||
const encodingXmlNodeId = getEncodingXmlId(schema); | ||
const encodingJsonNodeId = getEncodingJsonId(schema); | ||
@@ -646,2 +651,3 @@ const needRegistration = encodingBinaryNodeId.value !== 0; | ||
// ------------------------------------------------------------------------- | ||
write(` public static dataTypeNodeId = makeExpandedNodeId(${dataTypeNodeId.value}, ${dataTypeNodeId.namespace});`); | ||
if (encodingBinaryNodeId) { | ||
@@ -654,3 +660,3 @@ write(` public static encodingDefaultBinary = makeExpandedNodeId(${encodingBinaryNodeId.value}, ${encodingBinaryNodeId.namespace});` | ||
write( | ||
` public static encodingDefaultXml = makeExpandedNodeId(${encodingXmlNodeId.value}, ${encodingXmlNodeId.namespace});` | ||
` public static encodingDefaultXml = makeExpandedNodeId(${encodingXmlNodeId.value}, ${encodingXmlNodeId.namespace});` | ||
); | ||
@@ -660,2 +666,9 @@ } else { | ||
} | ||
if (encodingJsonNodeId) { | ||
write( | ||
` public static encodingDefaultJson = makeExpandedNodeId(${encodingJsonNodeId.value}, ${encodingJsonNodeId.namespace});` | ||
); | ||
} else { | ||
write(" public static encodingDefaultJson = null;"); | ||
} | ||
// xx write(` static schema = schema${className};`); | ||
@@ -676,2 +689,5 @@ | ||
if (dataTypeNodeId) { | ||
write(`${className}.schema.dataTypeNodeId = ${className}.dataTypeNodeId;`); | ||
} | ||
if (encodingBinaryNodeId) { | ||
@@ -684,8 +700,16 @@ write(`${className}.schema.encodingDefaultBinary = ${className}.encodingDefaultBinary;`); | ||
} | ||
if (encodingJsonNodeId) { | ||
write(`${className}.schema.encodingDefaultJson = ${className}.encodingDefaultJson;`); | ||
} | ||
if (needRegistration) { | ||
write(`registerClassDefinition("${className}", ${className});`); | ||
write(`registerClassDefinition( ${className}.dataTypeNodeId, "${className}", ${className});`); | ||
} | ||
} | ||
function getDataTypeNodeId(schema: StructuredTypeSchema): NodeId { | ||
const className = schema.name; | ||
const encodingBinarylId = (DataTypeIds as any)[className]; | ||
return coerceNodeId(encodingBinarylId); | ||
} | ||
function getEncodingBinaryId(schema: StructuredTypeSchema): NodeId { | ||
@@ -702,8 +726,13 @@ const className = schema.name; | ||
} | ||
function getEncodingJsonId(schema: StructuredTypeSchema): NodeId { | ||
const className = schema.name; | ||
const encodingXmlId = (ObjectIds as any)[className + "_Encoding_DefaultJson"]; | ||
return coerceNodeId(encodingXmlId); | ||
} | ||
/* eslint complexity:[0,50], max-statements: [1, 254]*/ | ||
export function produce_tscript_code( | ||
schema: StructuredTypeSchema, | ||
localSchemaFile: string, | ||
generatedTypescriptFilename: string | ||
schema: StructuredTypeSchema, | ||
localSchemaFile: string, | ||
generatedTypescriptFilename: string | ||
) { | ||
@@ -730,3 +759,3 @@ | ||
const complexTypes = schema.fields.filter( | ||
(field: FieldType) => field.category === FieldCategory.complex && field.fieldType !== schema.name); | ||
(field: FieldType) => field.category === FieldCategory.complex && field.fieldType !== schema.name); | ||
@@ -767,3 +796,3 @@ const folderForSourceFile = path.dirname(generatedTypescriptFilename); | ||
write( | ||
`import { ${schemaObjName} } from "${localSchemaFile}";` | ||
`import { ${schemaObjName} } from "${localSchemaFile}";` | ||
); | ||
@@ -788,7 +817,7 @@ write("const schema = " + schemaObjName + ";"); | ||
write( | ||
`import { ${field.fieldType} } from "${localFilename}";` | ||
`import { ${field.fieldType} } from "${localFilename}";` | ||
); | ||
} else { | ||
write( | ||
`import { ${field.fieldType} } from "../source/imports";` | ||
`import { ${field.fieldType} } from "../source/imports";` | ||
); | ||
@@ -795,0 +824,0 @@ } |
@@ -8,5 +8,15 @@ /* istanbul ignore file */ | ||
// | ||
import * as chalk from "chalk"; | ||
import * as fs from "fs"; | ||
import { assert } from "node-opcua-assert"; | ||
import { | ||
DataTypeIds, | ||
ObjectIds | ||
} from "node-opcua-constants"; | ||
import { | ||
checkDebugFlag, | ||
make_debugLog | ||
} from "node-opcua-debug"; | ||
import { | ||
EnumerationDefinitionSchema, | ||
@@ -16,11 +26,22 @@ FieldCategory, | ||
StructuredTypeSchema, | ||
DataTypeFactory, | ||
} from "node-opcua-factory"; | ||
import { EnumeratedType, parseBinaryXSD, TypeDictionary } from "node-opcua-schemas"; | ||
import { | ||
DataTypeAndEncodingId, | ||
MapDataTypeAndEncodingIdProvider, | ||
parseBinaryXSDAsync | ||
} from "node-opcua-schemas"; | ||
import { LineFile } from "node-opcua-utils"; | ||
import { promisify } from "util"; | ||
import { writeStructuredType } from "./factory_code_generator"; | ||
import { NodeId } from "node-opcua-nodeid"; | ||
import * as n from "node-opcua-numeric-range"; | ||
const doDebug = checkDebugFlag(__filename); | ||
const debugLog = make_debugLog(__filename); | ||
// Xx import * as prettier from "prettier"; | ||
const readFile = promisify(fs.readFile); | ||
const parseBinaryXSD2 = promisify(parseBinaryXSD); | ||
@@ -38,3 +59,2 @@ const f = new LineFile(); | ||
if (!hasInvalid) { | ||
// xx console.log("Adding Invalid Enum entry on ", enumeratedType.name); | ||
enumerationSchema.enumValues[enumerationSchema.enumValues.Invalid = 0xFFFFFFFF] = "Invalid"; | ||
@@ -128,4 +148,2 @@ } | ||
import * as n from "node-opcua-numeric-range"; | ||
export async function generate( | ||
@@ -140,26 +158,35 @@ filename: string, | ||
const typeDictionary = await parseBinaryXSD2(content, [getStandartDataTypeFactory()]); | ||
for (const key in typeDictionary.structuredTypes) { | ||
if (!typeDictionary.structuredTypes.hasOwnProperty(key)) { | ||
continue; | ||
const idProvider: MapDataTypeAndEncodingIdProvider = { | ||
getDataTypeAndEncodingId(name: string): DataTypeAndEncodingId { | ||
const dataType = (DataTypeIds as any)[name] || 0; | ||
const binEncoding = (ObjectIds as any)[name + "_Encoding_DefaultBinary"] || 0; | ||
const xmlEncoding = (ObjectIds as any)[name + "_Encoding_DefaultXml"] || 0; | ||
const jsonEncoding = (ObjectIds as any)[name + "_Encoding_DefaultJson"] || 0; | ||
if (dataType === undefined) { | ||
throw new Error("Cannot find " + name); | ||
} | ||
const dataTypeNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, dataType, 0); | ||
const binaryEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, binEncoding, 0); | ||
const xmlEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, xmlEncoding, 0); | ||
const jsonEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, jsonEncoding, 0); | ||
const data: DataTypeAndEncodingId = { | ||
binaryEncodingNodeId, | ||
dataTypeNodeId, | ||
jsonEncodingNodeId, | ||
xmlEncodingNodeId, | ||
}; | ||
if (doDebug) { | ||
debugLog("xxdata=", chalk.cyan(name.padEnd(43, " ")), | ||
data.dataTypeNodeId.toString().padEnd(43, " "), | ||
data.binaryEncodingNodeId.toString().padEnd(43, " ")); | ||
} | ||
return data; | ||
} | ||
const structuredType = typeDictionary.structuredTypes[key]; | ||
}; | ||
/* | ||
prepareStructureType(structuredType, typeDictionary); | ||
const dataTypeFactory = new DataTypeFactory([getStandartDataTypeFactory()]); | ||
await parseBinaryXSDAsync(content, idProvider, dataTypeFactory); | ||
const structuredTypeSchema: StructuredTypeSchema = buildStructuredType(structuredType); | ||
typeDictionary.structuredTypes[key] = structuredTypeSchema; | ||
*/ | ||
// reapply recursive schema on field | ||
for (const field of structuredType.fields) { | ||
if (field.category === FieldCategory.complex && field.fieldType === structuredType.name) { | ||
field.schema = structuredType; | ||
} | ||
} | ||
} | ||
write(`// tslint:disable:no-this-assignment | ||
write( | ||
`// tslint:disable:no-this-assignment | ||
// tslint:disable:max-classes-per-file | ||
@@ -185,5 +212,7 @@ // tslint:disable:no-empty-interface | ||
decodeUInt32, decodeUInt64, | ||
decodeUInt8, Double, | ||
decodeUInt8, | ||
decodeSByte, | ||
Double, | ||
encodeArray, encodeBoolean, | ||
encodeByte, encodeByteString, | ||
encodeSByte, encodeByte, encodeByteString, | ||
encodeDateTime, encodeDouble, | ||
@@ -293,14 +322,14 @@ encodeExpandedNodeId, encodeFloat, | ||
alreadyDone[structuredType.name] = structuredType; | ||
// make sure | ||
if (typeDictionary.structuredTypes[structuredType.baseType]) { | ||
processStructuredType(typeDictionary.structuredTypes[structuredType.baseType]); | ||
if (dataTypeFactory.hasStructuredType(structuredType.baseType)) { | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType)); | ||
} | ||
for (const field of structuredType.fields) { | ||
if (field.category === FieldCategory.complex) { | ||
const fieldSchema = typeDictionary.structuredTypes[field.fieldType]; | ||
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType); | ||
processStructuredType(fieldSchema); | ||
} | ||
if (field.category === FieldCategory.enumeration) { | ||
const fieldSchema = typeDictionary.enumeratedTypes[field.fieldType]; | ||
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType)!; | ||
processEnumeratedType(fieldSchema); | ||
@@ -312,13 +341,12 @@ } | ||
processStructuredType(typeDictionary.structuredTypes["LocalizedText"]); | ||
processStructuredType(typeDictionary.structuredTypes["AxisInformation"]); | ||
processStructuredType(typeDictionary.structuredTypes["DiagnosticInfo"]); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText")); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation")); | ||
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo")); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand")); | ||
processStructuredType(typeDictionary.structuredTypes["SimpleAttributeOperand"]); | ||
for (const structureType in typeDictionary.structuredTypes) { | ||
if (!typeDictionary.structuredTypes.hasOwnProperty(structureType)) { | ||
for (const structureType of dataTypeFactory.structuredTypesNames().sort()) { | ||
if (!dataTypeFactory.hasStructuredType(structureType)) { | ||
continue; | ||
} | ||
processStructuredType(typeDictionary.structuredTypes[structureType]); | ||
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType)); | ||
// if (++i > 250) { break; } | ||
@@ -325,0 +353,0 @@ } |
@@ -0,0 +0,0 @@ /* istanbul ignore file */ |
@@ -0,0 +0,0 @@ /* istanbul ignore file */ |
@@ -0,0 +0,0 @@ /* istanbul ignore file */ |
{ | ||
"extends" : "../tsconfig.json", | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "source", | ||
"outDir": "dist" | ||
"outDir": "dist", | ||
"composite": true | ||
}, | ||
"files": [ | ||
"source/index.ts", | ||
"source/opcua_code_generator.ts", | ||
"source/generate_extension_object_code.ts" | ||
"include": [ | ||
"source/**/*.ts" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../node-opcua-assert" | ||
}, | ||
{ | ||
"path": "../node-opcua-basic-types" | ||
}, | ||
{ | ||
"path": "../node-opcua-buffer-utils" | ||
}, | ||
{ | ||
"path": "../node-opcua-constants" | ||
}, | ||
{ | ||
"path": "../node-opcua-date-time" | ||
}, | ||
{ | ||
"path": "../node-opcua-debug" | ||
}, | ||
{ | ||
"path": "../node-opcua-enum" | ||
}, | ||
{ | ||
"path": "../node-opcua-factory" | ||
}, | ||
{ | ||
"path": "../node-opcua-guid" | ||
}, | ||
{ | ||
"path": "../node-opcua-nodeid" | ||
}, | ||
{ | ||
"path": "../node-opcua-numeric-range" | ||
}, | ||
{ | ||
"path": "../node-opcua-schemas" | ||
}, | ||
{ | ||
"path": "../node-opcua-status-code" | ||
}, | ||
{ | ||
"path": "../node-opcua-utils" | ||
}, | ||
{ | ||
"path": "../node-opcua-xml2json" | ||
}, | ||
{ | ||
"path": "../node-opcua-binary-stream" | ||
}, | ||
{ | ||
"path": "../node-opcua-extension-object" | ||
}, | ||
{ | ||
"path": "../node-opcua-packet-analyzer" | ||
} | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
329351
2536
1