node-opcua-schemas 2.97.0 → 2.98.1

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.
@@ -1,355 +1,355 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-schemas
4
- */
5
- // tslint:disable:object-literal-sort-keys
6
- // tslint:disable:no-empty
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.parseBinaryXSDAsync = exports.parseBinaryXSD = exports.InternalTypeDictionary = void 0;
18
- const chalk = require("chalk");
19
- const node_opcua_assert_1 = require("node-opcua-assert");
20
- const node_opcua_debug_1 = require("node-opcua-debug");
21
- const node_opcua_factory_1 = require("node-opcua-factory");
22
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
23
- const node_opcua_xml2json_1 = require("node-opcua-xml2json");
24
- const tools_1 = require("./tools");
25
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
26
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
27
- function w(s, l) {
28
- return s.padEnd(l).substring(0, l);
29
- }
30
- const predefinedType = {
31
- "opc:Bit": 1,
32
- "opc:Boolean": 1,
33
- "opc:Byte": 1,
34
- "opc:ByteString": 1,
35
- "opc:Char": 1,
36
- "opc:CharArray": 1,
37
- "opc:DateTime": 1,
38
- "opc:Double": 1,
39
- "opc:Float": 1,
40
- "opc:Guid": 1,
41
- "opc:Int16": 1,
42
- "opc:Int32": 1,
43
- "opc:Int64": 1,
44
- "opc:SByte": 1,
45
- "opc:String": 1,
46
- "opc:UInt16": 1,
47
- "opc:UInt32": 1,
48
- "opc:UInt64": 1,
49
- "ua:ByteStringNodeId": 1,
50
- "ua:DataValue": 1,
51
- "ua:DiagnosticInfo": 1,
52
- "ua:ExpandedNodeId": 1,
53
- "ua:ExtensionObject": 1,
54
- "ua:FourByteNodeId": 1,
55
- "ua:GuidNodeId": 1,
56
- "ua:LocalizedText": 1,
57
- "ua:NodeId": 1,
58
- "ua:NodeIdType": 1,
59
- "ua:NumericNodeId": 1,
60
- "ua:QualifiedName": 1,
61
- "ua:StatusCode": 1,
62
- "ua:StringNodeId": 1,
63
- "ua:TwoByteNodeId": 1,
64
- "ua:Variant": 1,
65
- "ua:XmlElement": 1
66
- };
67
- class InternalTypeDictionary {
68
- constructor() {
69
- this.targetNamespace = "";
70
- this.defaultByteOrder = "";
71
- this.imports = [];
72
- this.structuredTypesRaw = {};
73
- this.enumeratedTypesRaw = {};
74
- // tns: "http://opcfoundation.org/a/b"
75
- this._namespaces = {};
76
- /** */
77
- }
78
- addEnumeration(name, e) {
79
- this.enumeratedTypesRaw[name] = e;
80
- }
81
- getEnumerations() {
82
- return Object.values(this.enumeratedTypesRaw);
83
- }
84
- getStructures() {
85
- return Object.values(this.structuredTypesRaw);
86
- }
87
- addStructureRaw(structuredType) {
88
- this.structuredTypesRaw[structuredType.name] = structuredType;
89
- }
90
- getStructuredTypesRawByName(name) {
91
- name = name.split(":")[1] || name;
92
- return this.structuredTypesRaw[name];
93
- }
94
- }
95
- exports.InternalTypeDictionary = InternalTypeDictionary;
96
- /* tslint:disable:object-literal-shorthand */
97
- const state0 = {
98
- init: () => {
99
- const a = 1;
100
- },
101
- parser: {
102
- TypeDictionary: {
103
- init: function (name, attributes) {
104
- this.typeDictionary = this.engine.typeDictionary;
105
- this.typeDictionary.defaultByteOrder = attributes.DefaultByteOrder;
106
- this.typeDictionary.targetNamespace = attributes.TargetNamespace;
107
- for (const [k, v] of Object.entries(attributes)) {
108
- if (k.match(/xmlns:/)) {
109
- const ns = k.split(":")[1];
110
- this.typeDictionary._namespaces[ns] = v;
111
- this.typeDictionary._namespaces[v] = ns;
112
- }
113
- }
114
- },
115
- parser: {
116
- Import: {
117
- init: function (name, attributes) {
118
- this.parent.typeDictionary.imports.push(attributes.Namespace);
119
- },
120
- finish: function () {
121
- // _register_namespace_uri(this.text);
122
- // istanbul ignore next
123
- if (doDebug) {
124
- debugLog("Import NameSpace = ", this.attrs.Namespace, " Location", this.attrs.Location);
125
- }
126
- }
127
- },
128
- EnumeratedType: {
129
- init: function () {
130
- this.typescriptDefinition = "";
131
- // istanbul ignore next
132
- if (doDebug) {
133
- debugLog(chalk.cyan("EnumeratedType Name="), w(this.attrs.Name, 40), "LengthInBits=", this.attrs.LengthInBits);
134
- }
135
- this.enumeratedType = {
136
- enumeratedValues: {},
137
- lengthInBits: parseInt(this.attrs.LengthInBits, 10),
138
- name: this.attrs.Name
139
- };
140
- this.typescriptDefinition += `enum ${this.enumeratedType.name} {`;
141
- },
142
- parser: {
143
- Documentation: {
144
- finish: function () {
145
- this.parent.enumeratedType.documentation = this.text;
146
- }
147
- },
148
- EnumeratedValue: {
149
- finish: function () {
150
- // istanbul ignore next
151
- if (doDebug) {
152
- debugLog(" EnumeratedValue Name=", w(this.attrs.Name, 40), " Value=", this.attrs.Value);
153
- }
154
- const key = this.attrs.Name;
155
- const value = parseInt(this.attrs.Value, 10);
156
- const _enum = this.parent.enumeratedType.enumeratedValues;
157
- _enum[(_enum[key] = value)] = key;
158
- this.parent.typescriptDefinition += `\n ${key} = ${value},`;
159
- }
160
- }
161
- },
162
- finish: function () {
163
- this.typescriptDefinition += `\n}`;
164
- this.parent.typeDictionary.addEnumeration(this.attrs.Name, this.enumeratedType);
165
- // istanbul ignore next
166
- if (doDebug) {
167
- debugLog(" this.typescriptDefinition = ", this.typescriptDefinition);
168
- }
169
- }
170
- },
171
- StructuredType: {
172
- init: function () {
173
- // istanbul ignore next
174
- if (doDebug) {
175
- debugLog(chalk.cyan("StructureType Name="), chalk.green(this.attrs.Name), " BaseType=", this.attrs.BaseType);
176
- }
177
- const baseType = this.attrs.BaseType;
178
- const structuredType = {
179
- name: this.attrs.Name,
180
- baseType,
181
- fields: []
182
- };
183
- this.structuredType = structuredType;
184
- },
185
- parser: {
186
- Field: {
187
- finish: function () {
188
- if (this.attrs.SourceType) {
189
- // ignore this field, This is a repetition of the base type field with same name
190
- return;
191
- }
192
- // istanbul ignore next
193
- if (doDebug) {
194
- debugLog(chalk.yellow(" field Name="), w(this.attrs.Name, 40), chalk.yellow(" typeName="), w(this.attrs.TypeName, 40), this.attrs.LengthField
195
- ? chalk.yellow(" lengthField= ") + w(this.attrs.LengthField, 40)
196
- : "", this.attrs.SwitchField
197
- ? chalk.yellow(" SwitchField= ") + w(this.attrs.SwitchField, 40)
198
- : "", this.attrs.SwitchValue !== undefined
199
- ? chalk.yellow(" SwitchValue= ") + w(this.attrs.SwitchValue, 40)
200
- : ""
201
- // chalk.yellow(" lengthField="), w(this.attrs.LengthField, 40)
202
- );
203
- }
204
- const field = {
205
- name: this.attrs.Name,
206
- fieldType: this.attrs.TypeName
207
- };
208
- const structuredType = this.parent.structuredType;
209
- if (field.fieldType === "opc:Bit") {
210
- // do something to collect bits but ignore them as field
211
- structuredType.bitFields = structuredType.bitFields || [];
212
- const length = this.attrs.Length || 1;
213
- structuredType.bitFields.push({ name: field.name, length });
214
- return;
215
- }
216
- if (this.attrs.LengthField) {
217
- field.isArray = true;
218
- const n = structuredType.fields.length - 1;
219
- structuredType.fields[n] = field;
220
- }
221
- else {
222
- structuredType.fields.push(field);
223
- }
224
- if (this.attrs.SwitchField) {
225
- // field is optional and can be omitted
226
- const switchField = this.attrs.SwitchField;
227
- if (this.attrs.SwitchValue) {
228
- // we are in a union
229
- field.switchValue = parseInt(this.attrs.SwitchValue, 10);
230
- // istanbul ignore next
231
- if (doDebug) {
232
- debugLog("field", field.name, " is part of a union => ", switchField, " value #", field.switchValue);
233
- }
234
- // sometimes (like in Milo, baseType attribute is not specified)
235
- if (!this.parent.attrs.baseType) {
236
- this.parent.attrs.baseType = "Union";
237
- this.parent.structuredType.baseType = "Union";
238
- }
239
- }
240
- else {
241
- field.switchBit = structuredType.bitFields
242
- ? structuredType.bitFields.findIndex((x) => x.name === switchField)
243
- : -2;
244
- // istanbul ignore next
245
- if (doDebug) {
246
- debugLog("field", field.name, " is optional => ", switchField, "bit #", field.switchBit);
247
- }
248
- }
249
- }
250
- }
251
- }
252
- },
253
- finish: function () {
254
- (0, node_opcua_assert_1.default)(this.attrs.Name === this.structuredType.name);
255
- this.parent.typeDictionary.addStructureRaw(this.structuredType);
256
- }
257
- }
258
- }
259
- }
260
- }
261
- };
262
- function parseBinaryXSD(xmlString, idProvider, dataTypeFactory, callback) {
263
- const parser = new node_opcua_xml2json_1.Xml2Json(state0);
264
- const typeDictionary = new InternalTypeDictionary();
265
- parser.typeDictionary = typeDictionary;
266
- if (!xmlString || xmlString.length === 0) {
267
- return callback();
268
- }
269
- parser.parseString(xmlString, (err) => {
270
- // resolve and prepare enumerations
271
- for (const enumeratedType of typeDictionary.getEnumerations()) {
272
- if (Object.keys(enumeratedType.enumeratedValues).length >= 1) {
273
- const e = new node_opcua_factory_1.EnumerationDefinitionSchema(node_opcua_nodeid_1.NodeId.nullNodeId, {
274
- lengthInBits: enumeratedType.lengthInBits || 32,
275
- enumValues: enumeratedType.enumeratedValues,
276
- name: enumeratedType.name
277
- });
278
- dataTypeFactory.registerEnumeration(e);
279
- }
280
- }
281
- // istanbul ignore next
282
- if (doDebug) {
283
- debugLog("------------------------------- Resolving complex Type");
284
- typeDictionary.getStructures().map((x) => debugLog(x.name));
285
- }
286
- // create area in navigation order
287
- function createExplorationOrder() {
288
- const array = [];
289
- const _map = {};
290
- function alreadyVisited(name) {
291
- name = name.split(":")[1] || name;
292
- return !!_map[name];
293
- }
294
- function markAsVisited(name) {
295
- name = name.split(":")[1] || name;
296
- _map[name] = "1";
297
- }
298
- function visitStructure(structuredType) {
299
- if (!structuredType || structuredType.name === "ua:ExtensionObject") {
300
- return;
301
- }
302
- if (alreadyVisited(structuredType.name)) {
303
- return;
304
- }
305
- markAsVisited(structuredType.name);
306
- if (structuredType.baseType && structuredType.baseType !== "ua:ExtensionObject") {
307
- const base = typeDictionary.getStructuredTypesRawByName(structuredType.baseType);
308
- if (base && base.baseType) {
309
- doDebug && debugLog(" investigating base", chalk.cyan(base.name));
310
- visitStructure(base);
311
- }
312
- }
313
- for (const f of structuredType.fields) {
314
- const s = typeDictionary.getStructuredTypesRawByName(f.fieldType);
315
- if (s !== structuredType && s) {
316
- visitStructure(s);
317
- }
318
- else {
319
- markAsVisited(f.fieldType);
320
- }
321
- }
322
- doDebug && debugLog("processing ", chalk.cyan(structuredType.name));
323
- array.push(structuredType);
324
- }
325
- for (const structuredType of typeDictionary.getStructures()) {
326
- visitStructure(structuredType);
327
- }
328
- return array;
329
- }
330
- // resolve complex types
331
- const schemaInVisitingOrder = createExplorationOrder();
332
- for (const structuredType of schemaInVisitingOrder) {
333
- (0, tools_1.getOrCreateStructuredTypeSchema)(structuredType.name, typeDictionary, dataTypeFactory, idProvider);
334
- }
335
- callback(err);
336
- });
337
- }
338
- exports.parseBinaryXSD = parseBinaryXSD;
339
- function parseBinaryXSDAsync(xmlString, idProvider, dataTypeFactory) {
340
- return __awaiter(this, void 0, void 0, function* () {
341
- debugLog("parseBinaryXSDAsync");
342
- return new Promise((resolve, reject) => {
343
- parseBinaryXSD(xmlString, idProvider, dataTypeFactory, (err) => {
344
- if (err) {
345
- reject(err);
346
- }
347
- else {
348
- resolve();
349
- }
350
- });
351
- });
352
- });
353
- }
354
- exports.parseBinaryXSDAsync = parseBinaryXSDAsync;
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-schemas
4
+ */
5
+ // tslint:disable:object-literal-sort-keys
6
+ // tslint:disable:no-empty
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.parseBinaryXSDAsync = exports.parseBinaryXSD = exports.InternalTypeDictionary = void 0;
18
+ const chalk = require("chalk");
19
+ const node_opcua_assert_1 = require("node-opcua-assert");
20
+ const node_opcua_debug_1 = require("node-opcua-debug");
21
+ const node_opcua_factory_1 = require("node-opcua-factory");
22
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
23
+ const node_opcua_xml2json_1 = require("node-opcua-xml2json");
24
+ const tools_1 = require("./tools");
25
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
26
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
27
+ function w(s, l) {
28
+ return s.padEnd(l).substring(0, l);
29
+ }
30
+ const predefinedType = {
31
+ "opc:Bit": 1,
32
+ "opc:Boolean": 1,
33
+ "opc:Byte": 1,
34
+ "opc:ByteString": 1,
35
+ "opc:Char": 1,
36
+ "opc:CharArray": 1,
37
+ "opc:DateTime": 1,
38
+ "opc:Double": 1,
39
+ "opc:Float": 1,
40
+ "opc:Guid": 1,
41
+ "opc:Int16": 1,
42
+ "opc:Int32": 1,
43
+ "opc:Int64": 1,
44
+ "opc:SByte": 1,
45
+ "opc:String": 1,
46
+ "opc:UInt16": 1,
47
+ "opc:UInt32": 1,
48
+ "opc:UInt64": 1,
49
+ "ua:ByteStringNodeId": 1,
50
+ "ua:DataValue": 1,
51
+ "ua:DiagnosticInfo": 1,
52
+ "ua:ExpandedNodeId": 1,
53
+ "ua:ExtensionObject": 1,
54
+ "ua:FourByteNodeId": 1,
55
+ "ua:GuidNodeId": 1,
56
+ "ua:LocalizedText": 1,
57
+ "ua:NodeId": 1,
58
+ "ua:NodeIdType": 1,
59
+ "ua:NumericNodeId": 1,
60
+ "ua:QualifiedName": 1,
61
+ "ua:StatusCode": 1,
62
+ "ua:StringNodeId": 1,
63
+ "ua:TwoByteNodeId": 1,
64
+ "ua:Variant": 1,
65
+ "ua:XmlElement": 1
66
+ };
67
+ class InternalTypeDictionary {
68
+ constructor() {
69
+ this.targetNamespace = "";
70
+ this.defaultByteOrder = "";
71
+ this.imports = [];
72
+ this.structuredTypesRaw = {};
73
+ this.enumeratedTypesRaw = {};
74
+ // tns: "http://opcfoundation.org/a/b"
75
+ this._namespaces = {};
76
+ /** */
77
+ }
78
+ addEnumeration(name, e) {
79
+ this.enumeratedTypesRaw[name] = e;
80
+ }
81
+ getEnumerations() {
82
+ return Object.values(this.enumeratedTypesRaw);
83
+ }
84
+ getStructures() {
85
+ return Object.values(this.structuredTypesRaw);
86
+ }
87
+ addStructureRaw(structuredType) {
88
+ this.structuredTypesRaw[structuredType.name] = structuredType;
89
+ }
90
+ getStructuredTypesRawByName(name) {
91
+ name = name.split(":")[1] || name;
92
+ return this.structuredTypesRaw[name];
93
+ }
94
+ }
95
+ exports.InternalTypeDictionary = InternalTypeDictionary;
96
+ /* tslint:disable:object-literal-shorthand */
97
+ const state0 = {
98
+ init: () => {
99
+ const a = 1;
100
+ },
101
+ parser: {
102
+ TypeDictionary: {
103
+ init: function (name, attributes) {
104
+ this.typeDictionary = this.engine.typeDictionary;
105
+ this.typeDictionary.defaultByteOrder = attributes.DefaultByteOrder;
106
+ this.typeDictionary.targetNamespace = attributes.TargetNamespace;
107
+ for (const [k, v] of Object.entries(attributes)) {
108
+ if (k.match(/xmlns:/)) {
109
+ const ns = k.split(":")[1];
110
+ this.typeDictionary._namespaces[ns] = v;
111
+ this.typeDictionary._namespaces[v] = ns;
112
+ }
113
+ }
114
+ },
115
+ parser: {
116
+ Import: {
117
+ init: function (name, attributes) {
118
+ this.parent.typeDictionary.imports.push(attributes.Namespace);
119
+ },
120
+ finish: function () {
121
+ // _register_namespace_uri(this.text);
122
+ // istanbul ignore next
123
+ if (doDebug) {
124
+ debugLog("Import NameSpace = ", this.attrs.Namespace, " Location", this.attrs.Location);
125
+ }
126
+ }
127
+ },
128
+ EnumeratedType: {
129
+ init: function () {
130
+ this.typescriptDefinition = "";
131
+ // istanbul ignore next
132
+ if (doDebug) {
133
+ debugLog(chalk.cyan("EnumeratedType Name="), w(this.attrs.Name, 40), "LengthInBits=", this.attrs.LengthInBits);
134
+ }
135
+ this.enumeratedType = {
136
+ enumeratedValues: {},
137
+ lengthInBits: parseInt(this.attrs.LengthInBits, 10),
138
+ name: this.attrs.Name
139
+ };
140
+ this.typescriptDefinition += `enum ${this.enumeratedType.name} {`;
141
+ },
142
+ parser: {
143
+ Documentation: {
144
+ finish: function () {
145
+ this.parent.enumeratedType.documentation = this.text;
146
+ }
147
+ },
148
+ EnumeratedValue: {
149
+ finish: function () {
150
+ // istanbul ignore next
151
+ if (doDebug) {
152
+ debugLog(" EnumeratedValue Name=", w(this.attrs.Name, 40), " Value=", this.attrs.Value);
153
+ }
154
+ const key = this.attrs.Name;
155
+ const value = parseInt(this.attrs.Value, 10);
156
+ const _enum = this.parent.enumeratedType.enumeratedValues;
157
+ _enum[(_enum[key] = value)] = key;
158
+ this.parent.typescriptDefinition += `\n ${key} = ${value},`;
159
+ }
160
+ }
161
+ },
162
+ finish: function () {
163
+ this.typescriptDefinition += `\n}`;
164
+ this.parent.typeDictionary.addEnumeration(this.attrs.Name, this.enumeratedType);
165
+ // istanbul ignore next
166
+ if (doDebug) {
167
+ debugLog(" this.typescriptDefinition = ", this.typescriptDefinition);
168
+ }
169
+ }
170
+ },
171
+ StructuredType: {
172
+ init: function () {
173
+ // istanbul ignore next
174
+ if (doDebug) {
175
+ debugLog(chalk.cyan("StructureType Name="), chalk.green(this.attrs.Name), " BaseType=", this.attrs.BaseType);
176
+ }
177
+ const baseType = this.attrs.BaseType;
178
+ const structuredType = {
179
+ name: this.attrs.Name,
180
+ baseType,
181
+ fields: []
182
+ };
183
+ this.structuredType = structuredType;
184
+ },
185
+ parser: {
186
+ Field: {
187
+ finish: function () {
188
+ if (this.attrs.SourceType) {
189
+ // ignore this field, This is a repetition of the base type field with same name
190
+ return;
191
+ }
192
+ // istanbul ignore next
193
+ if (doDebug) {
194
+ debugLog(chalk.yellow(" field Name="), w(this.attrs.Name, 40), chalk.yellow(" typeName="), w(this.attrs.TypeName, 40), this.attrs.LengthField
195
+ ? chalk.yellow(" lengthField= ") + w(this.attrs.LengthField, 40)
196
+ : "", this.attrs.SwitchField
197
+ ? chalk.yellow(" SwitchField= ") + w(this.attrs.SwitchField, 40)
198
+ : "", this.attrs.SwitchValue !== undefined
199
+ ? chalk.yellow(" SwitchValue= ") + w(this.attrs.SwitchValue, 40)
200
+ : ""
201
+ // chalk.yellow(" lengthField="), w(this.attrs.LengthField, 40)
202
+ );
203
+ }
204
+ const field = {
205
+ name: this.attrs.Name,
206
+ fieldType: this.attrs.TypeName
207
+ };
208
+ const structuredType = this.parent.structuredType;
209
+ if (field.fieldType === "opc:Bit") {
210
+ // do something to collect bits but ignore them as field
211
+ structuredType.bitFields = structuredType.bitFields || [];
212
+ const length = this.attrs.Length || 1;
213
+ structuredType.bitFields.push({ name: field.name, length });
214
+ return;
215
+ }
216
+ if (this.attrs.LengthField) {
217
+ field.isArray = true;
218
+ const n = structuredType.fields.length - 1;
219
+ structuredType.fields[n] = field;
220
+ }
221
+ else {
222
+ structuredType.fields.push(field);
223
+ }
224
+ if (this.attrs.SwitchField) {
225
+ // field is optional and can be omitted
226
+ const switchField = this.attrs.SwitchField;
227
+ if (this.attrs.SwitchValue) {
228
+ // we are in a union
229
+ field.switchValue = parseInt(this.attrs.SwitchValue, 10);
230
+ // istanbul ignore next
231
+ if (doDebug) {
232
+ debugLog("field", field.name, " is part of a union => ", switchField, " value #", field.switchValue);
233
+ }
234
+ // sometimes (like in Milo, baseType attribute is not specified)
235
+ if (!this.parent.attrs.baseType) {
236
+ this.parent.attrs.baseType = "Union";
237
+ this.parent.structuredType.baseType = "Union";
238
+ }
239
+ }
240
+ else {
241
+ field.switchBit = structuredType.bitFields
242
+ ? structuredType.bitFields.findIndex((x) => x.name === switchField)
243
+ : -2;
244
+ // istanbul ignore next
245
+ if (doDebug) {
246
+ debugLog("field", field.name, " is optional => ", switchField, "bit #", field.switchBit);
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+ },
253
+ finish: function () {
254
+ (0, node_opcua_assert_1.default)(this.attrs.Name === this.structuredType.name);
255
+ this.parent.typeDictionary.addStructureRaw(this.structuredType);
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+ };
262
+ function parseBinaryXSD(xmlString, idProvider, dataTypeFactory, callback) {
263
+ const parser = new node_opcua_xml2json_1.Xml2Json(state0);
264
+ const typeDictionary = new InternalTypeDictionary();
265
+ parser.typeDictionary = typeDictionary;
266
+ if (!xmlString || xmlString.length === 0) {
267
+ return callback();
268
+ }
269
+ parser.parseString(xmlString, (err) => {
270
+ // resolve and prepare enumerations
271
+ for (const enumeratedType of typeDictionary.getEnumerations()) {
272
+ if (Object.keys(enumeratedType.enumeratedValues).length >= 1) {
273
+ const e = new node_opcua_factory_1.EnumerationDefinitionSchema(node_opcua_nodeid_1.NodeId.nullNodeId, {
274
+ lengthInBits: enumeratedType.lengthInBits || 32,
275
+ enumValues: enumeratedType.enumeratedValues,
276
+ name: enumeratedType.name
277
+ });
278
+ dataTypeFactory.registerEnumeration(e);
279
+ }
280
+ }
281
+ // istanbul ignore next
282
+ if (doDebug) {
283
+ debugLog("------------------------------- Resolving complex Type");
284
+ typeDictionary.getStructures().map((x) => debugLog(x.name));
285
+ }
286
+ // create area in navigation order
287
+ function createExplorationOrder() {
288
+ const array = [];
289
+ const _map = {};
290
+ function alreadyVisited(name) {
291
+ name = name.split(":")[1] || name;
292
+ return !!_map[name];
293
+ }
294
+ function markAsVisited(name) {
295
+ name = name.split(":")[1] || name;
296
+ _map[name] = "1";
297
+ }
298
+ function visitStructure(structuredType) {
299
+ if (!structuredType || structuredType.name === "ua:ExtensionObject") {
300
+ return;
301
+ }
302
+ if (alreadyVisited(structuredType.name)) {
303
+ return;
304
+ }
305
+ markAsVisited(structuredType.name);
306
+ if (structuredType.baseType && structuredType.baseType !== "ua:ExtensionObject") {
307
+ const base = typeDictionary.getStructuredTypesRawByName(structuredType.baseType);
308
+ if (base && base.baseType) {
309
+ doDebug && debugLog(" investigating base", chalk.cyan(base.name));
310
+ visitStructure(base);
311
+ }
312
+ }
313
+ for (const f of structuredType.fields) {
314
+ const s = typeDictionary.getStructuredTypesRawByName(f.fieldType);
315
+ if (s !== structuredType && s) {
316
+ visitStructure(s);
317
+ }
318
+ else {
319
+ markAsVisited(f.fieldType);
320
+ }
321
+ }
322
+ doDebug && debugLog("processing ", chalk.cyan(structuredType.name));
323
+ array.push(structuredType);
324
+ }
325
+ for (const structuredType of typeDictionary.getStructures()) {
326
+ visitStructure(structuredType);
327
+ }
328
+ return array;
329
+ }
330
+ // resolve complex types
331
+ const schemaInVisitingOrder = createExplorationOrder();
332
+ for (const structuredType of schemaInVisitingOrder) {
333
+ (0, tools_1.getOrCreateStructuredTypeSchema)(structuredType.name, typeDictionary, dataTypeFactory, idProvider);
334
+ }
335
+ callback(err);
336
+ });
337
+ }
338
+ exports.parseBinaryXSD = parseBinaryXSD;
339
+ function parseBinaryXSDAsync(xmlString, idProvider, dataTypeFactory) {
340
+ return __awaiter(this, void 0, void 0, function* () {
341
+ debugLog("parseBinaryXSDAsync");
342
+ return new Promise((resolve, reject) => {
343
+ parseBinaryXSD(xmlString, idProvider, dataTypeFactory, (err) => {
344
+ if (err) {
345
+ reject(err);
346
+ }
347
+ else {
348
+ resolve();
349
+ }
350
+ });
351
+ });
352
+ });
353
+ }
354
+ exports.parseBinaryXSDAsync = parseBinaryXSDAsync;
355
355
  //# sourceMappingURL=parse_binary_xsd.js.map