Skip to content

Commit 7b26532

Browse files
committed
1.1.4
1 parent 0c7bfd6 commit 7b26532

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@highmobility/auto-api-javascript",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Auto API for JavaScript - the parsing library for the Auto API vehicle data model",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/core/Capability.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export abstract class Capability<P extends string = string>
7171
return this;
7272
}
7373

74-
public diff(capability: Capability<P>) {
74+
public diff(capability: Capability<P>, fallbackToFirstOfType?: boolean) {
7575
const instance = new (Object.getPrototypeOf(this).constructor)(
7676
this.definition,
7777
this.universalProperties,
@@ -81,7 +81,7 @@ export abstract class Capability<P extends string = string>
8181
.getPropertiesArray()
8282
.reduce<Property[]>((properties, property) => {
8383
if (this.hasProperty(property.name as P)) {
84-
const ref = this.findProperty(property);
84+
const ref = this.findProperty(property, fallbackToFirstOfType);
8585
if (ref && ref.equals(property)) {
8686
return properties;
8787
}
@@ -188,10 +188,15 @@ export abstract class Capability<P extends string = string>
188188
return property;
189189
}
190190

191-
public findProperty(property: Property): Property | undefined {
191+
public findProperty(property: Property, fallbackToFirstOfType?: boolean): Property | undefined {
192192
if (this.hasProperty(property.name as P)) {
193193
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;
195200
} else {
196201
return this.getProperty(property.name as P);
197202
}
@@ -226,9 +231,9 @@ export abstract class Capability<P extends string = string>
226231
return this;
227232
}
228233

229-
public update(capability: Capability<P>) {
234+
public update(capability: Capability<P>, fallbackToFirstOfType?: boolean) {
230235
return capability.getPropertiesArray().reduce((result, property) => {
231-
const ref = this.findProperty(property);
236+
const ref = this.findProperty(property, fallbackToFirstOfType);
232237

233238
if (ref) {
234239
ref.replace(property);

0 commit comments

Comments
 (0)