Skip to content

Commit 899c5a9

Browse files
committed
1.3.2
1 parent 322e439 commit 899c5a9

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
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.3.1",
3+
"version": "1.3.2",
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: 10 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>, fallbackToFirstOfType?: boolean) {
74+
public diff(capability: Capability<P>, fallbackToFirstOfType?: boolean, strict?: 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, fallbackToFirstOfType);
84+
const ref = this.findProperty(property, fallbackToFirstOfType, strict);
8585
if (ref && ref.equals(property)) {
8686
return properties;
8787
}
@@ -188,11 +188,15 @@ export abstract class Capability<P extends string = string>
188188
return property;
189189
}
190190

191-
public findProperty(property: Property, fallbackToFirstOfType?: boolean): Property | undefined {
191+
public findProperty(
192+
property: Property,
193+
fallbackToFirstOfType?: boolean,
194+
strict?: boolean,
195+
): Property | undefined {
192196
if (this.hasProperty(property.name as P)) {
193197
if (property.multiple) {
194198
const match = this.getProperties(property.name as P).find((ref) =>
195-
ref.isInstanceOf(property),
199+
ref.isInstanceOf(property, strict),
196200
);
197201
return match === undefined && fallbackToFirstOfType
198202
? this.getProperty(property.name as P)
@@ -231,9 +235,9 @@ export abstract class Capability<P extends string = string>
231235
return this;
232236
}
233237

234-
public update(capability: Capability<P>, fallbackToFirstOfType?: boolean) {
238+
public update(capability: Capability<P>, fallbackToFirstOfType?: boolean, strict?: boolean) {
235239
return capability.getPropertiesArray().reduce((result, property) => {
236-
const ref = this.findProperty(property, fallbackToFirstOfType);
240+
const ref = this.findProperty(property, fallbackToFirstOfType, strict);
237241

238242
if (ref) {
239243
ref.replace(property);

src/core/Property.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ export class Property extends Serializable implements NamedEntity {
143143
return this;
144144
}
145145

146-
public isInstanceOf(property: Property) {
146+
public isInstanceOf(property: Property, strict?: boolean) {
147147
const { identityKey, multiple } = property;
148148
if (property instanceof Object.getPrototypeOf(this).constructor) {
149-
if (multiple) {
150-
if (identityKey && [this, property].every((p) => p.hasComponent('data'))) {
149+
if (multiple && identityKey) {
150+
if ([this, property].every((p) => p.hasComponent('data'))) {
151151
const [a, b] = [this, property].map((p) => p.valueOf() || {});
152152
return comparePropertyIdentity(a, b, identityKey);
153153
}
154154

155155
return false;
156156
}
157157

158-
return true;
158+
return multiple && strict ? false : true;
159159
}
160160

161161
return false;

0 commit comments

Comments
 (0)