6
6
StateMachine ,
7
7
} from './parsedApiConfigurationTypes' ;
8
8
9
+ import { normalizeCommunication } from './apiCommunicationUtils' ;
10
+
9
11
export interface PublisherDetails {
10
12
eventCode : number ;
11
13
routingKey : string ;
@@ -125,7 +127,7 @@ export class DefaultApiConfiguration implements ApiConfiguration {
125
127
containsStateMachine ( componentName : string , stateMachineName : string ) : boolean {
126
128
const result = this . findComponent ( component => component . name === componentName ) ;
127
129
if ( result ) {
128
- return result . stateMachines [ 0 ] . stateMachine . find ( stm => stm . attributes . name === stateMachineName ) != null ;
130
+ return result . stateMachines . stateMachine . find ( stm => stm . name === stateMachineName ) != null ;
129
131
}
130
132
return false ;
131
133
}
@@ -158,7 +160,11 @@ export class DefaultApiConfiguration implements ApiConfiguration {
158
160
stateMachineCode : number ,
159
161
messageType : string
160
162
) : ApiCommunication | undefined {
161
- return this . _config . deployment . clientAPICommunication [ 0 ] . publish . find (
163
+ const raw = this . _config . deployment . clientAPICommunication . publish ;
164
+ const publishArrayRaw = Array . isArray ( raw ) ? raw : [ raw ] ;
165
+ const publishArray = publishArrayRaw . map ( normalizeCommunication ) ;
166
+
167
+ return publishArray . find (
162
168
pub =>
163
169
Number ( pub . attributes . componentCode ) === componentCode &&
164
170
Number ( pub . attributes . stateMachineCode ) === stateMachineCode &&
@@ -183,18 +189,24 @@ export class DefaultApiConfiguration implements ApiConfiguration {
183
189
stateMachineCode : number ,
184
190
type : SubscriberEventType
185
191
) : ApiCommunication | undefined {
186
- return this . _config . deployment . clientAPICommunication [ 0 ] . subscribe . find (
187
- pub =>
188
- Number ( pub . attributes . componentCode ) === componentCode &&
189
- Number ( pub . attributes . stateMachineCode ) === stateMachineCode &&
190
- pub . attributes . eventType === SubscriberEventType [ type ] . toUpperCase ( )
192
+ const raw = this . _config . deployment . clientAPICommunication . subscribe ;
193
+ const subscribeArrayRaw = Array . isArray ( raw ) ? raw : [ raw ] ;
194
+ const subscribeArray = subscribeArrayRaw . map ( normalizeCommunication ) ;
195
+
196
+ return subscribeArray . find (
197
+ sub =>
198
+ Number ( sub . attributes . componentCode ) === componentCode &&
199
+ Number ( sub . attributes . stateMachineCode ) === stateMachineCode &&
200
+ sub . attributes . eventType === SubscriberEventType [ type ] . toUpperCase ( )
191
201
) ;
192
202
}
193
203
194
204
getSnapshotTopic ( componentCode : number ) : string {
195
- const snapshot = this . _config . deployment . clientAPICommunication [ 0 ] . snapshot . find (
196
- pub => Number ( pub . attributes . componentCode ) === componentCode
197
- ) ;
205
+ const raw = this . _config . deployment . clientAPICommunication . snapshot ;
206
+ const snapshotArrayRaw = Array . isArray ( raw ) ? raw : [ raw ] ;
207
+ const snapshotArray = snapshotArrayRaw . map ( normalizeCommunication ) ;
208
+
209
+ const snapshot = snapshotArray . find ( pub => Number ( pub . attributes . componentCode ) === componentCode ) ;
198
210
199
211
if ( ! snapshot ) {
200
212
throw new Error ( `Snapshot topic not found - component code: ${ componentCode } ` ) ;
0 commit comments