node-opcua-schemas 2.55.0 → 2.60.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/.mocharc.yml +9 -9
- package/LICENSE +20 -20
- package/dist/source/dynamic_extension_object.js +39 -30
- package/dist/source/dynamic_extension_object.js.map +1 -1
- package/dist/source/parse_binary_xsd.js +16 -5
- package/dist/source/parse_binary_xsd.js.map +1 -1
- package/dist/source/tools.js +5 -2
- package/dist/source/tools.js.map +1 -1
- package/package.json +13 -11
- package/source/dynamic_extension_object.ts +57 -91
- package/source/index.ts +4 -4
- package/source/parse_binary_xsd.ts +55 -39
- package/source/toTypeScript.ts +101 -101
- package/source/tools.ts +190 -192
package/source/toTypeScript.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import { ConstructorFuncWithSchema, DataTypeFactory, EnumerationDefinitionSchema, StructuredTypeSchema } from "node-opcua-factory";
|
|
2
|
-
|
|
3
|
-
export function toTypeScript(dataTypeFactory: DataTypeFactory): string {
|
|
4
|
-
const enumeratedTypes: Map<string, EnumerationDefinitionSchema> = (dataTypeFactory as any)._enumerations;
|
|
5
|
-
const structuredTypes: Map<string, ConstructorFuncWithSchema> = (dataTypeFactory as any)._structureTypeConstructorByNameMap;
|
|
6
|
-
|
|
7
|
-
const declaration: Map<string, string> = new Map();
|
|
8
|
-
|
|
9
|
-
function adjustType(t: string): string {
|
|
10
|
-
if (!enumeratedTypes.has(t) && !structuredTypes.has(t)) {
|
|
11
|
-
declaration.set(t, t);
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
}
|
|
15
|
-
const l: string[] = [];
|
|
16
|
-
// enumeration
|
|
17
|
-
for (const e of enumeratedTypes.values()) {
|
|
18
|
-
l.push(`export enum ${e.name} {`);
|
|
19
|
-
// console.log((e.typedEnum as any).enumItems);
|
|
20
|
-
for (const v of Object.entries(e.enumValues as any)) {
|
|
21
|
-
const vv = parseInt(v[0], 10);
|
|
22
|
-
if (vv >= 0) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
l.push(` ${v[0]} = ${v[1]},`);
|
|
26
|
-
}
|
|
27
|
-
l.push(`}`);
|
|
28
|
-
}
|
|
29
|
-
const alreadyDone: Set<string> = new Set();
|
|
30
|
-
function dumpType(o: StructuredTypeSchema) {
|
|
31
|
-
// base type first
|
|
32
|
-
const b = o.baseType;
|
|
33
|
-
|
|
34
|
-
const bt = structuredTypes.get(b)?.schema;
|
|
35
|
-
|
|
36
|
-
if (b && !alreadyDone.has(o.baseType) && bt) {
|
|
37
|
-
dumpType(bt);
|
|
38
|
-
}
|
|
39
|
-
alreadyDone.add(o.name);
|
|
40
|
-
const ex1 = b && bt ? `extends ${b} ` : "";
|
|
41
|
-
|
|
42
|
-
if (o.baseType === "Union") {
|
|
43
|
-
const p: string[] = [];
|
|
44
|
-
|
|
45
|
-
let switchFieldName = "";
|
|
46
|
-
// find switchFieldName
|
|
47
|
-
for (const field of o.fields) {
|
|
48
|
-
if (field.switchValue === undefined) {
|
|
49
|
-
// this is the switch value field
|
|
50
|
-
switchFieldName = field.name;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// export all flavors
|
|
55
|
-
for (const field of o.fields) {
|
|
56
|
-
const name = field.name;
|
|
57
|
-
if (field.switchValue === undefined) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const a = field.isArray ? "[]" : "";
|
|
61
|
-
const fieldType = adjustType(field.schema.name);
|
|
62
|
-
l.push(`interface ${o.name}${field.switchValue} ${ex1}{`);
|
|
63
|
-
l.push(` ${switchFieldName}: ${field.switchValue};`);
|
|
64
|
-
l.push(` ${field.name}: ${fieldType}${a};`);
|
|
65
|
-
l.push(`}`);
|
|
66
|
-
p.push(`${o.name}${field.switchValue}`);
|
|
67
|
-
}
|
|
68
|
-
const pp = p.join(" | ");
|
|
69
|
-
l.push(`type ${o.name} = ${pp};`);
|
|
70
|
-
} else {
|
|
71
|
-
if (o.fields.length === 0) {
|
|
72
|
-
l.push("// tslint:disable-next-line: no-empty-interface");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
l.push(`interface ${o.name} ${ex1}{`);
|
|
76
|
-
for (const f of o.fields) {
|
|
77
|
-
if (f.documentation) {
|
|
78
|
-
l.push(` // ${f.documentation}`);
|
|
79
|
-
}
|
|
80
|
-
const isOpt = f.switchBit !== undefined ? "?" : "";
|
|
81
|
-
const fieldType = adjustType(f.schema.name);
|
|
82
|
-
if (f.isArray) {
|
|
83
|
-
l.push(` ${f.name}${isOpt}: ${fieldType}[];`);
|
|
84
|
-
} else {
|
|
85
|
-
l.push(` ${f.name}${isOpt}: ${fieldType};`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
l.push(`}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// objects
|
|
92
|
-
for (const o of structuredTypes.values()) {
|
|
93
|
-
if (alreadyDone.has(o.schema.name)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
dumpType(o.schema);
|
|
97
|
-
}
|
|
98
|
-
const opcuaTypes = [...declaration.keys()].sort().join(",\n ");
|
|
99
|
-
l.unshift(`import {\n ${opcuaTypes}\n} from "node-opcua";`);
|
|
100
|
-
return l.join("\n");
|
|
101
|
-
}
|
|
1
|
+
import { ConstructorFuncWithSchema, DataTypeFactory, EnumerationDefinitionSchema, StructuredTypeSchema } from "node-opcua-factory";
|
|
2
|
+
|
|
3
|
+
export function toTypeScript(dataTypeFactory: DataTypeFactory): string {
|
|
4
|
+
const enumeratedTypes: Map<string, EnumerationDefinitionSchema> = (dataTypeFactory as any)._enumerations;
|
|
5
|
+
const structuredTypes: Map<string, ConstructorFuncWithSchema> = (dataTypeFactory as any)._structureTypeConstructorByNameMap;
|
|
6
|
+
|
|
7
|
+
const declaration: Map<string, string> = new Map();
|
|
8
|
+
|
|
9
|
+
function adjustType(t: string): string {
|
|
10
|
+
if (!enumeratedTypes.has(t) && !structuredTypes.has(t)) {
|
|
11
|
+
declaration.set(t, t);
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
15
|
+
const l: string[] = [];
|
|
16
|
+
// enumeration
|
|
17
|
+
for (const e of enumeratedTypes.values()) {
|
|
18
|
+
l.push(`export enum ${e.name} {`);
|
|
19
|
+
// console.log((e.typedEnum as any).enumItems);
|
|
20
|
+
for (const v of Object.entries(e.enumValues as any)) {
|
|
21
|
+
const vv = parseInt(v[0], 10);
|
|
22
|
+
if (vv >= 0) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
l.push(` ${v[0]} = ${v[1]},`);
|
|
26
|
+
}
|
|
27
|
+
l.push(`}`);
|
|
28
|
+
}
|
|
29
|
+
const alreadyDone: Set<string> = new Set();
|
|
30
|
+
function dumpType(o: StructuredTypeSchema) {
|
|
31
|
+
// base type first
|
|
32
|
+
const b = o.baseType;
|
|
33
|
+
|
|
34
|
+
const bt = structuredTypes.get(b)?.schema;
|
|
35
|
+
|
|
36
|
+
if (b && !alreadyDone.has(o.baseType) && bt) {
|
|
37
|
+
dumpType(bt);
|
|
38
|
+
}
|
|
39
|
+
alreadyDone.add(o.name);
|
|
40
|
+
const ex1 = b && bt ? `extends ${b} ` : "";
|
|
41
|
+
|
|
42
|
+
if (o.baseType === "Union") {
|
|
43
|
+
const p: string[] = [];
|
|
44
|
+
|
|
45
|
+
let switchFieldName = "";
|
|
46
|
+
// find switchFieldName
|
|
47
|
+
for (const field of o.fields) {
|
|
48
|
+
if (field.switchValue === undefined) {
|
|
49
|
+
// this is the switch value field
|
|
50
|
+
switchFieldName = field.name;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// export all flavors
|
|
55
|
+
for (const field of o.fields) {
|
|
56
|
+
const name = field.name;
|
|
57
|
+
if (field.switchValue === undefined) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const a = field.isArray ? "[]" : "";
|
|
61
|
+
const fieldType = adjustType(field.schema.name);
|
|
62
|
+
l.push(`interface ${o.name}${field.switchValue} ${ex1}{`);
|
|
63
|
+
l.push(` ${switchFieldName}: ${field.switchValue};`);
|
|
64
|
+
l.push(` ${field.name}: ${fieldType}${a};`);
|
|
65
|
+
l.push(`}`);
|
|
66
|
+
p.push(`${o.name}${field.switchValue}`);
|
|
67
|
+
}
|
|
68
|
+
const pp = p.join(" | ");
|
|
69
|
+
l.push(`type ${o.name} = ${pp};`);
|
|
70
|
+
} else {
|
|
71
|
+
if (o.fields.length === 0) {
|
|
72
|
+
l.push("// tslint:disable-next-line: no-empty-interface");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
l.push(`interface ${o.name} ${ex1}{`);
|
|
76
|
+
for (const f of o.fields) {
|
|
77
|
+
if (f.documentation) {
|
|
78
|
+
l.push(` // ${f.documentation}`);
|
|
79
|
+
}
|
|
80
|
+
const isOpt = f.switchBit !== undefined ? "?" : "";
|
|
81
|
+
const fieldType = adjustType(f.schema.name);
|
|
82
|
+
if (f.isArray) {
|
|
83
|
+
l.push(` ${f.name}${isOpt}: ${fieldType}[];`);
|
|
84
|
+
} else {
|
|
85
|
+
l.push(` ${f.name}${isOpt}: ${fieldType};`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
l.push(`}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// objects
|
|
92
|
+
for (const o of structuredTypes.values()) {
|
|
93
|
+
if (alreadyDone.has(o.schema.name)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
dumpType(o.schema);
|
|
97
|
+
}
|
|
98
|
+
const opcuaTypes = [...declaration.keys()].sort().join(",\n ");
|
|
99
|
+
l.unshift(`import {\n ${opcuaTypes}\n} from "node-opcua";`);
|
|
100
|
+
return l.join("\n");
|
|
101
|
+
}
|
package/source/tools.ts
CHANGED
|
@@ -1,192 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
): StructuredTypeSchema {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const prefix = _getNamespacePart(fieldType);
|
|
93
|
-
const fieldTypeName = _adjustFieldTypeName(_removeNamespacePart(fieldType)!);
|
|
94
|
-
|
|
95
|
-
switch (prefix) {
|
|
96
|
-
case "tns":
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
field.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
field.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
field.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
field.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
field.category = FieldCategory.
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
field.
|
|
155
|
-
|
|
156
|
-
field.
|
|
157
|
-
|
|
158
|
-
field.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
schema.id
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
schema.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return _getOrCreateStructuredTypeSchema(name);
|
|
192
|
-
}
|
|
1
|
+
/* eslint-disable max-depth */
|
|
2
|
+
/* eslint-disable max-statements */
|
|
3
|
+
import {
|
|
4
|
+
buildStructuredType,
|
|
5
|
+
ConstructorFuncWithSchema,
|
|
6
|
+
DataTypeFactory,
|
|
7
|
+
FieldCategory,
|
|
8
|
+
getBuildInType,
|
|
9
|
+
getStructuredTypeSchema,
|
|
10
|
+
hasBuiltInType,
|
|
11
|
+
hasStructuredType,
|
|
12
|
+
StructuredTypeOptions,
|
|
13
|
+
StructuredTypeSchema
|
|
14
|
+
} from "node-opcua-factory";
|
|
15
|
+
import { ExpandedNodeId } from "node-opcua-nodeid";
|
|
16
|
+
|
|
17
|
+
import { createDynamicObjectConstructor } from "./dynamic_extension_object";
|
|
18
|
+
import { MapDataTypeAndEncodingIdProvider, TypeDictionary } from "./parse_binary_xsd";
|
|
19
|
+
|
|
20
|
+
function _removeNamespacePart(str?: string): string | undefined {
|
|
21
|
+
if (!str) {
|
|
22
|
+
return str;
|
|
23
|
+
}
|
|
24
|
+
const data = str.split(":");
|
|
25
|
+
return data.length > 1 ? data[1] : str;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _getNamespacePart(str: string): string {
|
|
29
|
+
return str.split(":")[0];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _adjustFieldTypeName(fieldTypeName: string): string {
|
|
33
|
+
// special cases
|
|
34
|
+
if (fieldTypeName === "String" || fieldTypeName === "CharArray") {
|
|
35
|
+
fieldTypeName = "UAString";
|
|
36
|
+
}
|
|
37
|
+
if (fieldTypeName === "Boolean") {
|
|
38
|
+
fieldTypeName = "UABoolean";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return fieldTypeName;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getOrCreateStructuredTypeSchema(
|
|
45
|
+
name: string,
|
|
46
|
+
typeDictionary: TypeDictionary,
|
|
47
|
+
dataTypeFactory: DataTypeFactory,
|
|
48
|
+
idProvider: MapDataTypeAndEncodingIdProvider
|
|
49
|
+
): StructuredTypeSchema {
|
|
50
|
+
// eslint-disable-next-line complexity
|
|
51
|
+
function _getOrCreateStructuredTypeSchema(_name: string): StructuredTypeSchema {
|
|
52
|
+
if (dataTypeFactory.hasStructuredType(_name)) {
|
|
53
|
+
return dataTypeFactory.getStructuredTypeSchema(_name);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// construct it !
|
|
57
|
+
const structuredType = typeDictionary.getStructuredTypesRawByName(_name);
|
|
58
|
+
if (!structuredType) {
|
|
59
|
+
throw new Error("Cannot find structuredType " + _name);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
structuredType.baseType = _removeNamespacePart(structuredType.baseType);
|
|
63
|
+
structuredType.baseType = structuredType.baseType ? structuredType.baseType : "ExtensionObject";
|
|
64
|
+
|
|
65
|
+
const baseSchema = typeDictionary.getStructuredTypesRawByName(structuredType.baseType);
|
|
66
|
+
|
|
67
|
+
// remove redundant fields
|
|
68
|
+
// Note :some file do no thave SourceType property and may be replicated here ..
|
|
69
|
+
// but they belongs to the base class and shall be remove/
|
|
70
|
+
// For instance DataTypeSchemaHeader => UABinaryFileDataType
|
|
71
|
+
if (baseSchema && baseSchema.fields && baseSchema.name !== "ExtensionObject") {
|
|
72
|
+
structuredType.fields = structuredType.fields.filter((field) => {
|
|
73
|
+
const name = field.name;
|
|
74
|
+
const index = baseSchema.fields.findIndex((f) => f.name === name);
|
|
75
|
+
if (index >= 0) {
|
|
76
|
+
// tslint:disable-next-line: no-console
|
|
77
|
+
console.log(
|
|
78
|
+
"Warning : find duplicated field from base structure : field name ",
|
|
79
|
+
name,
|
|
80
|
+
"baseSchema = ",
|
|
81
|
+
baseSchema.name,
|
|
82
|
+
"schema =",
|
|
83
|
+
structuredType.name
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return index < 0;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
for (const field of structuredType.fields) {
|
|
90
|
+
const fieldType = field.fieldType;
|
|
91
|
+
if (!field.schema) {
|
|
92
|
+
const prefix = _getNamespacePart(fieldType);
|
|
93
|
+
const fieldTypeName = _adjustFieldTypeName(_removeNamespacePart(fieldType)!);
|
|
94
|
+
|
|
95
|
+
switch (prefix) {
|
|
96
|
+
case "tns":
|
|
97
|
+
field.fieldType = fieldTypeName;
|
|
98
|
+
if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
99
|
+
const enumeratedType = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
100
|
+
field.category = FieldCategory.enumeration;
|
|
101
|
+
field.schema = enumeratedType;
|
|
102
|
+
} else {
|
|
103
|
+
// must be a structure then ....
|
|
104
|
+
field.category = FieldCategory.complex;
|
|
105
|
+
const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
106
|
+
field.schema = schema1;
|
|
107
|
+
// _getOrCreateStructuredTypeSchema(fieldTypeName);
|
|
108
|
+
if (!field.schema) {
|
|
109
|
+
// tslint:disable-next-line:no-console
|
|
110
|
+
console.log("cannot find schema for ", fieldTypeName);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case "ua":
|
|
115
|
+
field.fieldType = fieldTypeName;
|
|
116
|
+
if (hasBuiltInType(fieldTypeName)) {
|
|
117
|
+
field.category = FieldCategory.basic;
|
|
118
|
+
field.schema = getBuildInType(fieldTypeName);
|
|
119
|
+
} else if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
120
|
+
field.category = FieldCategory.complex;
|
|
121
|
+
field.schema = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
122
|
+
} else {
|
|
123
|
+
field.category = FieldCategory.basic;
|
|
124
|
+
// try in this
|
|
125
|
+
field.schema = _getOrCreateStructuredTypeSchema(fieldTypeName);
|
|
126
|
+
if (!field.schema) {
|
|
127
|
+
// tslint:disable-next-line:no-console
|
|
128
|
+
console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
|
|
129
|
+
} else {
|
|
130
|
+
if (hasBuiltInType(fieldTypeName)) {
|
|
131
|
+
field.category = FieldCategory.basic;
|
|
132
|
+
} else {
|
|
133
|
+
field.category = FieldCategory.complex;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case "opc":
|
|
139
|
+
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
|
|
140
|
+
field.fieldType = "NumericRange";
|
|
141
|
+
// xx console.log(" NumericRange detected here !");
|
|
142
|
+
} else {
|
|
143
|
+
field.fieldType = fieldTypeName;
|
|
144
|
+
}
|
|
145
|
+
if (!hasBuiltInType(fieldTypeName)) {
|
|
146
|
+
throw new Error("Unknown basic type " + fieldTypeName);
|
|
147
|
+
}
|
|
148
|
+
field.category = FieldCategory.basic;
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
if (dataTypeFactory.hasEnumeration(fieldTypeName)) {
|
|
152
|
+
field.category = FieldCategory.enumeration;
|
|
153
|
+
const enumeratedType = dataTypeFactory.getEnumeration(fieldTypeName);
|
|
154
|
+
field.schema = enumeratedType;
|
|
155
|
+
} else if (dataTypeFactory.hasStructuredType(fieldTypeName)) {
|
|
156
|
+
field.category = FieldCategory.complex;
|
|
157
|
+
const schema1 = dataTypeFactory.getStructuredTypeSchema(fieldTypeName);
|
|
158
|
+
field.schema = schema1;
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const schema = buildStructuredType(structuredType as StructuredTypeOptions);
|
|
166
|
+
const ids = idProvider.getDataTypeAndEncodingId(schema.name);
|
|
167
|
+
if (!ids) {
|
|
168
|
+
// this may happen if the type is abstract or if the type referes to a internal ExtnsionObject
|
|
169
|
+
// that can only exists inside an other extension object.this Type of extension object cannot
|
|
170
|
+
// instantiated as standalone object and do not have encoding nodeIds...
|
|
171
|
+
const Constructor = createDynamicObjectConstructor(schema, dataTypeFactory) as ConstructorFuncWithSchema;
|
|
172
|
+
return schema;
|
|
173
|
+
}
|
|
174
|
+
schema.id = ids.dataTypeNodeId;
|
|
175
|
+
schema.dataTypeNodeId = ids.dataTypeNodeId;
|
|
176
|
+
if (schema.id.namespace === 0 && schema.id.value === 0) {
|
|
177
|
+
return schema;
|
|
178
|
+
}
|
|
179
|
+
schema.encodingDefaultXml = ExpandedNodeId.fromNodeId(ids.xmlEncodingNodeId);
|
|
180
|
+
schema.encodingDefaultJson = ExpandedNodeId.fromNodeId(ids.jsonEncodingNodeId);
|
|
181
|
+
schema.encodingDefaultBinary = ExpandedNodeId.fromNodeId(ids.binaryEncodingNodeId);
|
|
182
|
+
|
|
183
|
+
const Constructor = createDynamicObjectConstructor(schema, dataTypeFactory) as ConstructorFuncWithSchema;
|
|
184
|
+
Constructor.encodingDefaultBinary = schema.encodingDefaultBinary;
|
|
185
|
+
Constructor.encodingDefaultXml = schema.encodingDefaultXml;
|
|
186
|
+
|
|
187
|
+
return schema;
|
|
188
|
+
}
|
|
189
|
+
return _getOrCreateStructuredTypeSchema(name);
|
|
190
|
+
}
|