node-opcua-schemas 2.70.3 → 2.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/source/dynamic_extension_object.d.ts +22 -22
- package/dist/source/dynamic_extension_object.js +594 -598
- package/dist/source/dynamic_extension_object.js.map +1 -1
- package/dist/source/index.d.ts +4 -4
- package/dist/source/index.js +20 -20
- package/dist/source/parse_binary_xsd.d.ts +44 -44
- package/dist/source/parse_binary_xsd.js +346 -346
- package/dist/source/toTypeScript.d.ts +2 -2
- package/dist/source/toTypeScript.js +99 -99
- package/dist/source/tools.d.ts +3 -3
- package/dist/source/tools.js +163 -163
- package/package.json +13 -13
- package/source/dynamic_extension_object.ts +7 -11
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DataTypeFactory } from "node-opcua-factory";
|
|
2
|
-
export declare function toTypeScript(dataTypeFactory: DataTypeFactory): string;
|
|
1
|
+
import { DataTypeFactory } from "node-opcua-factory";
|
|
2
|
+
export declare function toTypeScript(dataTypeFactory: DataTypeFactory): string;
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toTypeScript = void 0;
|
|
4
|
-
function toTypeScript(dataTypeFactory) {
|
|
5
|
-
const enumeratedTypes = dataTypeFactory._enumerations;
|
|
6
|
-
const structuredTypes = dataTypeFactory._structureTypeConstructorByNameMap;
|
|
7
|
-
const declaration = new Map();
|
|
8
|
-
function adjustType(t) {
|
|
9
|
-
if (!enumeratedTypes.has(t) && !structuredTypes.has(t)) {
|
|
10
|
-
declaration.set(t, t);
|
|
11
|
-
}
|
|
12
|
-
return t;
|
|
13
|
-
}
|
|
14
|
-
const l = [];
|
|
15
|
-
// enumeration
|
|
16
|
-
for (const e of enumeratedTypes.values()) {
|
|
17
|
-
l.push(`export enum ${e.name} {`);
|
|
18
|
-
// console.log((e.typedEnum as any).enumItems);
|
|
19
|
-
for (const v of Object.entries(e.enumValues)) {
|
|
20
|
-
const vv = parseInt(v[0], 10);
|
|
21
|
-
if (vv >= 0) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
l.push(` ${v[0]} = ${v[1]},`);
|
|
25
|
-
}
|
|
26
|
-
l.push(`}`);
|
|
27
|
-
}
|
|
28
|
-
const alreadyDone = new Set();
|
|
29
|
-
function dumpType(o) {
|
|
30
|
-
var _a;
|
|
31
|
-
// base type first
|
|
32
|
-
const b = o.baseType;
|
|
33
|
-
const bt = (_a = structuredTypes.get(b)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
34
|
-
if (b && !alreadyDone.has(o.baseType) && bt) {
|
|
35
|
-
dumpType(bt);
|
|
36
|
-
}
|
|
37
|
-
alreadyDone.add(o.name);
|
|
38
|
-
const ex1 = b && bt ? `extends ${b} ` : "";
|
|
39
|
-
if (o.baseType === "Union") {
|
|
40
|
-
const p = [];
|
|
41
|
-
let switchFieldName = "";
|
|
42
|
-
// find switchFieldName
|
|
43
|
-
for (const field of o.fields) {
|
|
44
|
-
if (field.switchValue === undefined) {
|
|
45
|
-
// this is the switch value field
|
|
46
|
-
switchFieldName = field.name;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// export all flavors
|
|
51
|
-
for (const field of o.fields) {
|
|
52
|
-
const name = field.name;
|
|
53
|
-
if (field.switchValue === undefined) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const a = field.isArray ? "[]" : "";
|
|
57
|
-
const fieldType = adjustType(field.schema.name);
|
|
58
|
-
l.push(`interface ${o.name}${field.switchValue} ${ex1}{`);
|
|
59
|
-
l.push(` ${switchFieldName}: ${field.switchValue};`);
|
|
60
|
-
l.push(` ${field.name}: ${fieldType}${a};`);
|
|
61
|
-
l.push(`}`);
|
|
62
|
-
p.push(`${o.name}${field.switchValue}`);
|
|
63
|
-
}
|
|
64
|
-
const pp = p.join(" | ");
|
|
65
|
-
l.push(`type ${o.name} = ${pp};`);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
if (o.fields.length === 0) {
|
|
69
|
-
l.push("// tslint:disable-next-line: no-empty-interface");
|
|
70
|
-
}
|
|
71
|
-
l.push(`interface ${o.name} ${ex1}{`);
|
|
72
|
-
for (const f of o.fields) {
|
|
73
|
-
if (f.documentation) {
|
|
74
|
-
l.push(` // ${f.documentation}`);
|
|
75
|
-
}
|
|
76
|
-
const isOpt = f.switchBit !== undefined ? "?" : "";
|
|
77
|
-
const fieldType = adjustType(f.schema.name);
|
|
78
|
-
if (f.isArray) {
|
|
79
|
-
l.push(` ${f.name}${isOpt}: ${fieldType}[];`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
l.push(` ${f.name}${isOpt}: ${fieldType};`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
l.push(`}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// objects
|
|
89
|
-
for (const o of structuredTypes.values()) {
|
|
90
|
-
if (alreadyDone.has(o.schema.name)) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
dumpType(o.schema);
|
|
94
|
-
}
|
|
95
|
-
const opcuaTypes = [...declaration.keys()].sort().join(",\n ");
|
|
96
|
-
l.unshift(`import {\n ${opcuaTypes}\n} from "node-opcua";`);
|
|
97
|
-
return l.join("\n");
|
|
98
|
-
}
|
|
99
|
-
exports.toTypeScript = toTypeScript;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toTypeScript = void 0;
|
|
4
|
+
function toTypeScript(dataTypeFactory) {
|
|
5
|
+
const enumeratedTypes = dataTypeFactory._enumerations;
|
|
6
|
+
const structuredTypes = dataTypeFactory._structureTypeConstructorByNameMap;
|
|
7
|
+
const declaration = new Map();
|
|
8
|
+
function adjustType(t) {
|
|
9
|
+
if (!enumeratedTypes.has(t) && !structuredTypes.has(t)) {
|
|
10
|
+
declaration.set(t, t);
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
const l = [];
|
|
15
|
+
// enumeration
|
|
16
|
+
for (const e of enumeratedTypes.values()) {
|
|
17
|
+
l.push(`export enum ${e.name} {`);
|
|
18
|
+
// console.log((e.typedEnum as any).enumItems);
|
|
19
|
+
for (const v of Object.entries(e.enumValues)) {
|
|
20
|
+
const vv = parseInt(v[0], 10);
|
|
21
|
+
if (vv >= 0) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
l.push(` ${v[0]} = ${v[1]},`);
|
|
25
|
+
}
|
|
26
|
+
l.push(`}`);
|
|
27
|
+
}
|
|
28
|
+
const alreadyDone = new Set();
|
|
29
|
+
function dumpType(o) {
|
|
30
|
+
var _a;
|
|
31
|
+
// base type first
|
|
32
|
+
const b = o.baseType;
|
|
33
|
+
const bt = (_a = structuredTypes.get(b)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
34
|
+
if (b && !alreadyDone.has(o.baseType) && bt) {
|
|
35
|
+
dumpType(bt);
|
|
36
|
+
}
|
|
37
|
+
alreadyDone.add(o.name);
|
|
38
|
+
const ex1 = b && bt ? `extends ${b} ` : "";
|
|
39
|
+
if (o.baseType === "Union") {
|
|
40
|
+
const p = [];
|
|
41
|
+
let switchFieldName = "";
|
|
42
|
+
// find switchFieldName
|
|
43
|
+
for (const field of o.fields) {
|
|
44
|
+
if (field.switchValue === undefined) {
|
|
45
|
+
// this is the switch value field
|
|
46
|
+
switchFieldName = field.name;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// export all flavors
|
|
51
|
+
for (const field of o.fields) {
|
|
52
|
+
const name = field.name;
|
|
53
|
+
if (field.switchValue === undefined) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const a = field.isArray ? "[]" : "";
|
|
57
|
+
const fieldType = adjustType(field.schema.name);
|
|
58
|
+
l.push(`interface ${o.name}${field.switchValue} ${ex1}{`);
|
|
59
|
+
l.push(` ${switchFieldName}: ${field.switchValue};`);
|
|
60
|
+
l.push(` ${field.name}: ${fieldType}${a};`);
|
|
61
|
+
l.push(`}`);
|
|
62
|
+
p.push(`${o.name}${field.switchValue}`);
|
|
63
|
+
}
|
|
64
|
+
const pp = p.join(" | ");
|
|
65
|
+
l.push(`type ${o.name} = ${pp};`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
if (o.fields.length === 0) {
|
|
69
|
+
l.push("// tslint:disable-next-line: no-empty-interface");
|
|
70
|
+
}
|
|
71
|
+
l.push(`interface ${o.name} ${ex1}{`);
|
|
72
|
+
for (const f of o.fields) {
|
|
73
|
+
if (f.documentation) {
|
|
74
|
+
l.push(` // ${f.documentation}`);
|
|
75
|
+
}
|
|
76
|
+
const isOpt = f.switchBit !== undefined ? "?" : "";
|
|
77
|
+
const fieldType = adjustType(f.schema.name);
|
|
78
|
+
if (f.isArray) {
|
|
79
|
+
l.push(` ${f.name}${isOpt}: ${fieldType}[];`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
l.push(` ${f.name}${isOpt}: ${fieldType};`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
l.push(`}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// objects
|
|
89
|
+
for (const o of structuredTypes.values()) {
|
|
90
|
+
if (alreadyDone.has(o.schema.name)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
dumpType(o.schema);
|
|
94
|
+
}
|
|
95
|
+
const opcuaTypes = [...declaration.keys()].sort().join(",\n ");
|
|
96
|
+
l.unshift(`import {\n ${opcuaTypes}\n} from "node-opcua";`);
|
|
97
|
+
return l.join("\n");
|
|
98
|
+
}
|
|
99
|
+
exports.toTypeScript = toTypeScript;
|
|
100
100
|
//# sourceMappingURL=toTypeScript.js.map
|
package/dist/source/tools.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypeFactory, StructuredTypeSchema } from "node-opcua-factory";
|
|
2
|
-
import { MapDataTypeAndEncodingIdProvider, TypeDictionary } from "./parse_binary_xsd";
|
|
3
|
-
export declare function getOrCreateStructuredTypeSchema(name: string, typeDictionary: TypeDictionary, dataTypeFactory: DataTypeFactory, idProvider: MapDataTypeAndEncodingIdProvider): StructuredTypeSchema;
|
|
1
|
+
import { DataTypeFactory, StructuredTypeSchema } from "node-opcua-factory";
|
|
2
|
+
import { MapDataTypeAndEncodingIdProvider, TypeDictionary } from "./parse_binary_xsd";
|
|
3
|
+
export declare function getOrCreateStructuredTypeSchema(name: string, typeDictionary: TypeDictionary, dataTypeFactory: DataTypeFactory, idProvider: MapDataTypeAndEncodingIdProvider): StructuredTypeSchema;
|
package/dist/source/tools.js
CHANGED
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOrCreateStructuredTypeSchema = void 0;
|
|
4
|
-
/* eslint-disable max-depth */
|
|
5
|
-
/* eslint-disable max-statements */
|
|
6
|
-
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
7
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
8
|
-
const dynamic_extension_object_1 = require("./dynamic_extension_object");
|
|
9
|
-
function _removeNamespacePart(str) {
|
|
10
|
-
if (!str) {
|
|
11
|
-
return str;
|
|
12
|
-
}
|
|
13
|
-
const data = str.split(":");
|
|
14
|
-
return data.length > 1 ? data[1] : str;
|
|
15
|
-
}
|
|
16
|
-
function _getNamespacePart(str) {
|
|
17
|
-
return str.split(":")[0];
|
|
18
|
-
}
|
|
19
|
-
function _adjustFieldTypeName(fieldTypeName) {
|
|
20
|
-
// special cases
|
|
21
|
-
if (fieldTypeName === "String" || fieldTypeName === "CharArray") {
|
|
22
|
-
fieldTypeName = "UAString";
|
|
23
|
-
}
|
|
24
|
-
if (fieldTypeName === "Boolean") {
|
|
25
|
-
fieldTypeName = "UABoolean";
|
|
26
|
-
}
|
|
27
|
-
return fieldTypeName;
|
|
28
|
-
}
|
|
29
|
-
function getOrCreateStructuredTypeSchema(name, typeDictionary, dataTypeFactory, idProvider) {
|
|
30
|
-
// eslint-disable-next-line complexity
|
|
31
|
-
function _getOrCreateStructuredTypeSchema(_name) {
|
|
32
|
-
if (dataTypeFactory.hasStructuredType(_name)) {
|
|
33
|
-
return dataTypeFactory.getStructuredTypeSchema(_name);
|
|
34
|
-
}
|
|
35
|
-
// construct it !
|
|
36
|
-
const structuredType = typeDictionary.getStructuredTypesRawByName(_name);
|
|
37
|
-
if (!structuredType) {
|
|
38
|
-
throw new Error("Cannot find structuredType " + _name);
|
|
39
|
-
}
|
|
40
|
-
structuredType.baseType = _removeNamespacePart(structuredType.baseType);
|
|
41
|
-
structuredType.baseType = structuredType.baseType ? structuredType.baseType : "ExtensionObject";
|
|
42
|
-
const baseSchema = typeDictionary.getStructuredTypesRawByName(structuredType.baseType);
|
|
43
|
-
// remove redundant fields
|
|
44
|
-
// Note :some file do no thave SourceType property and may be replicated here ..
|
|
45
|
-
// but they belongs to the base class and shall be remove/
|
|
46
|
-
// For instance DataTypeSchemaHeader => UABinaryFileDataType
|
|
47
|
-
if (baseSchema && baseSchema.fields && baseSchema.name !== "ExtensionObject") {
|
|
48
|
-
structuredType.fields = structuredType.fields.filter((field) => {
|
|
49
|
-
const name = field.name;
|
|
50
|
-
const index = baseSchema.fields.findIndex((f) => f.name === name);
|
|
51
|
-
if (index >= 0) {
|
|
52
|
-
// tslint:disable-next-line: no-console
|
|
53
|
-
console.log("Warning : find duplicated field from base structure : field name ", name, "baseSchema = ", baseSchema.name, "schema =", structuredType.name);
|
|
54
|
-
}
|
|
55
|
-
return index < 0;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
for (const field of structuredType.fields) {
|
|
59
|
-
const fieldType = field.fieldType;
|
|
60
|
-
if (!field.schema) {
|
|
61
|
-
const prefix = _getNamespacePart(fieldType);
|
|
62
|
-
const fieldTypeName = _adjustFieldTypeName(_removeNamespacePart(fieldType));
|
|
63
|
-
switch (prefix) {
|
|
64
|
-
case "tns":
|
|
65
|
-
field.fieldType = fieldTypeName;
|
|
66
|
-
if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
67
|
-
const enumeratedType = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
68
|
-
field.category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
69
|
-
field.schema = enumeratedType;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
// must be a structure then ....
|
|
73
|
-
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
74
|
-
const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
75
|
-
field.schema = schema1;
|
|
76
|
-
// _getOrCreateStructuredTypeSchema(fieldTypeName);
|
|
77
|
-
if (!field.schema) {
|
|
78
|
-
// tslint:disable-next-line:no-console
|
|
79
|
-
console.log("cannot find schema for ", fieldTypeName);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
case "ua":
|
|
84
|
-
field.fieldType = fieldTypeName;
|
|
85
|
-
if ((0, node_opcua_factory_1.hasBuiltInType)(fieldTypeName)) {
|
|
86
|
-
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
87
|
-
field.schema = (0, node_opcua_factory_1.getBuildInType)(fieldTypeName);
|
|
88
|
-
}
|
|
89
|
-
else if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
90
|
-
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
91
|
-
field.schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
95
|
-
// try in this
|
|
96
|
-
field.schema = _getOrCreateStructuredTypeSchema(fieldTypeName);
|
|
97
|
-
if (!field.schema) {
|
|
98
|
-
// tslint:disable-next-line:no-console
|
|
99
|
-
console.log("What should I do ??", fieldTypeName, " ", (0, node_opcua_factory_1.hasStructuredType)(fieldTypeName));
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
if ((0, node_opcua_factory_1.hasBuiltInType)(fieldTypeName)) {
|
|
103
|
-
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
break;
|
|
111
|
-
case "opc":
|
|
112
|
-
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
|
|
113
|
-
field.fieldType = "NumericRange";
|
|
114
|
-
// xx console.log(" NumericRange detected here !");
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
field.fieldType = fieldTypeName;
|
|
118
|
-
}
|
|
119
|
-
if (!(0, node_opcua_factory_1.hasBuiltInType)(fieldTypeName)) {
|
|
120
|
-
throw new Error("Unknown basic type " + fieldTypeName);
|
|
121
|
-
}
|
|
122
|
-
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
123
|
-
break;
|
|
124
|
-
default:
|
|
125
|
-
if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
126
|
-
field.category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
127
|
-
const enumeratedType = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
128
|
-
field.schema = enumeratedType;
|
|
129
|
-
}
|
|
130
|
-
else if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
131
|
-
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
132
|
-
const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
133
|
-
field.schema = schema1;
|
|
134
|
-
}
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const schema = (0, node_opcua_factory_1.buildStructuredType)(structuredType);
|
|
140
|
-
const ids = idProvider.getDataTypeAndEncodingId(schema.name);
|
|
141
|
-
if (!ids) {
|
|
142
|
-
// this may happen if the type is abstract or if the type referes to a internal ExtnsionObject
|
|
143
|
-
// that can only exists inside an other extension object.this Type of extension object cannot
|
|
144
|
-
// instantiated as standalone object and do not have encoding nodeIds...
|
|
145
|
-
const Constructor = (0, dynamic_extension_object_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
|
|
146
|
-
return schema;
|
|
147
|
-
}
|
|
148
|
-
schema.id = ids.dataTypeNodeId;
|
|
149
|
-
schema.dataTypeNodeId = ids.dataTypeNodeId;
|
|
150
|
-
if (schema.id.namespace === 0 && schema.id.value === 0) {
|
|
151
|
-
return schema;
|
|
152
|
-
}
|
|
153
|
-
schema.encodingDefaultXml = node_opcua_nodeid_1.ExpandedNodeId.fromNodeId(ids.xmlEncodingNodeId);
|
|
154
|
-
schema.encodingDefaultJson = node_opcua_nodeid_1.ExpandedNodeId.fromNodeId(ids.jsonEncodingNodeId);
|
|
155
|
-
schema.encodingDefaultBinary = node_opcua_nodeid_1.ExpandedNodeId.fromNodeId(ids.binaryEncodingNodeId);
|
|
156
|
-
const Constructor = (0, dynamic_extension_object_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
|
|
157
|
-
Constructor.encodingDefaultBinary = schema.encodingDefaultBinary;
|
|
158
|
-
Constructor.encodingDefaultXml = schema.encodingDefaultXml;
|
|
159
|
-
return schema;
|
|
160
|
-
}
|
|
161
|
-
return _getOrCreateStructuredTypeSchema(name);
|
|
162
|
-
}
|
|
163
|
-
exports.getOrCreateStructuredTypeSchema = getOrCreateStructuredTypeSchema;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrCreateStructuredTypeSchema = void 0;
|
|
4
|
+
/* eslint-disable max-depth */
|
|
5
|
+
/* eslint-disable max-statements */
|
|
6
|
+
const node_opcua_factory_1 = require("node-opcua-factory");
|
|
7
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
8
|
+
const dynamic_extension_object_1 = require("./dynamic_extension_object");
|
|
9
|
+
function _removeNamespacePart(str) {
|
|
10
|
+
if (!str) {
|
|
11
|
+
return str;
|
|
12
|
+
}
|
|
13
|
+
const data = str.split(":");
|
|
14
|
+
return data.length > 1 ? data[1] : str;
|
|
15
|
+
}
|
|
16
|
+
function _getNamespacePart(str) {
|
|
17
|
+
return str.split(":")[0];
|
|
18
|
+
}
|
|
19
|
+
function _adjustFieldTypeName(fieldTypeName) {
|
|
20
|
+
// special cases
|
|
21
|
+
if (fieldTypeName === "String" || fieldTypeName === "CharArray") {
|
|
22
|
+
fieldTypeName = "UAString";
|
|
23
|
+
}
|
|
24
|
+
if (fieldTypeName === "Boolean") {
|
|
25
|
+
fieldTypeName = "UABoolean";
|
|
26
|
+
}
|
|
27
|
+
return fieldTypeName;
|
|
28
|
+
}
|
|
29
|
+
function getOrCreateStructuredTypeSchema(name, typeDictionary, dataTypeFactory, idProvider) {
|
|
30
|
+
// eslint-disable-next-line complexity
|
|
31
|
+
function _getOrCreateStructuredTypeSchema(_name) {
|
|
32
|
+
if (dataTypeFactory.hasStructuredType(_name)) {
|
|
33
|
+
return dataTypeFactory.getStructuredTypeSchema(_name);
|
|
34
|
+
}
|
|
35
|
+
// construct it !
|
|
36
|
+
const structuredType = typeDictionary.getStructuredTypesRawByName(_name);
|
|
37
|
+
if (!structuredType) {
|
|
38
|
+
throw new Error("Cannot find structuredType " + _name);
|
|
39
|
+
}
|
|
40
|
+
structuredType.baseType = _removeNamespacePart(structuredType.baseType);
|
|
41
|
+
structuredType.baseType = structuredType.baseType ? structuredType.baseType : "ExtensionObject";
|
|
42
|
+
const baseSchema = typeDictionary.getStructuredTypesRawByName(structuredType.baseType);
|
|
43
|
+
// remove redundant fields
|
|
44
|
+
// Note :some file do no thave SourceType property and may be replicated here ..
|
|
45
|
+
// but they belongs to the base class and shall be remove/
|
|
46
|
+
// For instance DataTypeSchemaHeader => UABinaryFileDataType
|
|
47
|
+
if (baseSchema && baseSchema.fields && baseSchema.name !== "ExtensionObject") {
|
|
48
|
+
structuredType.fields = structuredType.fields.filter((field) => {
|
|
49
|
+
const name = field.name;
|
|
50
|
+
const index = baseSchema.fields.findIndex((f) => f.name === name);
|
|
51
|
+
if (index >= 0) {
|
|
52
|
+
// tslint:disable-next-line: no-console
|
|
53
|
+
console.log("Warning : find duplicated field from base structure : field name ", name, "baseSchema = ", baseSchema.name, "schema =", structuredType.name);
|
|
54
|
+
}
|
|
55
|
+
return index < 0;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
for (const field of structuredType.fields) {
|
|
59
|
+
const fieldType = field.fieldType;
|
|
60
|
+
if (!field.schema) {
|
|
61
|
+
const prefix = _getNamespacePart(fieldType);
|
|
62
|
+
const fieldTypeName = _adjustFieldTypeName(_removeNamespacePart(fieldType));
|
|
63
|
+
switch (prefix) {
|
|
64
|
+
case "tns":
|
|
65
|
+
field.fieldType = fieldTypeName;
|
|
66
|
+
if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
67
|
+
const enumeratedType = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
68
|
+
field.category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
69
|
+
field.schema = enumeratedType;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// must be a structure then ....
|
|
73
|
+
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
74
|
+
const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
75
|
+
field.schema = schema1;
|
|
76
|
+
// _getOrCreateStructuredTypeSchema(fieldTypeName);
|
|
77
|
+
if (!field.schema) {
|
|
78
|
+
// tslint:disable-next-line:no-console
|
|
79
|
+
console.log("cannot find schema for ", fieldTypeName);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case "ua":
|
|
84
|
+
field.fieldType = fieldTypeName;
|
|
85
|
+
if ((0, node_opcua_factory_1.hasBuiltInType)(fieldTypeName)) {
|
|
86
|
+
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
87
|
+
field.schema = (0, node_opcua_factory_1.getBuildInType)(fieldTypeName);
|
|
88
|
+
}
|
|
89
|
+
else if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
90
|
+
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
91
|
+
field.schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
95
|
+
// try in this
|
|
96
|
+
field.schema = _getOrCreateStructuredTypeSchema(fieldTypeName);
|
|
97
|
+
if (!field.schema) {
|
|
98
|
+
// tslint:disable-next-line:no-console
|
|
99
|
+
console.log("What should I do ??", fieldTypeName, " ", (0, node_opcua_factory_1.hasStructuredType)(fieldTypeName));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if ((0, node_opcua_factory_1.hasBuiltInType)(fieldTypeName)) {
|
|
103
|
+
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case "opc":
|
|
112
|
+
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
|
|
113
|
+
field.fieldType = "NumericRange";
|
|
114
|
+
// xx console.log(" NumericRange detected here !");
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
field.fieldType = fieldTypeName;
|
|
118
|
+
}
|
|
119
|
+
if (!(0, node_opcua_factory_1.hasBuiltInType)(fieldTypeName)) {
|
|
120
|
+
throw new Error("Unknown basic type " + fieldTypeName);
|
|
121
|
+
}
|
|
122
|
+
field.category = node_opcua_factory_1.FieldCategory.basic;
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
126
|
+
field.category = node_opcua_factory_1.FieldCategory.enumeration;
|
|
127
|
+
const enumeratedType = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
128
|
+
field.schema = enumeratedType;
|
|
129
|
+
}
|
|
130
|
+
else if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
131
|
+
field.category = node_opcua_factory_1.FieldCategory.complex;
|
|
132
|
+
const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
133
|
+
field.schema = schema1;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const schema = (0, node_opcua_factory_1.buildStructuredType)(structuredType);
|
|
140
|
+
const ids = idProvider.getDataTypeAndEncodingId(schema.name);
|
|
141
|
+
if (!ids) {
|
|
142
|
+
// this may happen if the type is abstract or if the type referes to a internal ExtnsionObject
|
|
143
|
+
// that can only exists inside an other extension object.this Type of extension object cannot
|
|
144
|
+
// instantiated as standalone object and do not have encoding nodeIds...
|
|
145
|
+
const Constructor = (0, dynamic_extension_object_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
|
|
146
|
+
return schema;
|
|
147
|
+
}
|
|
148
|
+
schema.id = ids.dataTypeNodeId;
|
|
149
|
+
schema.dataTypeNodeId = ids.dataTypeNodeId;
|
|
150
|
+
if (schema.id.namespace === 0 && schema.id.value === 0) {
|
|
151
|
+
return schema;
|
|
152
|
+
}
|
|
153
|
+
schema.encodingDefaultXml = node_opcua_nodeid_1.ExpandedNodeId.fromNodeId(ids.xmlEncodingNodeId);
|
|
154
|
+
schema.encodingDefaultJson = node_opcua_nodeid_1.ExpandedNodeId.fromNodeId(ids.jsonEncodingNodeId);
|
|
155
|
+
schema.encodingDefaultBinary = node_opcua_nodeid_1.ExpandedNodeId.fromNodeId(ids.binaryEncodingNodeId);
|
|
156
|
+
const Constructor = (0, dynamic_extension_object_1.createDynamicObjectConstructor)(schema, dataTypeFactory);
|
|
157
|
+
Constructor.encodingDefaultBinary = schema.encodingDefaultBinary;
|
|
158
|
+
Constructor.encodingDefaultXml = schema.encodingDefaultXml;
|
|
159
|
+
return schema;
|
|
160
|
+
}
|
|
161
|
+
return _getOrCreateStructuredTypeSchema(name);
|
|
162
|
+
}
|
|
163
|
+
exports.getOrCreateStructuredTypeSchema = getOrCreateStructuredTypeSchema;
|
|
164
164
|
//# sourceMappingURL=tools.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-schemas",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.71.0",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -schemas",
|
|
5
5
|
"main": "dist/source/index.js",
|
|
6
6
|
"types": "dist/source/index.d.ts",
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"node-opcua-assert": "2.66.0",
|
|
16
|
-
"node-opcua-binary-stream": "2.
|
|
17
|
-
"node-opcua-data-model": "2.
|
|
18
|
-
"node-opcua-debug": "2.
|
|
19
|
-
"node-opcua-enum": "2.
|
|
20
|
-
"node-opcua-extension-object": "2.
|
|
21
|
-
"node-opcua-factory": "2.
|
|
22
|
-
"node-opcua-nodeid": "2.
|
|
23
|
-
"node-opcua-utils": "2.
|
|
24
|
-
"node-opcua-variant": "2.
|
|
25
|
-
"node-opcua-xml2json": "2.
|
|
16
|
+
"node-opcua-binary-stream": "2.71.0",
|
|
17
|
+
"node-opcua-data-model": "2.71.0",
|
|
18
|
+
"node-opcua-debug": "2.71.0",
|
|
19
|
+
"node-opcua-enum": "2.71.0",
|
|
20
|
+
"node-opcua-extension-object": "2.71.0",
|
|
21
|
+
"node-opcua-factory": "2.71.0",
|
|
22
|
+
"node-opcua-nodeid": "2.71.0",
|
|
23
|
+
"node-opcua-utils": "2.71.0",
|
|
24
|
+
"node-opcua-variant": "2.71.0",
|
|
25
|
+
"node-opcua-xml2json": "2.71.0",
|
|
26
26
|
"thenify": "^3.3.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"node-opcua-packet-analyzer": "2.
|
|
29
|
+
"node-opcua-packet-analyzer": "2.71.0"
|
|
30
30
|
},
|
|
31
31
|
"author": "Etienne Rossignon",
|
|
32
32
|
"license": "MIT",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"internet of things"
|
|
44
44
|
],
|
|
45
45
|
"homepage": "http://node-opcua.github.io/",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "10f7cc1e1cd30dfef75adad9cb709a78401fabf3"
|
|
47
47
|
}
|
|
@@ -382,10 +382,6 @@ export class DynamicExtensionObject extends ExtensionObject {
|
|
|
382
382
|
|
|
383
383
|
public get schema(): StructuredTypeSchema {
|
|
384
384
|
const r = _private.get(this);
|
|
385
|
-
if (!r) {
|
|
386
|
-
console.log("cannot find private stuff for", this.constructor.name);
|
|
387
|
-
console.log(new Error());
|
|
388
|
-
}
|
|
389
385
|
return r.schema!;
|
|
390
386
|
}
|
|
391
387
|
|
|
@@ -400,7 +396,7 @@ export class DynamicExtensionObject extends ExtensionObject {
|
|
|
400
396
|
interface AnyConstructable {
|
|
401
397
|
schema: StructuredTypeSchema;
|
|
402
398
|
possibleFields: string[];
|
|
403
|
-
new
|
|
399
|
+
new(options?: any, schema?: StructuredTypeSchema, factory?: DataTypeFactory): any;
|
|
404
400
|
}
|
|
405
401
|
|
|
406
402
|
export type AnyConstructorFunc = AnyConstructable;
|
|
@@ -440,11 +436,11 @@ class UnionBaseClass extends BaseUAObject {
|
|
|
440
436
|
debugLog(this.schema);
|
|
441
437
|
throw new Error(
|
|
442
438
|
"union must have only one choice in " +
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
439
|
+
JSON.stringify(options) +
|
|
440
|
+
"\n found while investigating " +
|
|
441
|
+
field.name +
|
|
442
|
+
"\n switchFieldName = " +
|
|
443
|
+
switchFieldName
|
|
448
444
|
);
|
|
449
445
|
}
|
|
450
446
|
|
|
@@ -643,7 +639,7 @@ export function createDynamicObjectConstructor(schema: StructuredTypeSchema, dat
|
|
|
643
639
|
schema.baseType !== "OptionSet" &&
|
|
644
640
|
schema.baseType !== "DataTypeDescription" &&
|
|
645
641
|
schema.baseType !== "DataTypeDefinition" &&
|
|
646
|
-
schema.baseType !== "EnumValueType" &&
|
|
642
|
+
schema.baseType !== "EnumValueType" &&
|
|
647
643
|
schema.baseType !== "Structure"
|
|
648
644
|
) {
|
|
649
645
|
try {
|