Skip to content

Commit 1ec2a55

Browse files
committed
0.0.13
1 parent a3787f5 commit 1ec2a55

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
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.12",
3+
"version": "0.0.13",
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/Value.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { Serializable } from './Serializable';
33
export abstract class Value<D = unknown, S = D> extends Serializable {
44
protected _value: D | undefined;
55

6+
public get value() {
7+
return this._value;
8+
}
9+
610
public abstract setValue(value: S): this;
711

812
public toJSON() {

src/values/CustomValue.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ export class CustomValue extends Value<CustomValueData, CustomValueSetter> imple
100100
return this.definition.name;
101101
}
102102

103+
public getItemTypeDefinition(name: string) {
104+
const definition = this.definition.items!.find((item) => item.name === name);
105+
106+
if (!definition) {
107+
throw new Error(`Custom type ${this.name} has no member called ${name}.`);
108+
}
109+
110+
return definition;
111+
}
112+
103113
public setValue(value: unknown) {
104114
if (this.hasItems) {
105115
if (isObject(value)) {
@@ -160,16 +170,6 @@ export class CustomValue extends Value<CustomValueData, CustomValueSetter> imple
160170
return size || !this.hasItems ? bytes : bytesWithSize(bytes);
161171
}
162172

163-
protected getItemTypeDefinition(name: string) {
164-
const definition = this.definition.items!.find((item) => item.name === name);
165-
166-
if (!definition) {
167-
throw new Error(`Custom type ${this.name} has no member called ${name}.`);
168-
}
169-
170-
return definition;
171-
}
172-
173173
protected isVariableSizeSubtype({ customType, type }: TypeDefinition, hasItems = true) {
174174
return (
175175
hasItems &&

src/values/UnitValue.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ export class UnitValue extends Value<UnitValueData, UnitValueDataSetter> impleme
6868
return this.definition.name;
6969
}
7070

71+
public getFirstUnitDefinition() {
72+
return this.definition.unit_types[0];
73+
}
74+
75+
public getUnitDefinition<T extends keyof UnitType>(field: T, value: UnitType[T]) {
76+
const {
77+
definition: { unit_types: units },
78+
name,
79+
} = this;
80+
81+
const unit = units.find((type) => type[field] === value);
82+
83+
if (!unit) {
84+
throw new Error(
85+
`Measurement type ${name} does not define unit identified by (${field}: ${value}).`,
86+
);
87+
}
88+
89+
return unit;
90+
}
91+
7192
public setValue(data: UnitValueDataSetter) {
7293
const { unit: unitIdentifier, value: valueInUnits } = data;
7394

@@ -101,25 +122,4 @@ export class UnitValue extends Value<UnitValueData, UnitValueDataSetter> impleme
101122

102123
return null;
103124
}
104-
105-
protected getFirstUnitDefinition() {
106-
return this.definition.unit_types[0];
107-
}
108-
109-
protected getUnitDefinition<T extends keyof UnitType>(field: T, value: UnitType[T]) {
110-
const {
111-
definition: { unit_types: units },
112-
name,
113-
} = this;
114-
115-
const unit = units.find((type) => type[field] === value);
116-
117-
if (!unit) {
118-
throw new Error(
119-
`Measurement type ${name} does not define unit identified by (${field}: ${value}).`,
120-
);
121-
}
122-
123-
return unit;
124-
}
125125
}

0 commit comments

Comments
 (0)