Skip to content

Commit 412b524

Browse files
committed
update
1 parent bc794a4 commit 412b524

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
import { ApiCommunication, Topic } from './parsedApiConfigurationTypes';
22

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 = {
45
attributes?: Partial<ApiCommunication['attributes']>;
5-
topic?: Topic | Topic[] | undefined;
6-
[key: string]: unknown;
6+
topic?: { value?: string } | { value?: string }[];
77
};
88

99
export function normalizeCommunication(input: RawCommunication): ApiCommunication {
10+
const attr = input.attributes ?? {};
11+
1012
return {
1113
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,
1719
},
1820
topic: normalizeTopic(input.topic),
1921
};
2022
}
2123

22-
function normalizeTopic(topic: Topic | Topic[] | undefined): [Topic] {
24+
function normalizeTopic(topic: { value?: string } | { value?: string }[] | undefined): [Topic] {
2325
if (!topic) {
2426
return [{ value: '' }];
2527
}
28+
2629
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: '' }];
2832
}
33+
2934
return [{ value: topic.value ?? '' }];
30-
}
35+
}

src/configuration/parsedApiConfigurationTypes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ export interface ParsedApiConfiguration {
44
deployment: Deployment;
55
}
66

7+
export type RawCommunication = {
8+
componentCode?: string;
9+
stateMachineCode?: string;
10+
eventType?: string;
11+
event?: string;
12+
eventCode?: string;
13+
topic?: { value?: string } | { value?: string }[];
14+
attributes?: {
15+
componentCode?: string;
16+
stateMachineCode?: string;
17+
eventType?: string;
18+
event?: string;
19+
eventCode?: string;
20+
};
21+
};
22+
723
export interface ApiCommunication {
824
attributes: {
925
componentCode: string;

0 commit comments

Comments
 (0)