Skip to content

Commit

Permalink
1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
unematiii committed Feb 14, 2023
1 parent 322e439 commit 899c5a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 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.3.1",
"version": "1.3.2",
"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
16 changes: 10 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>, fallbackToFirstOfType?: boolean) {
public diff(capability: Capability<P>, fallbackToFirstOfType?: boolean, strict?: 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, fallbackToFirstOfType);
const ref = this.findProperty(property, fallbackToFirstOfType, strict);
if (ref && ref.equals(property)) {
return properties;
}
Expand Down Expand Up @@ -188,11 +188,15 @@ export abstract class Capability<P extends string = string>
return property;
}

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

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

if (ref) {
ref.replace(property);
Expand Down
8 changes: 4 additions & 4 deletions src/core/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ export class Property extends Serializable implements NamedEntity {
return this;
}

public isInstanceOf(property: Property) {
public isInstanceOf(property: Property, strict?: boolean) {
const { identityKey, multiple } = property;
if (property instanceof Object.getPrototypeOf(this).constructor) {
if (multiple) {
if (identityKey && [this, property].every((p) => p.hasComponent('data'))) {
if (multiple && identityKey) {
if ([this, property].every((p) => p.hasComponent('data'))) {
const [a, b] = [this, property].map((p) => p.valueOf() || {});
return comparePropertyIdentity(a, b, identityKey);
}

return false;
}

return true;
return multiple && strict ? false : true;
}

return false;
Expand Down

0 comments on commit 899c5a9

Please sign in to comment.