Skip to content

Commit

Permalink
1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
unematiii committed Jun 21, 2022
1 parent 0c7bfd6 commit 7b26532
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@highmobility/auto-api-javascript",
"version": "1.1.3",
"version": "1.1.4",
"description": "Auto API for JavaScript - the parsing library for the Auto API vehicle data model",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
17 changes: 11 additions & 6 deletions src/core/Capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export abstract class Capability<P extends string = string>
return this;
}

public diff(capability: Capability<P>) {
public diff(capability: Capability<P>, fallbackToFirstOfType?: boolean) {
const instance = new (Object.getPrototypeOf(this).constructor)(
this.definition,
this.universalProperties,
Expand All @@ -81,7 +81,7 @@ export abstract class Capability<P extends string = string>
.getPropertiesArray()
.reduce<Property[]>((properties, property) => {
if (this.hasProperty(property.name as P)) {
const ref = this.findProperty(property);
const ref = this.findProperty(property, fallbackToFirstOfType);
if (ref && ref.equals(property)) {
return properties;
}
Expand Down Expand Up @@ -188,10 +188,15 @@ export abstract class Capability<P extends string = string>
return property;
}

public findProperty(property: Property): Property | undefined {
public findProperty(property: Property, fallbackToFirstOfType?: boolean): Property | undefined {
if (this.hasProperty(property.name as P)) {
if (property.multiple) {
return this.getProperties(property.name as P).find((ref) => ref.isInstanceOf(property));
const match = this.getProperties(property.name as P).find((ref) =>
ref.isInstanceOf(property),
);
return match === undefined && fallbackToFirstOfType
? this.getProperty(property.name as P)
: match;
} else {
return this.getProperty(property.name as P);
}
Expand Down Expand Up @@ -226,9 +231,9 @@ export abstract class Capability<P extends string = string>
return this;
}

public update(capability: Capability<P>) {
public update(capability: Capability<P>, fallbackToFirstOfType?: boolean) {
return capability.getPropertiesArray().reduce((result, property) => {
const ref = this.findProperty(property);
const ref = this.findProperty(property, fallbackToFirstOfType);

if (ref) {
ref.replace(property);
Expand Down

0 comments on commit 7b26532

Please sign in to comment.