Skip to content

Commit 2246fd6

Browse files
committed
Fixes custom value instantiation for ValueFactory
1 parent 7e03831 commit 2246fd6

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
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": "0.0.7",
3+
"version": "0.0.8",
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/factories/ValueFactory.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const ValueConstructors: Partial<Record<TypeDefinitionType | string, ValueConstr
4444

4545
export class ValueFactory {
4646
public static createFromDefinition(definition: TypeDefinition) {
47-
const { customType, event, type, unitType } = definition;
47+
const { customType, event, size, type, unitType } = definition;
4848

4949
const ValueConstructor =
5050
customType || event ? CustomValue : unitType ? UnitValue : ValueConstructors[type];
@@ -53,26 +53,26 @@ export class ValueFactory {
5353
case CustomValue:
5454
return new ValueConstructor(
5555
event
56-
? Configuration.getEventDefinition(definition.event as string)
57-
: Configuration.getCustomTypeDefinition(definition.customType as string),
56+
? Configuration.getEventDefinition(event)
57+
: customType
58+
? Configuration.getCustomTypeDefinition(customType)
59+
: definition,
5860
);
5961
case EnumValue:
6062
return new ValueConstructor(definition);
6163
case DoubleValue:
6264
case FloatValue:
6365
case IntegerValue:
6466
case UintValue:
65-
return new (ValueConstructor as NumericValueConstructor)(definition.size);
67+
return new (ValueConstructor as NumericValueConstructor)(size);
6668
case BytesValue:
6769
case StringValue:
6870
case TimestampValue:
6971
return new ValueConstructor();
7072
case UnitValue:
71-
return new ValueConstructor(
72-
Configuration.getMeasurementTypeDefinition(definition.unitType as string),
73-
);
73+
return new ValueConstructor(Configuration.getMeasurementTypeDefinition(unitType as string));
7474
default:
75-
throw new Error(`Unknown value type: ${definition.type}`);
75+
throw new Error(`Unknown value type: ${type}`);
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)