1
1
import { ApiCommunication , Topic } from './parsedApiConfigurationTypes' ;
2
2
3
- type RawCommunication = Partial < ApiCommunication > & {
3
+ // Définir un type plus large pour couvrir les cas transformés depuis le XML
4
+ export type RawCommunication = {
4
5
attributes ?: Partial < ApiCommunication [ 'attributes' ] > ;
5
- topic ?: Topic | Topic [ ] | undefined ;
6
- [ key : string ] : unknown ;
6
+ topic ?: { value ?: string } | { value ?: string } [ ] ;
7
7
} ;
8
8
9
9
export function normalizeCommunication ( input : RawCommunication ) : ApiCommunication {
10
+ const attr = input . attributes ?? { } ;
11
+
10
12
return {
11
13
attributes : {
12
- componentCode : input . componentCode ?? input . attributes ? .componentCode ?? '' ,
13
- stateMachineCode : input . stateMachineCode ?? input . attributes ? .stateMachineCode ,
14
- eventType : input . eventType ?? input . attributes ? .eventType ,
15
- event : input . event ?? input . attributes ? .event ,
16
- eventCode : input . eventCode ?? input . attributes ? .eventCode ,
14
+ componentCode : attr . componentCode ?? '' ,
15
+ stateMachineCode : attr . stateMachineCode ,
16
+ eventType : attr . eventType ,
17
+ event : attr . event ,
18
+ eventCode : attr . eventCode ,
17
19
} ,
18
20
topic : normalizeTopic ( input . topic ) ,
19
21
} ;
20
22
}
21
23
22
- function normalizeTopic ( topic : Topic | Topic [ ] | undefined ) : [ Topic ] {
24
+ function normalizeTopic ( topic : { value ?: string } | { value ?: string } [ ] | undefined ) : [ Topic ] {
23
25
if ( ! topic ) {
24
26
return [ { value : '' } ] ;
25
27
}
28
+
26
29
if ( Array . isArray ( topic ) ) {
27
- return topic . map ( ( t ) => ( { value : t . value ?? '' } ) ) as [ Topic ] ;
30
+ const normalized = topic . map ( ( t ) : Topic => ( { value : t . value ?? '' } ) ) ;
31
+ return normalized . length > 0 ? [ normalized [ 0 ] ] : [ { value : '' } ] ;
28
32
}
33
+
29
34
return [ { value : topic . value ?? '' } ] ;
30
- }
35
+ }
0 commit comments