@@ -71,7 +71,7 @@ export abstract class Capability<P extends string = string>
71
71
return this ;
72
72
}
73
73
74
- public diff ( capability : Capability < P > ) {
74
+ public diff ( capability : Capability < P > , fallbackToFirstOfType ?: boolean ) {
75
75
const instance = new ( Object . getPrototypeOf ( this ) . constructor ) (
76
76
this . definition ,
77
77
this . universalProperties ,
@@ -81,7 +81,7 @@ export abstract class Capability<P extends string = string>
81
81
. getPropertiesArray ( )
82
82
. reduce < Property [ ] > ( ( properties , property ) => {
83
83
if ( this . hasProperty ( property . name as P ) ) {
84
- const ref = this . findProperty ( property ) ;
84
+ const ref = this . findProperty ( property , fallbackToFirstOfType ) ;
85
85
if ( ref && ref . equals ( property ) ) {
86
86
return properties ;
87
87
}
@@ -188,10 +188,15 @@ export abstract class Capability<P extends string = string>
188
188
return property ;
189
189
}
190
190
191
- public findProperty ( property : Property ) : Property | undefined {
191
+ public findProperty ( property : Property , fallbackToFirstOfType ?: boolean ) : Property | undefined {
192
192
if ( this . hasProperty ( property . name as P ) ) {
193
193
if ( property . multiple ) {
194
- return this . getProperties ( property . name as P ) . find ( ( ref ) => ref . isInstanceOf ( property ) ) ;
194
+ const match = this . getProperties ( property . name as P ) . find ( ( ref ) =>
195
+ ref . isInstanceOf ( property ) ,
196
+ ) ;
197
+ return match === undefined && fallbackToFirstOfType
198
+ ? this . getProperty ( property . name as P )
199
+ : match ;
195
200
} else {
196
201
return this . getProperty ( property . name as P ) ;
197
202
}
@@ -226,9 +231,9 @@ export abstract class Capability<P extends string = string>
226
231
return this ;
227
232
}
228
233
229
- public update ( capability : Capability < P > ) {
234
+ public update ( capability : Capability < P > , fallbackToFirstOfType ?: boolean ) {
230
235
return capability . getPropertiesArray ( ) . reduce ( ( result , property ) => {
231
- const ref = this . findProperty ( property ) ;
236
+ const ref = this . findProperty ( property , fallbackToFirstOfType ) ;
232
237
233
238
if ( ref ) {
234
239
ref . replace ( property ) ;
0 commit comments