basyx-typescript-sdk 1.0.3 → 1.1.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/README.md +50 -0
- package/dist/lib/aas-dataformat-xml/index.d.ts +1 -0
- package/dist/lib/aas-dataformat-xml/index.js +1 -0
- package/dist/lib/aas-dataformat-xml/xmlization.d.ts +3 -0
- package/dist/lib/aas-dataformat-xml/xmlization.js +1332 -0
- package/dist/models/BaSyxEnvironment.d.ts +3 -0
- package/dist/models/BaSyxEnvironment.js +3 -0
- package/package.json +11 -2
|
@@ -0,0 +1,1332 @@
|
|
|
1
|
+
import { jsonization } from '@aas-core-works/aas-core3.0-typescript';
|
|
2
|
+
import { AdministrativeInformation, AnnotatedRelationshipElement, AssetAdministrationShell, AssetInformation, AssetKind, BasicEventElement, Blob, Capability, ConceptDescription, DataSpecificationIec61360, DataTypeDefXsd, EmbeddedDataSpecification, Entity, Extension, File, Key, KeyTypes, LangStringDefinitionTypeIec61360, LangStringNameType, LangStringPreferredNameTypeIec61360, LangStringShortNameTypeIec61360, LangStringTextType, LevelType, MultiLanguageProperty, Operation, OperationVariable, Property, Qualifier, Range, Reference, ReferenceElement, ReferenceTypes, RelationshipElement, Resource, SpecificAssetId, Submodel, SubmodelElementCollection, SubmodelElementList, ValueList, ValueReferencePair, } from '@aas-core-works/aas-core3.0-typescript/types';
|
|
3
|
+
import { XMLBuilder, XMLParser } from 'fast-xml-parser';
|
|
4
|
+
import { BaSyxEnvironment } from '../../models/BaSyxEnvironment';
|
|
5
|
+
export function serializeXml(data, namespacePrefix = 'aas') {
|
|
6
|
+
// Return empty string for empty environment
|
|
7
|
+
if (!data.assetAdministrationShells?.length && !data.submodels?.length && !data.conceptDescriptions?.length) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
const builder = new XMLBuilder({
|
|
11
|
+
ignoreAttributes: false,
|
|
12
|
+
attributeNamePrefix: '@_',
|
|
13
|
+
attributeValueProcessor: (name, val) => val,
|
|
14
|
+
format: true,
|
|
15
|
+
indentBy: ' ',
|
|
16
|
+
suppressEmptyNode: true,
|
|
17
|
+
suppressBooleanAttributes: false,
|
|
18
|
+
processEntities: false,
|
|
19
|
+
cdataPropName: '__cdata',
|
|
20
|
+
arrayNodeName: 'element',
|
|
21
|
+
suppressUnpairedNode: false,
|
|
22
|
+
unpairedTags: [],
|
|
23
|
+
tagValueProcessor: (name, val) => val,
|
|
24
|
+
});
|
|
25
|
+
// Transform and add namespace prefix to all elements
|
|
26
|
+
const envData = transformEnvironmentToXmlStructure(data);
|
|
27
|
+
const prefixedData = addNamespacePrefix(envData, namespacePrefix);
|
|
28
|
+
// Wrap the environment data with proper XML declaration and namespace
|
|
29
|
+
const xmlObject = {
|
|
30
|
+
'?xml': {
|
|
31
|
+
'@_version': '1.0',
|
|
32
|
+
'@_encoding': 'UTF-8',
|
|
33
|
+
},
|
|
34
|
+
[`${namespacePrefix}:environment`]: {
|
|
35
|
+
[`@_xmlns:${namespacePrefix}`]: 'https://admin-shell.io/aas/3/1',
|
|
36
|
+
'@_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
37
|
+
'@_xsi:schemaLocation': 'https://admin-shell.io/aas/3/1 AAS.xsd',
|
|
38
|
+
...prefixedData,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
let xml = builder.build(xmlObject);
|
|
42
|
+
// Format the root element attributes to be on separate lines
|
|
43
|
+
const escapedPrefix = namespacePrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
44
|
+
const regex = new RegExp(`<${escapedPrefix}:environment xmlns:${escapedPrefix}="https:\\/\\/admin-shell\\.io\\/aas\\/3\\/1" xmlns:xsi="http:\\/\\/www\\.w3\\.org\\/2001\\/XMLSchema-instance" xsi:schemaLocation="https:\\/\\/admin-shell\\.io\\/aas\\/3\\/1 AAS\\.xsd">`, 'g');
|
|
45
|
+
xml = xml.replace(regex, `<${namespacePrefix}:environment xmlns:${namespacePrefix}="https://admin-shell.io/aas/3/1"\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="https://admin-shell.io/aas/3/1 AAS.xsd">`);
|
|
46
|
+
return xml;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recursively adds namespace prefix to all object keys except attributes
|
|
50
|
+
*/
|
|
51
|
+
function addNamespacePrefix(obj, prefix) {
|
|
52
|
+
if (obj === null || obj === undefined) {
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(obj)) {
|
|
56
|
+
return obj.map((item) => addNamespacePrefix(item, prefix));
|
|
57
|
+
}
|
|
58
|
+
if (typeof obj === 'object') {
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const key in obj) {
|
|
61
|
+
// Skip attributes (they start with @_) and keys that already have a namespace prefix
|
|
62
|
+
if (key.startsWith('@_') || key.includes(':')) {
|
|
63
|
+
result[key] = addNamespacePrefix(obj[key], prefix);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
result[`${prefix}:${key}`] = addNamespacePrefix(obj[key], prefix);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
function transformEnvironmentToXmlStructure(env) {
|
|
74
|
+
const result = {};
|
|
75
|
+
// Convert entire environment to jsonable to handle all enum conversions
|
|
76
|
+
const jsonableEnv = JSON.parse(JSON.stringify(jsonization.toJsonable(env)));
|
|
77
|
+
// Transform Asset Administration Shells
|
|
78
|
+
if (jsonableEnv.assetAdministrationShells && jsonableEnv.assetAdministrationShells.length > 0) {
|
|
79
|
+
result['assetAdministrationShells'] = {
|
|
80
|
+
assetAdministrationShell: jsonableEnv.assetAdministrationShells.map(transformAAS),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Transform Submodels
|
|
84
|
+
if (jsonableEnv.submodels && jsonableEnv.submodels.length > 0) {
|
|
85
|
+
result['submodels'] = {
|
|
86
|
+
submodel: jsonableEnv.submodels.map(transformSubmodel),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Transform Concept Descriptions
|
|
90
|
+
if (jsonableEnv.conceptDescriptions && jsonableEnv.conceptDescriptions.length > 0) {
|
|
91
|
+
result['conceptDescriptions'] = {
|
|
92
|
+
conceptDescription: jsonableEnv.conceptDescriptions.map(transformConceptDescription),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
function transformAAS(aas) {
|
|
98
|
+
const result = {};
|
|
99
|
+
// hasExtensions (from referable)
|
|
100
|
+
if (aas.extensions && aas.extensions.length > 0) {
|
|
101
|
+
result['extensions'] = {
|
|
102
|
+
extension: aas.extensions.map(transformExtension),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// category (from referable)
|
|
106
|
+
if (aas.category) {
|
|
107
|
+
result['category'] = aas.category;
|
|
108
|
+
}
|
|
109
|
+
// idShort (from referable)
|
|
110
|
+
if (aas.idShort) {
|
|
111
|
+
result['idShort'] = aas.idShort;
|
|
112
|
+
}
|
|
113
|
+
// displayName (from referable)
|
|
114
|
+
if (aas.displayName && aas.displayName.length > 0) {
|
|
115
|
+
result['displayName'] = {
|
|
116
|
+
langStringNameType: aas.displayName.map(transformLangString),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// description (from referable)
|
|
120
|
+
if (aas.description && aas.description.length > 0) {
|
|
121
|
+
result['description'] = {
|
|
122
|
+
langStringTextType: aas.description.map(transformLangString),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// administration (from identifiable)
|
|
126
|
+
if (aas.administration) {
|
|
127
|
+
result['administration'] = transformAdministrativeInformation(aas.administration);
|
|
128
|
+
}
|
|
129
|
+
// id (from identifiable) - REQUIRED
|
|
130
|
+
result['id'] = aas.id;
|
|
131
|
+
// embeddedDataSpecifications (from hasDataSpecification)
|
|
132
|
+
if (aas.embeddedDataSpecifications && aas.embeddedDataSpecifications.length > 0) {
|
|
133
|
+
result['embeddedDataSpecifications'] = {
|
|
134
|
+
embeddedDataSpecification: aas.embeddedDataSpecifications.map(transformEmbeddedDataSpecification),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// derivedFrom (specific to AAS)
|
|
138
|
+
if (aas.derivedFrom) {
|
|
139
|
+
result['derivedFrom'] = transformReference(aas.derivedFrom);
|
|
140
|
+
}
|
|
141
|
+
// assetInformation (specific to AAS) - REQUIRED
|
|
142
|
+
result['assetInformation'] = transformAssetInformation(aas.assetInformation);
|
|
143
|
+
// submodels (specific to AAS)
|
|
144
|
+
if (aas.submodels && aas.submodels.length > 0) {
|
|
145
|
+
result['submodels'] = {
|
|
146
|
+
reference: aas.submodels.map(transformReference),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
function transformExtension(ext) {
|
|
152
|
+
const result = {};
|
|
153
|
+
// semanticId (from hasSemantics)
|
|
154
|
+
if (ext.semanticId) {
|
|
155
|
+
result.semanticId = transformReference(ext.semanticId);
|
|
156
|
+
}
|
|
157
|
+
// supplementalSemanticIds (from hasSemantics)
|
|
158
|
+
if (ext.supplementalSemanticIds && ext.supplementalSemanticIds.length > 0) {
|
|
159
|
+
result.supplementalSemanticIds = {
|
|
160
|
+
reference: ext.supplementalSemanticIds.map(transformReference),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
// name - REQUIRED
|
|
164
|
+
result.name = ext.name;
|
|
165
|
+
// valueType
|
|
166
|
+
if (ext.valueType !== undefined && ext.valueType !== null) {
|
|
167
|
+
result.valueType = ext.valueType;
|
|
168
|
+
}
|
|
169
|
+
// value
|
|
170
|
+
if (ext.value !== undefined && ext.value !== null) {
|
|
171
|
+
result.value = ext.value;
|
|
172
|
+
}
|
|
173
|
+
// refersTo
|
|
174
|
+
if (ext.refersTo && ext.refersTo.length > 0) {
|
|
175
|
+
result.refersTo = {
|
|
176
|
+
reference: ext.refersTo.map(transformReference),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
function transformLangString(langStr) {
|
|
182
|
+
return {
|
|
183
|
+
language: langStr.language,
|
|
184
|
+
text: langStr.text,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function transformAdministrativeInformation(admin) {
|
|
188
|
+
const result = {};
|
|
189
|
+
// embeddedDataSpecifications (from hasDataSpecification)
|
|
190
|
+
if (admin.embeddedDataSpecifications && admin.embeddedDataSpecifications.length > 0) {
|
|
191
|
+
result.embeddedDataSpecifications = {
|
|
192
|
+
embeddedDataSpecification: admin.embeddedDataSpecifications.map(transformEmbeddedDataSpecification),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// version
|
|
196
|
+
if (admin.version) {
|
|
197
|
+
result.version = admin.version;
|
|
198
|
+
}
|
|
199
|
+
// revision
|
|
200
|
+
if (admin.revision) {
|
|
201
|
+
result.revision = admin.revision;
|
|
202
|
+
}
|
|
203
|
+
// creator
|
|
204
|
+
if (admin.creator) {
|
|
205
|
+
result.creator = transformReference(admin.creator);
|
|
206
|
+
}
|
|
207
|
+
// templateId
|
|
208
|
+
if (admin.templateId) {
|
|
209
|
+
result.templateId = admin.templateId;
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
function transformEmbeddedDataSpecification(eds) {
|
|
214
|
+
const result = {};
|
|
215
|
+
// dataSpecification - REQUIRED
|
|
216
|
+
result.dataSpecification = transformReference(eds.dataSpecification);
|
|
217
|
+
// dataSpecificationContent
|
|
218
|
+
if (eds.dataSpecificationContent) {
|
|
219
|
+
result.dataSpecificationContent = transformDataSpecificationContent(eds.dataSpecificationContent);
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
function transformDataSpecificationContent(content) {
|
|
224
|
+
// Check the type and transform accordingly
|
|
225
|
+
// For now, assume IEC61360
|
|
226
|
+
if (content.preferredName) {
|
|
227
|
+
return {
|
|
228
|
+
dataSpecificationIec61360: transformDataSpecificationIec61360(content),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return content;
|
|
232
|
+
}
|
|
233
|
+
function transformDataSpecificationIec61360(spec) {
|
|
234
|
+
const result = {};
|
|
235
|
+
// preferredName - REQUIRED
|
|
236
|
+
if (spec.preferredName && spec.preferredName.length > 0) {
|
|
237
|
+
result.preferredName = {
|
|
238
|
+
langStringPreferredNameTypeIec61360: spec.preferredName.map(transformLangString),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// shortName
|
|
242
|
+
if (spec.shortName && spec.shortName.length > 0) {
|
|
243
|
+
result.shortName = {
|
|
244
|
+
langStringShortNameTypeIec61360: spec.shortName.map(transformLangString),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// unit
|
|
248
|
+
if (spec.unit) {
|
|
249
|
+
result.unit = spec.unit;
|
|
250
|
+
}
|
|
251
|
+
// unitId
|
|
252
|
+
if (spec.unitId) {
|
|
253
|
+
result.unitId = transformReference(spec.unitId);
|
|
254
|
+
}
|
|
255
|
+
// sourceOfDefinition
|
|
256
|
+
if (spec.sourceOfDefinition) {
|
|
257
|
+
result.sourceOfDefinition = spec.sourceOfDefinition;
|
|
258
|
+
}
|
|
259
|
+
// symbol
|
|
260
|
+
if (spec.symbol) {
|
|
261
|
+
result.symbol = spec.symbol;
|
|
262
|
+
}
|
|
263
|
+
// dataType
|
|
264
|
+
if (spec.dataType !== undefined && spec.dataType !== null) {
|
|
265
|
+
result.dataType = spec.dataType;
|
|
266
|
+
}
|
|
267
|
+
// definition
|
|
268
|
+
if (spec.definition && spec.definition.length > 0) {
|
|
269
|
+
result.definition = {
|
|
270
|
+
langStringDefinitionTypeIec61360: spec.definition.map(transformLangString),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
// valueFormat
|
|
274
|
+
if (spec.valueFormat) {
|
|
275
|
+
result.valueFormat = spec.valueFormat;
|
|
276
|
+
}
|
|
277
|
+
// valueList
|
|
278
|
+
if (spec.valueList) {
|
|
279
|
+
result.valueList = transformValueList(spec.valueList);
|
|
280
|
+
}
|
|
281
|
+
// value
|
|
282
|
+
if (spec.value) {
|
|
283
|
+
result.value = spec.value;
|
|
284
|
+
}
|
|
285
|
+
// levelType
|
|
286
|
+
if (spec.levelType) {
|
|
287
|
+
result.levelType = spec.levelType;
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
function transformValueList(valueList) {
|
|
292
|
+
if (!valueList.valueReferencePairs || valueList.valueReferencePairs.length === 0) {
|
|
293
|
+
return valueList;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
valueReferencePairs: {
|
|
297
|
+
valueReferencePair: valueList.valueReferencePairs.map((vrp) => ({
|
|
298
|
+
value: vrp.value,
|
|
299
|
+
...(vrp.valueId && { valueId: transformReference(vrp.valueId) }),
|
|
300
|
+
})),
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function transformReference(ref) {
|
|
305
|
+
const result = {};
|
|
306
|
+
// type - REQUIRED
|
|
307
|
+
result.type = ref.type;
|
|
308
|
+
// referredSemanticId
|
|
309
|
+
if (ref.referredSemanticId) {
|
|
310
|
+
result.referredSemanticId = transformReference(ref.referredSemanticId);
|
|
311
|
+
}
|
|
312
|
+
// keys - REQUIRED
|
|
313
|
+
if (ref.keys && ref.keys.length > 0) {
|
|
314
|
+
result.keys = {
|
|
315
|
+
key: ref.keys.map((k) => ({
|
|
316
|
+
type: k.type,
|
|
317
|
+
value: k.value,
|
|
318
|
+
})),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
function transformAssetInformation(assetInfo) {
|
|
324
|
+
const result = {};
|
|
325
|
+
// assetKind - REQUIRED
|
|
326
|
+
// Convert AssetKind enum to string value
|
|
327
|
+
const assetKindValue = getAssetKindString(assetInfo.assetKind);
|
|
328
|
+
result['assetKind'] = assetKindValue;
|
|
329
|
+
// globalAssetId
|
|
330
|
+
if (assetInfo.globalAssetId) {
|
|
331
|
+
result['globalAssetId'] = assetInfo.globalAssetId;
|
|
332
|
+
}
|
|
333
|
+
// specificAssetIds
|
|
334
|
+
if (assetInfo.specificAssetIds && assetInfo.specificAssetIds.length > 0) {
|
|
335
|
+
result['specificAssetIds'] = {
|
|
336
|
+
specificAssetId: assetInfo.specificAssetIds.map(transformSpecificAssetId),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
// assetType
|
|
340
|
+
if (assetInfo.assetType) {
|
|
341
|
+
result['assetType'] = assetInfo.assetType;
|
|
342
|
+
}
|
|
343
|
+
// defaultThumbnail
|
|
344
|
+
if (assetInfo.defaultThumbnail) {
|
|
345
|
+
result['defaultThumbnail'] = transformResource(assetInfo.defaultThumbnail);
|
|
346
|
+
}
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
function getAssetKindString(assetKind) {
|
|
350
|
+
// toJsonable() already converts enums to strings
|
|
351
|
+
return assetKind;
|
|
352
|
+
}
|
|
353
|
+
function transformSpecificAssetId(sai) {
|
|
354
|
+
const result = {};
|
|
355
|
+
// name - REQUIRED
|
|
356
|
+
result.name = sai.name;
|
|
357
|
+
// value - REQUIRED
|
|
358
|
+
result.value = sai.value;
|
|
359
|
+
// externalSubjectId
|
|
360
|
+
if (sai.externalSubjectId) {
|
|
361
|
+
result.externalSubjectId = transformReference(sai.externalSubjectId);
|
|
362
|
+
}
|
|
363
|
+
// semanticId (from hasSemantics)
|
|
364
|
+
if (sai.semanticId) {
|
|
365
|
+
result.semanticId = transformReference(sai.semanticId);
|
|
366
|
+
}
|
|
367
|
+
// supplementalSemanticIds (from hasSemantics)
|
|
368
|
+
if (sai.supplementalSemanticIds && sai.supplementalSemanticIds.length > 0) {
|
|
369
|
+
result.supplementalSemanticIds = {
|
|
370
|
+
reference: sai.supplementalSemanticIds.map(transformReference),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return result;
|
|
374
|
+
}
|
|
375
|
+
function transformResource(resource) {
|
|
376
|
+
const result = {};
|
|
377
|
+
// path - REQUIRED
|
|
378
|
+
result.path = resource.path;
|
|
379
|
+
// contentType
|
|
380
|
+
if (resource.contentType) {
|
|
381
|
+
result.contentType = resource.contentType;
|
|
382
|
+
}
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
function transformSubmodel(submodel) {
|
|
386
|
+
const result = {};
|
|
387
|
+
// hasExtensions (from referable)
|
|
388
|
+
if (submodel.extensions && submodel.extensions.length > 0) {
|
|
389
|
+
result['extensions'] = {
|
|
390
|
+
extension: submodel.extensions.map(transformExtension),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
// category (from referable)
|
|
394
|
+
if (submodel.category) {
|
|
395
|
+
result['category'] = submodel.category;
|
|
396
|
+
}
|
|
397
|
+
// idShort (from referable)
|
|
398
|
+
if (submodel.idShort) {
|
|
399
|
+
result['idShort'] = submodel.idShort;
|
|
400
|
+
}
|
|
401
|
+
// displayName (from referable)
|
|
402
|
+
if (submodel.displayName && submodel.displayName.length > 0) {
|
|
403
|
+
result['displayName'] = {
|
|
404
|
+
langStringNameType: submodel.displayName.map(transformLangString),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
// description (from referable)
|
|
408
|
+
if (submodel.description && submodel.description.length > 0) {
|
|
409
|
+
result['description'] = {
|
|
410
|
+
langStringTextType: submodel.description.map(transformLangString),
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
// administration (from identifiable)
|
|
414
|
+
if (submodel.administration) {
|
|
415
|
+
result['administration'] = transformAdministrativeInformation(submodel.administration);
|
|
416
|
+
}
|
|
417
|
+
// id (from identifiable) - REQUIRED
|
|
418
|
+
result['id'] = submodel.id;
|
|
419
|
+
// kind (from hasKind)
|
|
420
|
+
if (submodel.kind !== undefined && submodel.kind !== null) {
|
|
421
|
+
result['kind'] = submodel.kind;
|
|
422
|
+
}
|
|
423
|
+
// semanticId (from hasSemantics)
|
|
424
|
+
if (submodel.semanticId) {
|
|
425
|
+
result['semanticId'] = transformReference(submodel.semanticId);
|
|
426
|
+
}
|
|
427
|
+
// supplementalSemanticIds (from hasSemantics)
|
|
428
|
+
if (submodel.supplementalSemanticIds && submodel.supplementalSemanticIds.length > 0) {
|
|
429
|
+
result['supplementalSemanticIds'] = {
|
|
430
|
+
reference: submodel.supplementalSemanticIds.map(transformReference),
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
// qualifiers (from qualifiable)
|
|
434
|
+
if (submodel.qualifiers && submodel.qualifiers.length > 0) {
|
|
435
|
+
result['qualifiers'] = {
|
|
436
|
+
qualifier: submodel.qualifiers.map(transformQualifier),
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
// embeddedDataSpecifications (from hasDataSpecification)
|
|
440
|
+
if (submodel.embeddedDataSpecifications && submodel.embeddedDataSpecifications.length > 0) {
|
|
441
|
+
result['embeddedDataSpecifications'] = {
|
|
442
|
+
embeddedDataSpecification: submodel.embeddedDataSpecifications.map(transformEmbeddedDataSpecification),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
// submodelElements (specific to Submodel)
|
|
446
|
+
if (submodel.submodelElements && submodel.submodelElements.length > 0) {
|
|
447
|
+
result['submodelElements'] = transformSubmodelElements(submodel.submodelElements);
|
|
448
|
+
}
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
451
|
+
function transformQualifier(qualifier) {
|
|
452
|
+
const result = {};
|
|
453
|
+
// semanticId (from hasSemantics)
|
|
454
|
+
if (qualifier.semanticId) {
|
|
455
|
+
result['semanticId'] = transformReference(qualifier.semanticId);
|
|
456
|
+
}
|
|
457
|
+
// supplementalSemanticIds (from hasSemantics)
|
|
458
|
+
if (qualifier.supplementalSemanticIds && qualifier.supplementalSemanticIds.length > 0) {
|
|
459
|
+
result['supplementalSemanticIds'] = {
|
|
460
|
+
reference: qualifier.supplementalSemanticIds.map(transformReference),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
// kind (from hasKind)
|
|
464
|
+
if (qualifier.kind !== undefined && qualifier.kind !== null) {
|
|
465
|
+
result['kind'] = qualifier.kind;
|
|
466
|
+
}
|
|
467
|
+
// type - REQUIRED
|
|
468
|
+
result['type'] = qualifier.type;
|
|
469
|
+
// valueType - REQUIRED
|
|
470
|
+
result['valueType'] = qualifier.valueType;
|
|
471
|
+
// value
|
|
472
|
+
if (qualifier.value !== undefined && qualifier.value !== null) {
|
|
473
|
+
result['value'] = qualifier.value;
|
|
474
|
+
}
|
|
475
|
+
// valueId
|
|
476
|
+
if (qualifier.valueId) {
|
|
477
|
+
result['valueId'] = transformReference(qualifier.valueId);
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
function transformSubmodelElements(elements) {
|
|
482
|
+
const result = {};
|
|
483
|
+
for (const element of elements) {
|
|
484
|
+
const modelType = element.modelType;
|
|
485
|
+
if (!modelType) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
let transformedElement;
|
|
489
|
+
switch (modelType) {
|
|
490
|
+
case 'Property':
|
|
491
|
+
transformedElement = transformProperty(element);
|
|
492
|
+
break;
|
|
493
|
+
case 'MultiLanguageProperty':
|
|
494
|
+
transformedElement = transformMultiLanguageProperty(element);
|
|
495
|
+
break;
|
|
496
|
+
case 'Range':
|
|
497
|
+
transformedElement = transformRange(element);
|
|
498
|
+
break;
|
|
499
|
+
case 'ReferenceElement':
|
|
500
|
+
transformedElement = transformReferenceElement(element);
|
|
501
|
+
break;
|
|
502
|
+
case 'Blob':
|
|
503
|
+
transformedElement = transformBlob(element);
|
|
504
|
+
break;
|
|
505
|
+
case 'File':
|
|
506
|
+
transformedElement = transformFile(element);
|
|
507
|
+
break;
|
|
508
|
+
case 'Entity':
|
|
509
|
+
transformedElement = transformEntity(element);
|
|
510
|
+
break;
|
|
511
|
+
case 'RelationshipElement':
|
|
512
|
+
transformedElement = transformRelationshipElement(element);
|
|
513
|
+
break;
|
|
514
|
+
case 'AnnotatedRelationshipElement':
|
|
515
|
+
transformedElement = transformAnnotatedRelationshipElement(element);
|
|
516
|
+
break;
|
|
517
|
+
case 'SubmodelElementCollection':
|
|
518
|
+
transformedElement = transformSubmodelElementCollection(element);
|
|
519
|
+
break;
|
|
520
|
+
case 'SubmodelElementList':
|
|
521
|
+
transformedElement = transformSubmodelElementList(element);
|
|
522
|
+
break;
|
|
523
|
+
case 'Operation':
|
|
524
|
+
transformedElement = transformOperation(element);
|
|
525
|
+
break;
|
|
526
|
+
case 'Capability':
|
|
527
|
+
transformedElement = transformCapability(element);
|
|
528
|
+
break;
|
|
529
|
+
case 'BasicEventElement':
|
|
530
|
+
transformedElement = transformBasicEventElement(element);
|
|
531
|
+
break;
|
|
532
|
+
default:
|
|
533
|
+
// Unknown type, skip it
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
// Use modelType as the key with lowercase first letter
|
|
537
|
+
const key = modelType.charAt(0).toLowerCase() + modelType.slice(1);
|
|
538
|
+
if (!result[key]) {
|
|
539
|
+
result[key] = [];
|
|
540
|
+
}
|
|
541
|
+
result[key].push(transformedElement);
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
function transformProperty(property) {
|
|
546
|
+
const result = {};
|
|
547
|
+
// Add common referable/qualifiable/semantic properties
|
|
548
|
+
addReferableProperties(result, property);
|
|
549
|
+
addSemanticProperties(result, property);
|
|
550
|
+
addQualifiableProperties(result, property);
|
|
551
|
+
// valueType - REQUIRED
|
|
552
|
+
result['valueType'] = property.valueType;
|
|
553
|
+
// value
|
|
554
|
+
if (property.value !== undefined && property.value !== null) {
|
|
555
|
+
result['value'] = property.value;
|
|
556
|
+
}
|
|
557
|
+
// valueId
|
|
558
|
+
if (property.valueId) {
|
|
559
|
+
result['valueId'] = transformReference(property.valueId);
|
|
560
|
+
}
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
563
|
+
function transformMultiLanguageProperty(mlp) {
|
|
564
|
+
const result = {};
|
|
565
|
+
addReferableProperties(result, mlp);
|
|
566
|
+
addSemanticProperties(result, mlp);
|
|
567
|
+
addQualifiableProperties(result, mlp);
|
|
568
|
+
// value
|
|
569
|
+
if (mlp.value && mlp.value.length > 0) {
|
|
570
|
+
result['value'] = {
|
|
571
|
+
langStringTextType: mlp.value.map(transformLangString),
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
// valueId
|
|
575
|
+
if (mlp.valueId) {
|
|
576
|
+
result['valueId'] = transformReference(mlp.valueId);
|
|
577
|
+
}
|
|
578
|
+
return result;
|
|
579
|
+
}
|
|
580
|
+
function transformRange(range) {
|
|
581
|
+
const result = {};
|
|
582
|
+
addReferableProperties(result, range);
|
|
583
|
+
addSemanticProperties(result, range);
|
|
584
|
+
addQualifiableProperties(result, range);
|
|
585
|
+
// valueType - REQUIRED
|
|
586
|
+
result['valueType'] = range.valueType;
|
|
587
|
+
// min
|
|
588
|
+
if (range.min !== undefined && range.min !== null) {
|
|
589
|
+
result['min'] = range.min;
|
|
590
|
+
}
|
|
591
|
+
// max
|
|
592
|
+
if (range.max !== undefined && range.max !== null) {
|
|
593
|
+
result['max'] = range.max;
|
|
594
|
+
}
|
|
595
|
+
return result;
|
|
596
|
+
}
|
|
597
|
+
function transformReferenceElement(refElem) {
|
|
598
|
+
const result = {};
|
|
599
|
+
addReferableProperties(result, refElem);
|
|
600
|
+
addSemanticProperties(result, refElem);
|
|
601
|
+
addQualifiableProperties(result, refElem);
|
|
602
|
+
// value
|
|
603
|
+
if (refElem.value) {
|
|
604
|
+
result['value'] = transformReference(refElem.value);
|
|
605
|
+
}
|
|
606
|
+
return result;
|
|
607
|
+
}
|
|
608
|
+
function transformBlob(blob) {
|
|
609
|
+
const result = {};
|
|
610
|
+
addReferableProperties(result, blob);
|
|
611
|
+
addSemanticProperties(result, blob);
|
|
612
|
+
addQualifiableProperties(result, blob);
|
|
613
|
+
// value
|
|
614
|
+
if (blob.value !== undefined && blob.value !== null) {
|
|
615
|
+
result['value'] = blob.value;
|
|
616
|
+
}
|
|
617
|
+
// contentType - REQUIRED
|
|
618
|
+
result['contentType'] = blob.contentType;
|
|
619
|
+
return result;
|
|
620
|
+
}
|
|
621
|
+
function transformFile(file) {
|
|
622
|
+
const result = {};
|
|
623
|
+
addReferableProperties(result, file);
|
|
624
|
+
addSemanticProperties(result, file);
|
|
625
|
+
addQualifiableProperties(result, file);
|
|
626
|
+
// value
|
|
627
|
+
if (file.value !== undefined && file.value !== null) {
|
|
628
|
+
result['value'] = file.value;
|
|
629
|
+
}
|
|
630
|
+
// contentType - REQUIRED
|
|
631
|
+
result['contentType'] = file.contentType;
|
|
632
|
+
return result;
|
|
633
|
+
}
|
|
634
|
+
function transformEntity(entity) {
|
|
635
|
+
const result = {};
|
|
636
|
+
addReferableProperties(result, entity);
|
|
637
|
+
addSemanticProperties(result, entity);
|
|
638
|
+
addQualifiableProperties(result, entity);
|
|
639
|
+
// statements (submodel elements)
|
|
640
|
+
if (entity.statements && entity.statements.length > 0) {
|
|
641
|
+
result['statements'] = transformSubmodelElements(entity.statements);
|
|
642
|
+
}
|
|
643
|
+
// entityType - REQUIRED
|
|
644
|
+
result['entityType'] = entity.entityType;
|
|
645
|
+
// globalAssetId
|
|
646
|
+
if (entity.globalAssetId) {
|
|
647
|
+
result['globalAssetId'] = entity.globalAssetId;
|
|
648
|
+
}
|
|
649
|
+
// specificAssetIds
|
|
650
|
+
if (entity.specificAssetIds && entity.specificAssetIds.length > 0) {
|
|
651
|
+
result['specificAssetIds'] = {
|
|
652
|
+
specificAssetId: entity.specificAssetIds.map(transformSpecificAssetId),
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
return result;
|
|
656
|
+
}
|
|
657
|
+
function transformRelationshipElement(rel) {
|
|
658
|
+
const result = {};
|
|
659
|
+
addReferableProperties(result, rel);
|
|
660
|
+
addSemanticProperties(result, rel);
|
|
661
|
+
addQualifiableProperties(result, rel);
|
|
662
|
+
// first - REQUIRED
|
|
663
|
+
result['first'] = transformReference(rel.first);
|
|
664
|
+
// second - REQUIRED
|
|
665
|
+
result['second'] = transformReference(rel.second);
|
|
666
|
+
return result;
|
|
667
|
+
}
|
|
668
|
+
function transformAnnotatedRelationshipElement(annotatedRel) {
|
|
669
|
+
const result = {};
|
|
670
|
+
addReferableProperties(result, annotatedRel);
|
|
671
|
+
addSemanticProperties(result, annotatedRel);
|
|
672
|
+
addQualifiableProperties(result, annotatedRel);
|
|
673
|
+
// first - REQUIRED
|
|
674
|
+
result['first'] = transformReference(annotatedRel.first);
|
|
675
|
+
// second - REQUIRED
|
|
676
|
+
result['second'] = transformReference(annotatedRel.second);
|
|
677
|
+
// annotations
|
|
678
|
+
if (annotatedRel.annotations && annotatedRel.annotations.length > 0) {
|
|
679
|
+
result['annotations'] = transformSubmodelElements(annotatedRel.annotations);
|
|
680
|
+
}
|
|
681
|
+
return result;
|
|
682
|
+
}
|
|
683
|
+
function transformSubmodelElementCollection(collection) {
|
|
684
|
+
const result = {};
|
|
685
|
+
addReferableProperties(result, collection);
|
|
686
|
+
addSemanticProperties(result, collection);
|
|
687
|
+
addQualifiableProperties(result, collection);
|
|
688
|
+
// value (submodel elements)
|
|
689
|
+
if (collection.value && collection.value.length > 0) {
|
|
690
|
+
result['value'] = transformSubmodelElements(collection.value);
|
|
691
|
+
}
|
|
692
|
+
return result;
|
|
693
|
+
}
|
|
694
|
+
function transformSubmodelElementList(list) {
|
|
695
|
+
const result = {};
|
|
696
|
+
addReferableProperties(result, list);
|
|
697
|
+
addSemanticProperties(result, list);
|
|
698
|
+
addQualifiableProperties(result, list);
|
|
699
|
+
// orderRelevant
|
|
700
|
+
if (list.orderRelevant !== undefined && list.orderRelevant !== null) {
|
|
701
|
+
result['orderRelevant'] = list.orderRelevant;
|
|
702
|
+
}
|
|
703
|
+
// semanticIdListElement
|
|
704
|
+
if (list.semanticIdListElement) {
|
|
705
|
+
result['semanticIdListElement'] = transformReference(list.semanticIdListElement);
|
|
706
|
+
}
|
|
707
|
+
// typeValueListElement - REQUIRED
|
|
708
|
+
result['typeValueListElement'] = list.typeValueListElement;
|
|
709
|
+
// valueTypeListElement
|
|
710
|
+
if (list.valueTypeListElement) {
|
|
711
|
+
result['valueTypeListElement'] = list.valueTypeListElement;
|
|
712
|
+
}
|
|
713
|
+
// value (submodel elements)
|
|
714
|
+
if (list.value && list.value.length > 0) {
|
|
715
|
+
result['value'] = transformSubmodelElements(list.value);
|
|
716
|
+
}
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
719
|
+
function transformOperation(operation) {
|
|
720
|
+
const result = {};
|
|
721
|
+
addReferableProperties(result, operation);
|
|
722
|
+
addSemanticProperties(result, operation);
|
|
723
|
+
addQualifiableProperties(result, operation);
|
|
724
|
+
// inputVariables
|
|
725
|
+
if (operation.inputVariables && operation.inputVariables.length > 0) {
|
|
726
|
+
result['inputVariables'] = {
|
|
727
|
+
operationVariable: operation.inputVariables.map(transformOperationVariable),
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
// outputVariables
|
|
731
|
+
if (operation.outputVariables && operation.outputVariables.length > 0) {
|
|
732
|
+
result['outputVariables'] = {
|
|
733
|
+
operationVariable: operation.outputVariables.map(transformOperationVariable),
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
// inoutputVariables
|
|
737
|
+
if (operation.inoutputVariables && operation.inoutputVariables.length > 0) {
|
|
738
|
+
result['inoutputVariables'] = {
|
|
739
|
+
operationVariable: operation.inoutputVariables.map(transformOperationVariable),
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
return result;
|
|
743
|
+
}
|
|
744
|
+
function transformOperationVariable(opVar) {
|
|
745
|
+
const result = {};
|
|
746
|
+
// value - REQUIRED (a SubmodelElement)
|
|
747
|
+
if (opVar.value) {
|
|
748
|
+
const valueElements = transformSubmodelElements([opVar.value]);
|
|
749
|
+
result['value'] = valueElements;
|
|
750
|
+
}
|
|
751
|
+
return result;
|
|
752
|
+
}
|
|
753
|
+
function transformCapability(capability) {
|
|
754
|
+
const result = {};
|
|
755
|
+
addReferableProperties(result, capability);
|
|
756
|
+
addSemanticProperties(result, capability);
|
|
757
|
+
addQualifiableProperties(result, capability);
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
function transformBasicEventElement(event) {
|
|
761
|
+
const result = {};
|
|
762
|
+
addReferableProperties(result, event);
|
|
763
|
+
addSemanticProperties(result, event);
|
|
764
|
+
addQualifiableProperties(result, event);
|
|
765
|
+
// observed - REQUIRED
|
|
766
|
+
result['observed'] = transformReference(event.observed);
|
|
767
|
+
// direction - REQUIRED
|
|
768
|
+
result['direction'] = event.direction;
|
|
769
|
+
// state - REQUIRED
|
|
770
|
+
result['state'] = event.state;
|
|
771
|
+
// messageTopic
|
|
772
|
+
if (event.messageTopic) {
|
|
773
|
+
result['messageTopic'] = event.messageTopic;
|
|
774
|
+
}
|
|
775
|
+
// messageBroker
|
|
776
|
+
if (event.messageBroker) {
|
|
777
|
+
result['messageBroker'] = transformReference(event.messageBroker);
|
|
778
|
+
}
|
|
779
|
+
// lastUpdate
|
|
780
|
+
if (event.lastUpdate) {
|
|
781
|
+
result['lastUpdate'] = event.lastUpdate;
|
|
782
|
+
}
|
|
783
|
+
// minInterval
|
|
784
|
+
if (event.minInterval) {
|
|
785
|
+
result['minInterval'] = event.minInterval;
|
|
786
|
+
}
|
|
787
|
+
// maxInterval
|
|
788
|
+
if (event.maxInterval) {
|
|
789
|
+
result['maxInterval'] = event.maxInterval;
|
|
790
|
+
}
|
|
791
|
+
return result;
|
|
792
|
+
}
|
|
793
|
+
// Helper functions to add common properties
|
|
794
|
+
function addReferableProperties(result, element) {
|
|
795
|
+
// extensions
|
|
796
|
+
if (element.extensions && element.extensions.length > 0) {
|
|
797
|
+
result['extensions'] = {
|
|
798
|
+
extension: element.extensions.map(transformExtension),
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
// category
|
|
802
|
+
if (element.category) {
|
|
803
|
+
result['category'] = element.category;
|
|
804
|
+
}
|
|
805
|
+
// idShort
|
|
806
|
+
if (element.idShort) {
|
|
807
|
+
result['idShort'] = element.idShort;
|
|
808
|
+
}
|
|
809
|
+
// displayName
|
|
810
|
+
if (element.displayName && element.displayName.length > 0) {
|
|
811
|
+
result['displayName'] = {
|
|
812
|
+
langStringNameType: element.displayName.map(transformLangString),
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
// description
|
|
816
|
+
if (element.description && element.description.length > 0) {
|
|
817
|
+
result['description'] = {
|
|
818
|
+
langStringTextType: element.description.map(transformLangString),
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
function addSemanticProperties(result, element) {
|
|
823
|
+
// semanticId
|
|
824
|
+
if (element.semanticId) {
|
|
825
|
+
result['semanticId'] = transformReference(element.semanticId);
|
|
826
|
+
}
|
|
827
|
+
// supplementalSemanticIds
|
|
828
|
+
if (element.supplementalSemanticIds && element.supplementalSemanticIds.length > 0) {
|
|
829
|
+
result['supplementalSemanticIds'] = {
|
|
830
|
+
reference: element.supplementalSemanticIds.map(transformReference),
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
function addQualifiableProperties(result, element) {
|
|
835
|
+
// qualifiers
|
|
836
|
+
if (element.qualifiers && element.qualifiers.length > 0) {
|
|
837
|
+
result['qualifiers'] = {
|
|
838
|
+
qualifier: element.qualifiers.map(transformQualifier),
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function transformConceptDescription(cd) {
|
|
843
|
+
const result = {};
|
|
844
|
+
// hasExtensions (from referable)
|
|
845
|
+
if (cd.extensions && cd.extensions.length > 0) {
|
|
846
|
+
result['extensions'] = {
|
|
847
|
+
extension: cd.extensions.map(transformExtension),
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
// category (from referable)
|
|
851
|
+
if (cd.category) {
|
|
852
|
+
result['category'] = cd.category;
|
|
853
|
+
}
|
|
854
|
+
// idShort (from referable)
|
|
855
|
+
if (cd.idShort) {
|
|
856
|
+
result['idShort'] = cd.idShort;
|
|
857
|
+
}
|
|
858
|
+
// displayName (from referable)
|
|
859
|
+
if (cd.displayName && cd.displayName.length > 0) {
|
|
860
|
+
result['displayName'] = {
|
|
861
|
+
langStringNameType: cd.displayName.map(transformLangString),
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
// description (from referable)
|
|
865
|
+
if (cd.description && cd.description.length > 0) {
|
|
866
|
+
result['description'] = {
|
|
867
|
+
langStringTextType: cd.description.map(transformLangString),
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
// administration (from identifiable)
|
|
871
|
+
if (cd.administration) {
|
|
872
|
+
result['administration'] = transformAdministrativeInformation(cd.administration);
|
|
873
|
+
}
|
|
874
|
+
// id (from identifiable) - REQUIRED
|
|
875
|
+
result['id'] = cd.id;
|
|
876
|
+
// embeddedDataSpecifications (from hasDataSpecification)
|
|
877
|
+
if (cd.embeddedDataSpecifications && cd.embeddedDataSpecifications.length > 0) {
|
|
878
|
+
result['embeddedDataSpecifications'] = {
|
|
879
|
+
embeddedDataSpecification: cd.embeddedDataSpecifications.map(transformEmbeddedDataSpecification),
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
// isCaseOf (specific to ConceptDescription)
|
|
883
|
+
if (cd.isCaseOf && cd.isCaseOf.length > 0) {
|
|
884
|
+
result['isCaseOf'] = {
|
|
885
|
+
reference: cd.isCaseOf.map(transformReference),
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
return result;
|
|
889
|
+
}
|
|
890
|
+
// Helper function to ensure a value is an array
|
|
891
|
+
function ensureArray(val) {
|
|
892
|
+
if (!val)
|
|
893
|
+
return [];
|
|
894
|
+
return Array.isArray(val) ? val : [val];
|
|
895
|
+
}
|
|
896
|
+
export function deserializeXml(xmlString) {
|
|
897
|
+
if (!xmlString || xmlString.trim() === '') {
|
|
898
|
+
return new BaSyxEnvironment();
|
|
899
|
+
}
|
|
900
|
+
const parser = new XMLParser({
|
|
901
|
+
ignoreAttributes: false,
|
|
902
|
+
attributeNamePrefix: '@_',
|
|
903
|
+
parseAttributeValue: false,
|
|
904
|
+
parseTagValue: false,
|
|
905
|
+
trimValues: true,
|
|
906
|
+
removeNSPrefix: true, // Remove namespace prefixes like aas:
|
|
907
|
+
isArray: (name) => {
|
|
908
|
+
// Define which elements should always be treated as arrays
|
|
909
|
+
const arrayElements = [
|
|
910
|
+
'extension',
|
|
911
|
+
'langStringNameType',
|
|
912
|
+
'langStringTextType',
|
|
913
|
+
'langStringPreferredNameTypeIec61360',
|
|
914
|
+
'langStringShortNameTypeIec61360',
|
|
915
|
+
'langStringDefinitionTypeIec61360',
|
|
916
|
+
'reference',
|
|
917
|
+
'key',
|
|
918
|
+
'valueReferencePair',
|
|
919
|
+
'embeddedDataSpecification',
|
|
920
|
+
'specificAssetId',
|
|
921
|
+
'assetAdministrationShell',
|
|
922
|
+
'submodel',
|
|
923
|
+
'conceptDescription',
|
|
924
|
+
'qualifier',
|
|
925
|
+
'operationVariable',
|
|
926
|
+
];
|
|
927
|
+
return arrayElements.includes(name);
|
|
928
|
+
},
|
|
929
|
+
});
|
|
930
|
+
const parsed = parser.parse(xmlString);
|
|
931
|
+
const env = new BaSyxEnvironment();
|
|
932
|
+
// Extract the environment data
|
|
933
|
+
const envData = parsed.environment;
|
|
934
|
+
if (!envData) {
|
|
935
|
+
return env;
|
|
936
|
+
}
|
|
937
|
+
// Parse Asset Administration Shells
|
|
938
|
+
if (envData.assetAdministrationShells?.assetAdministrationShell) {
|
|
939
|
+
env.assetAdministrationShells =
|
|
940
|
+
envData.assetAdministrationShells.assetAdministrationShell.map(parseAssetAdministrationShell);
|
|
941
|
+
}
|
|
942
|
+
// Parse Submodels
|
|
943
|
+
if (envData.submodels?.submodel) {
|
|
944
|
+
env.submodels = Array.isArray(envData.submodels.submodel)
|
|
945
|
+
? envData.submodels.submodel.map(parseSubmodel)
|
|
946
|
+
: [parseSubmodel(envData.submodels.submodel)];
|
|
947
|
+
}
|
|
948
|
+
// Parse Concept Descriptions
|
|
949
|
+
if (envData.conceptDescriptions?.conceptDescription) {
|
|
950
|
+
env.conceptDescriptions = Array.isArray(envData.conceptDescriptions.conceptDescription)
|
|
951
|
+
? envData.conceptDescriptions.conceptDescription.map(parseConceptDescription)
|
|
952
|
+
: [parseConceptDescription(envData.conceptDescriptions.conceptDescription)];
|
|
953
|
+
}
|
|
954
|
+
return env;
|
|
955
|
+
}
|
|
956
|
+
function parseAssetAdministrationShell(data) {
|
|
957
|
+
return new AssetAdministrationShell(data.id, parseAssetInformation(data.assetInformation), data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
958
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
959
|
+
: undefined, data.description?.langStringTextType
|
|
960
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
961
|
+
: undefined, data.administration ? parseAdministrativeInformation(data.administration) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
962
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
963
|
+
: undefined, data.derivedFrom ? parseReference(data.derivedFrom) : undefined, data.submodels?.reference ? data.submodels.reference.map(parseReference) : undefined);
|
|
964
|
+
}
|
|
965
|
+
function parseExtension(data) {
|
|
966
|
+
// Map XML valueType string to DataTypeDefXsd enum
|
|
967
|
+
let valueType = data.valueType || undefined;
|
|
968
|
+
if (valueType && typeof valueType === 'string' && valueType.startsWith('xs:')) {
|
|
969
|
+
// Extract the type after 'xs:' prefix and map to enum
|
|
970
|
+
const typeValue = valueType.substring(3);
|
|
971
|
+
const capitalizedType = typeValue.charAt(0).toUpperCase() + typeValue.slice(1);
|
|
972
|
+
// Map string to DataTypeDefXsd enum value
|
|
973
|
+
valueType = DataTypeDefXsd[capitalizedType];
|
|
974
|
+
}
|
|
975
|
+
return new Extension(data.name, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
976
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
977
|
+
: undefined, valueType, data.value || undefined, data.refersTo?.reference ? data.refersTo.reference.map(parseReference) : undefined);
|
|
978
|
+
}
|
|
979
|
+
function parseLangStringNameType(data) {
|
|
980
|
+
return new LangStringNameType(data.language, data.text);
|
|
981
|
+
}
|
|
982
|
+
function parseLangStringTextType(data) {
|
|
983
|
+
return new LangStringTextType(data.language, data.text);
|
|
984
|
+
}
|
|
985
|
+
function parseAdministrativeInformation(data) {
|
|
986
|
+
return new AdministrativeInformation(data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
987
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
988
|
+
: undefined, data.version || undefined, data.revision || undefined, data.creator ? parseReference(data.creator) : undefined, data.templateId || undefined);
|
|
989
|
+
}
|
|
990
|
+
function parseEmbeddedDataSpecification(data) {
|
|
991
|
+
const dataSpecContent = data.dataSpecificationContent?.dataSpecificationIec61360
|
|
992
|
+
? parseDataSpecificationIec61360(data.dataSpecificationContent.dataSpecificationIec61360)
|
|
993
|
+
: undefined;
|
|
994
|
+
return new EmbeddedDataSpecification(parseReference(data.dataSpecification), dataSpecContent);
|
|
995
|
+
}
|
|
996
|
+
function parseDataSpecificationIec61360(data) {
|
|
997
|
+
// Map string dataType to enum value using jsonization
|
|
998
|
+
let dataType = data.dataType;
|
|
999
|
+
if (dataType && typeof dataType === 'string') {
|
|
1000
|
+
const result = jsonization.dataTypeIec61360FromJsonable(dataType);
|
|
1001
|
+
if (result.error === null && result.value !== null) {
|
|
1002
|
+
dataType = result.value;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return new DataSpecificationIec61360(data.preferredName?.langStringPreferredNameTypeIec61360
|
|
1006
|
+
? data.preferredName.langStringPreferredNameTypeIec61360.map(parseLangStringPreferredNameTypeIec61360)
|
|
1007
|
+
: [], data.shortName?.langStringShortNameTypeIec61360
|
|
1008
|
+
? data.shortName.langStringShortNameTypeIec61360.map(parseLangStringShortNameTypeIec61360)
|
|
1009
|
+
: undefined, data.unit || undefined, data.unitId ? parseReference(data.unitId) : undefined, data.sourceOfDefinition || undefined, data.symbol || undefined, dataType || undefined, data.definition?.langStringDefinitionTypeIec61360
|
|
1010
|
+
? data.definition.langStringDefinitionTypeIec61360.map(parseLangStringDefinitionTypeIec61360)
|
|
1011
|
+
: undefined, data.valueFormat || undefined, data.valueList ? parseValueList(data.valueList) : undefined, data.value || undefined, data.levelType ? parseLevelType(data.levelType) : undefined);
|
|
1012
|
+
}
|
|
1013
|
+
function parseLangStringPreferredNameTypeIec61360(data) {
|
|
1014
|
+
return new LangStringPreferredNameTypeIec61360(data.language, data.text);
|
|
1015
|
+
}
|
|
1016
|
+
function parseLangStringShortNameTypeIec61360(data) {
|
|
1017
|
+
return new LangStringShortNameTypeIec61360(data.language, data.text);
|
|
1018
|
+
}
|
|
1019
|
+
function parseLangStringDefinitionTypeIec61360(data) {
|
|
1020
|
+
return new LangStringDefinitionTypeIec61360(data.language, data.text);
|
|
1021
|
+
}
|
|
1022
|
+
function parseValueList(data) {
|
|
1023
|
+
return new ValueList(data.valueReferencePairs?.valueReferencePair
|
|
1024
|
+
? data.valueReferencePairs.valueReferencePair.map(parseValueReferencePair)
|
|
1025
|
+
: []);
|
|
1026
|
+
}
|
|
1027
|
+
function parseValueReferencePair(data) {
|
|
1028
|
+
const valueId = data.valueId ? parseReference(data.valueId) : undefined;
|
|
1029
|
+
return new ValueReferencePair(data.value, valueId);
|
|
1030
|
+
}
|
|
1031
|
+
function parseLevelType(data) {
|
|
1032
|
+
return new LevelType(data.min === 'true' || data.min === true, data.nom === 'true' || data.nom === true, data.typ === 'true' || data.typ === true, data.max === 'true' || data.max === true);
|
|
1033
|
+
}
|
|
1034
|
+
function parseReference(data) {
|
|
1035
|
+
// Map string type to enum
|
|
1036
|
+
const referenceType = ReferenceTypes[data.type] ?? data.type;
|
|
1037
|
+
return new Reference(referenceType, data.keys?.key ? data.keys.key.map(parseKey) : [], data.referredSemanticId ? parseReference(data.referredSemanticId) : undefined);
|
|
1038
|
+
}
|
|
1039
|
+
function parseKey(data) {
|
|
1040
|
+
// Map string type to enum
|
|
1041
|
+
const keyType = KeyTypes[data.type] ?? data.type;
|
|
1042
|
+
return new Key(keyType, data.value);
|
|
1043
|
+
}
|
|
1044
|
+
function parseAssetInformation(data) {
|
|
1045
|
+
// Map string assetKind to enum
|
|
1046
|
+
const assetKind = AssetKind[data.assetKind] ?? data.assetKind;
|
|
1047
|
+
return new AssetInformation(assetKind, data.globalAssetId || undefined, data.specificAssetIds?.specificAssetId
|
|
1048
|
+
? ensureArray(data.specificAssetIds.specificAssetId).map(parseSpecificAssetId)
|
|
1049
|
+
: undefined, data.assetType || undefined, data.defaultThumbnail ? parseResource(data.defaultThumbnail) : undefined);
|
|
1050
|
+
}
|
|
1051
|
+
function parseSpecificAssetId(data) {
|
|
1052
|
+
const semanticId = data.semanticId ? parseReference(data.semanticId) : undefined;
|
|
1053
|
+
const supplementalSemanticIds = data.supplementalSemanticIds?.reference
|
|
1054
|
+
? ensureArray(data.supplementalSemanticIds.reference).map(parseReference)
|
|
1055
|
+
: undefined;
|
|
1056
|
+
return new SpecificAssetId(data.name, data.value, semanticId, supplementalSemanticIds, data.externalSubjectId ? parseReference(data.externalSubjectId) : undefined);
|
|
1057
|
+
}
|
|
1058
|
+
function parseResource(data) {
|
|
1059
|
+
return new Resource(data.path, data.contentType || undefined);
|
|
1060
|
+
}
|
|
1061
|
+
function parseConceptDescription(data) {
|
|
1062
|
+
return new ConceptDescription(data.id, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1063
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1064
|
+
: undefined, data.description?.langStringTextType
|
|
1065
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1066
|
+
: undefined, data.administration ? parseAdministrativeInformation(data.administration) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1067
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1068
|
+
: undefined, data.isCaseOf?.reference ? data.isCaseOf.reference.map(parseReference) : undefined);
|
|
1069
|
+
}
|
|
1070
|
+
function parseSubmodel(data) {
|
|
1071
|
+
return new Submodel(data.id, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1072
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1073
|
+
: undefined, data.description?.langStringTextType
|
|
1074
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1075
|
+
: undefined, data.administration ? parseAdministrativeInformation(data.administration) : undefined, data.kind ? (jsonization.modellingKindFromJsonable(data.kind).value ?? data.kind) : undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1076
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1077
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1078
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1079
|
+
: undefined, data.submodelElements ? parseSubmodelElements(data.submodelElements) : undefined);
|
|
1080
|
+
}
|
|
1081
|
+
function parseQualifier(data) {
|
|
1082
|
+
// Map XML valueType string to DataTypeDefXsd enum
|
|
1083
|
+
let valueType = data.valueType || undefined;
|
|
1084
|
+
if (valueType && typeof valueType === 'string') {
|
|
1085
|
+
// Convert string to enum value using jsonization (expects xs: prefix)
|
|
1086
|
+
const result = jsonization.dataTypeDefXsdFromJsonable(valueType);
|
|
1087
|
+
if (result.error === null && result.value !== null) {
|
|
1088
|
+
valueType = result.value;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
return new Qualifier(data.type, valueType, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1092
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1093
|
+
: undefined, data.kind ? (jsonization.qualifierKindFromJsonable(data.kind).value ?? data.kind) : undefined, data.value || undefined, data.valueId ? parseReference(data.valueId) : undefined);
|
|
1094
|
+
}
|
|
1095
|
+
function parseSubmodelElements(data) {
|
|
1096
|
+
const elements = [];
|
|
1097
|
+
// Check for all possible submodel element types
|
|
1098
|
+
const elementTypes = [
|
|
1099
|
+
{ key: 'property', parser: parseProperty },
|
|
1100
|
+
{ key: 'multiLanguageProperty', parser: parseMultiLanguageProperty },
|
|
1101
|
+
{ key: 'range', parser: parseRange },
|
|
1102
|
+
{ key: 'referenceElement', parser: parseReferenceElement },
|
|
1103
|
+
{ key: 'blob', parser: parseBlob },
|
|
1104
|
+
{ key: 'file', parser: parseFile },
|
|
1105
|
+
{ key: 'entity', parser: parseEntity },
|
|
1106
|
+
{ key: 'relationshipElement', parser: parseRelationshipElement },
|
|
1107
|
+
{ key: 'annotatedRelationshipElement', parser: parseAnnotatedRelationshipElement },
|
|
1108
|
+
{ key: 'submodelElementCollection', parser: parseSubmodelElementCollection },
|
|
1109
|
+
{ key: 'submodelElementList', parser: parseSubmodelElementList },
|
|
1110
|
+
{ key: 'operation', parser: parseOperation },
|
|
1111
|
+
{ key: 'capability', parser: parseCapability },
|
|
1112
|
+
{ key: 'basicEventElement', parser: parseBasicEventElement },
|
|
1113
|
+
];
|
|
1114
|
+
for (const { key, parser } of elementTypes) {
|
|
1115
|
+
if (data[key]) {
|
|
1116
|
+
const items = Array.isArray(data[key]) ? data[key] : [data[key]];
|
|
1117
|
+
elements.push(...items.map(parser));
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
return elements;
|
|
1121
|
+
}
|
|
1122
|
+
function parseProperty(data) {
|
|
1123
|
+
// Map XML valueType string to DataTypeDefXsd enum
|
|
1124
|
+
let valueType = data.valueType || undefined;
|
|
1125
|
+
if (valueType && typeof valueType === 'string') {
|
|
1126
|
+
// Convert string to enum value using jsonization (expects xs: prefix)
|
|
1127
|
+
const result = jsonization.dataTypeDefXsdFromJsonable(valueType);
|
|
1128
|
+
if (result.error === null && result.value !== null) {
|
|
1129
|
+
valueType = result.value;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return new Property(valueType, data.extensions?.extension ? ensureArray(data.extensions.extension).map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1133
|
+
? ensureArray(data.displayName.langStringNameType).map(parseLangStringNameType)
|
|
1134
|
+
: undefined, data.description?.langStringTextType
|
|
1135
|
+
? ensureArray(data.description.langStringTextType).map(parseLangStringTextType)
|
|
1136
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1137
|
+
? ensureArray(data.supplementalSemanticIds.reference).map(parseReference)
|
|
1138
|
+
: undefined, data.qualifiers?.qualifier ? ensureArray(data.qualifiers.qualifier).map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1139
|
+
? ensureArray(data.embeddedDataSpecifications.embeddedDataSpecification).map(parseEmbeddedDataSpecification)
|
|
1140
|
+
: undefined, data.value || undefined, data.valueId ? parseReference(data.valueId) : undefined);
|
|
1141
|
+
}
|
|
1142
|
+
function parseMultiLanguageProperty(data) {
|
|
1143
|
+
return new MultiLanguageProperty(data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1144
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1145
|
+
: undefined, data.description?.langStringTextType
|
|
1146
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1147
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1148
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1149
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1150
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1151
|
+
: undefined, data.value?.langStringTextType ? data.value.langStringTextType.map(parseLangStringTextType) : undefined, data.valueId ? parseReference(data.valueId) : undefined);
|
|
1152
|
+
}
|
|
1153
|
+
function parseRange(data) {
|
|
1154
|
+
// Map XML valueType string to DataTypeDefXsd enum
|
|
1155
|
+
let valueType = data.valueType || undefined;
|
|
1156
|
+
if (valueType && typeof valueType === 'string') {
|
|
1157
|
+
// Convert string to enum value using jsonization (expects xs: prefix)
|
|
1158
|
+
const result = jsonization.dataTypeDefXsdFromJsonable(valueType);
|
|
1159
|
+
if (result.error === null && result.value !== null) {
|
|
1160
|
+
valueType = result.value;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return new Range(valueType, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1164
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1165
|
+
: undefined, data.description?.langStringTextType
|
|
1166
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1167
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1168
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1169
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1170
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1171
|
+
: undefined, data.min || undefined, data.max || undefined);
|
|
1172
|
+
}
|
|
1173
|
+
function parseReferenceElement(data) {
|
|
1174
|
+
return new ReferenceElement(data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1175
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1176
|
+
: undefined, data.description?.langStringTextType
|
|
1177
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1178
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1179
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1180
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1181
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1182
|
+
: undefined, data.value ? parseReference(data.value) : undefined);
|
|
1183
|
+
}
|
|
1184
|
+
function parseBlob(data) {
|
|
1185
|
+
return new Blob(data.contentType, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1186
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1187
|
+
: undefined, data.description?.langStringTextType
|
|
1188
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1189
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1190
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1191
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1192
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1193
|
+
: undefined, data.value || undefined);
|
|
1194
|
+
}
|
|
1195
|
+
function parseFile(data) {
|
|
1196
|
+
return new File(data.contentType, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1197
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1198
|
+
: undefined, data.description?.langStringTextType
|
|
1199
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1200
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1201
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1202
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1203
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1204
|
+
: undefined, data.value || undefined);
|
|
1205
|
+
}
|
|
1206
|
+
function parseEntity(data) {
|
|
1207
|
+
const entityType = data.entityType
|
|
1208
|
+
? (jsonization.entityTypeFromJsonable(data.entityType).value ?? data.entityType)
|
|
1209
|
+
: undefined;
|
|
1210
|
+
return new Entity(entityType, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1211
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1212
|
+
: undefined, data.description?.langStringTextType
|
|
1213
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1214
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1215
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1216
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1217
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1218
|
+
: undefined, data.statements ? parseSubmodelElements(data.statements) : undefined, data.globalAssetId || undefined, data.specificAssetIds?.specificAssetId
|
|
1219
|
+
? data.specificAssetIds.specificAssetId.map(parseSpecificAssetId)
|
|
1220
|
+
: undefined);
|
|
1221
|
+
}
|
|
1222
|
+
function parseRelationshipElement(data) {
|
|
1223
|
+
return new RelationshipElement(parseReference(data.first), parseReference(data.second), data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1224
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1225
|
+
: undefined, data.description?.langStringTextType
|
|
1226
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1227
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1228
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1229
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1230
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1231
|
+
: undefined);
|
|
1232
|
+
}
|
|
1233
|
+
function parseAnnotatedRelationshipElement(data) {
|
|
1234
|
+
return new AnnotatedRelationshipElement(parseReference(data.first), parseReference(data.second), data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1235
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1236
|
+
: undefined, data.description?.langStringTextType
|
|
1237
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1238
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1239
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1240
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1241
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1242
|
+
: undefined, data.annotations ? parseSubmodelElements(data.annotations) : undefined);
|
|
1243
|
+
}
|
|
1244
|
+
function parseSubmodelElementCollection(data) {
|
|
1245
|
+
return new SubmodelElementCollection(data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1246
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1247
|
+
: undefined, data.description?.langStringTextType
|
|
1248
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1249
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1250
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1251
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1252
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1253
|
+
: undefined, data.value ? parseSubmodelElements(data.value) : undefined);
|
|
1254
|
+
}
|
|
1255
|
+
function parseSubmodelElementList(data) {
|
|
1256
|
+
// Convert string to enum value
|
|
1257
|
+
const typeValueListElement = data.typeValueListElement
|
|
1258
|
+
? (jsonization.aasSubmodelElementsFromJsonable(data.typeValueListElement).value ?? data.typeValueListElement)
|
|
1259
|
+
: undefined;
|
|
1260
|
+
return new SubmodelElementList(typeValueListElement, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1261
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1262
|
+
: undefined, data.description?.langStringTextType
|
|
1263
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1264
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1265
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1266
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1267
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1268
|
+
: undefined, data.orderRelevant !== undefined ? data.orderRelevant === 'true' || data.orderRelevant === true : undefined, data.semanticIdListElement ? parseReference(data.semanticIdListElement) : undefined, data.valueTypeListElement || undefined, data.value ? parseSubmodelElements(data.value) : undefined);
|
|
1269
|
+
}
|
|
1270
|
+
function parseOperation(data) {
|
|
1271
|
+
const ensureArray = (val) => (Array.isArray(val) ? val : val ? [val] : []);
|
|
1272
|
+
return new Operation(data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1273
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1274
|
+
: undefined, data.description?.langStringTextType
|
|
1275
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1276
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1277
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1278
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1279
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1280
|
+
: undefined, data.inputVariables?.operationVariable
|
|
1281
|
+
? ensureArray(data.inputVariables.operationVariable)
|
|
1282
|
+
.map(parseOperationVariable)
|
|
1283
|
+
.filter((v) => v !== null)
|
|
1284
|
+
: undefined, data.outputVariables?.operationVariable
|
|
1285
|
+
? ensureArray(data.outputVariables.operationVariable)
|
|
1286
|
+
.map(parseOperationVariable)
|
|
1287
|
+
.filter((v) => v !== null)
|
|
1288
|
+
: undefined, data.inoutputVariables?.operationVariable
|
|
1289
|
+
? ensureArray(data.inoutputVariables.operationVariable)
|
|
1290
|
+
.map(parseOperationVariable)
|
|
1291
|
+
.filter((v) => v !== null)
|
|
1292
|
+
: undefined);
|
|
1293
|
+
}
|
|
1294
|
+
function parseOperationVariable(data) {
|
|
1295
|
+
// The value of an operation variable is a submodel element
|
|
1296
|
+
// We need to determine which type it is and parse it accordingly
|
|
1297
|
+
if (data.value) {
|
|
1298
|
+
const subElements = parseSubmodelElements(data.value);
|
|
1299
|
+
if (subElements.length > 0) {
|
|
1300
|
+
return new OperationVariable(subElements[0]);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
// OperationVariable requires a value, so return null if not available
|
|
1304
|
+
// This will be filtered out when mapping
|
|
1305
|
+
return null;
|
|
1306
|
+
}
|
|
1307
|
+
function parseCapability(data) {
|
|
1308
|
+
return new Capability(data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1309
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1310
|
+
: undefined, data.description?.langStringTextType
|
|
1311
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1312
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1313
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1314
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1315
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1316
|
+
: undefined);
|
|
1317
|
+
}
|
|
1318
|
+
function parseBasicEventElement(data) {
|
|
1319
|
+
const direction = data.direction
|
|
1320
|
+
? (jsonization.directionFromJsonable(data.direction).value ?? data.direction)
|
|
1321
|
+
: undefined;
|
|
1322
|
+
const state = data.state ? (jsonization.stateOfEventFromJsonable(data.state).value ?? data.state) : undefined;
|
|
1323
|
+
return new BasicEventElement(parseReference(data.observed), direction, state, data.extensions?.extension ? data.extensions.extension.map(parseExtension) : undefined, data.category || undefined, data.idShort || undefined, data.displayName?.langStringNameType
|
|
1324
|
+
? data.displayName.langStringNameType.map(parseLangStringNameType)
|
|
1325
|
+
: undefined, data.description?.langStringTextType
|
|
1326
|
+
? data.description.langStringTextType.map(parseLangStringTextType)
|
|
1327
|
+
: undefined, data.semanticId ? parseReference(data.semanticId) : undefined, data.supplementalSemanticIds?.reference
|
|
1328
|
+
? data.supplementalSemanticIds.reference.map(parseReference)
|
|
1329
|
+
: undefined, data.qualifiers?.qualifier ? data.qualifiers.qualifier.map(parseQualifier) : undefined, data.embeddedDataSpecifications?.embeddedDataSpecification
|
|
1330
|
+
? data.embeddedDataSpecifications.embeddedDataSpecification.map(parseEmbeddedDataSpecification)
|
|
1331
|
+
: undefined, data.messageTopic || undefined, data.messageBroker ? parseReference(data.messageBroker) : undefined, data.lastUpdate || undefined, data.minInterval || undefined, data.maxInterval || undefined);
|
|
1332
|
+
}
|