node-opcua-schemas 2.76.0 → 2.76.2

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