Skip to content

Commit 3b9b669

Browse files
committed
fix(TS): update TS with better property name and value in fromJS() and toJson()
1 parent 506935b commit 3b9b669

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2135
-769
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ ts-build:
3333
cp ./src/TypeScriptSDK/*.tgz ./
3434

3535
ts-test:
36-
cd ./src/TypeScriptSDK.Tests && npm i ./../TypeScriptSDK/dragonfly-schema-$(NEW_RELEASE_VERSION).tgz
36+
cd ./src/TypeScriptSDK.Tests && npm i ./../TypeScriptSDK/*-$(NEW_RELEASE_VERSION).tgz
3737
cd ./src/TypeScriptSDK.Tests && npm i honeybee-schema
3838
cd ./src/TypeScriptSDK.Tests && npm run test

src/TypeScriptSDK/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dragonfly-schema",
33
"license": "MIT",
4-
"version": "1.1501.0",
4+
"version": "0.0.1",
55
"description": "Dragonfly Schema's typescript version",
66
"author": "Ladybug Tools",
77
"type": "module",

src/TypeScriptSDK/src/models/Building.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IsInstance, ValidateNested, IsDefined, IsString, IsOptional, Matches, IsArray, validate, ValidationError as TsValidationError } from 'class-validator';
2-
import { Type, plainToClass, instanceToPlain, Transform } from 'class-transformer';
2+
import { Type, plainToClass, instanceToPlain, Expose, Transform } from 'class-transformer';
33
import { BuildingPropertiesAbridged } from "./BuildingPropertiesAbridged";
44
import { IDdBaseModel } from "honeybee-schema";
55
import { RoofSpecification } from "./RoofSpecification";
@@ -12,53 +12,58 @@ export class Building extends IDdBaseModel {
1212
@Type(() => BuildingPropertiesAbridged)
1313
@ValidateNested()
1414
@IsDefined()
15+
@Expose({ name: "properties" })
1516
/** Extension properties for particular simulation engines (Radiance, EnergyPlus). */
16-
Properties!: BuildingPropertiesAbridged;
17+
properties!: BuildingPropertiesAbridged;
1718

1819
@IsString()
1920
@IsOptional()
2021
@Matches(/^Building$/)
21-
/** Type */
22-
Type: string = "Building";
22+
@Expose({ name: "type" })
23+
/** type */
24+
type: string = "Building";
2325

2426
@IsArray()
2527
@IsInstance(Story, { each: true })
2628
@Type(() => Story)
2729
@ValidateNested({ each: true })
2830
@IsOptional()
31+
@Expose({ name: "unique_stories" })
2932
/** An array of unique dragonfly Story objects that together form the entire building. Stories should generally be ordered from lowest floor to highest floor, though this is not required. Note that, if a given Story is repeated several times over the height of the building and this is represented by the multiplier, the unique story included in this list should be the first (lowest) story of the repeated floors. */
30-
UniqueStories?: Story[];
33+
uniqueStories?: Story[];
3134

3235
@IsArray()
3336
@IsInstance(Room, { each: true })
3437
@Type(() => Room)
3538
@ValidateNested({ each: true })
3639
@IsOptional()
40+
@Expose({ name: "room_3ds" })
3741
/** An optional array of 3D Honeybee Room objects for additional Rooms that are a part of the Building but are not represented within the unique_stories. This is useful when there are parts of the Building geometry that cannot easily be represented with the extruded floor plate and sloped roof assumptions that underlie Dragonfly Room2Ds and RoofSpecification. Cases where this input is most useful include sloped walls and certain types of domed roofs that become tedious to implement with RoofSpecification. Matching the Honeybee Room.story property to the Dragonfly Story.display_name of an object within the unique_stories will effectively place the Honeybee Room on that Story for the purposes of floor_area, exterior_wall_area, etc. However, note that the Honeybee Room.multiplier property takes precedence over whatever multiplier is assigned to the Dragonfly Story that the Room.story may reference. (Default: None). */
38-
Room3ds?: Room[];
42+
room3ds?: Room[];
3943

4044
@IsInstance(RoofSpecification)
4145
@Type(() => RoofSpecification)
4246
@ValidateNested()
4347
@IsOptional()
48+
@Expose({ name: "roof" })
4449
/** An optional RoofSpecification object that provides an alternative way to describe roof geometry over rooms (instead of specifying roofs on each story). If trying to decide between the two, specifying geometry on each story is closer to how dragonfly natively works with roof geometry as it relates to rooms. However, when it is unknown which roof geometries correspond to which stories, this Building-level attribute may be used and each roof geometry will automatically be added to the best Story in the Building upon serialization to Python. This automatic assignment will happen by checking for overlaps between the Story Room2Ds and the Roof geometry in plan. When a given roof geometry overlaps with several Stories, the top-most Story will get the roof geometry assigned to it unless this top Story has a floor_height above the roof geometry, in which case the next highest story will be checked until a compatible one is found. */
45-
Roof?: RoofSpecification;
50+
roof?: RoofSpecification;
4651

4752

4853
constructor() {
4954
super();
50-
this.Type = "Building";
55+
this.type = "Building";
5156
}
5257

5358

5459
override init(_data?: any) {
5560
super.init(_data);
5661
if (_data) {
57-
const obj = plainToClass(Building, _data, { enableImplicitConversion: true });
62+
const obj = plainToClass(Building, _data, { enableImplicitConversion: true, exposeUnsetFields: false });
5863
this.properties = obj.properties;
59-
this.type = obj.type;
60-
this.unique_stories = obj.unique_stories;
61-
this.room_3ds = obj.room_3ds;
64+
this.type = obj.type ?? "Building";
65+
this.uniqueStories = obj.uniqueStories;
66+
this.room3ds = obj.room3ds;
6267
this.roof = obj.roof;
6368
}
6469
}
@@ -82,12 +87,12 @@ export class Building extends IDdBaseModel {
8287
override toJSON(data?: any) {
8388
data = typeof data === 'object' ? data : {};
8489
data["properties"] = this.properties;
85-
data["type"] = this.type;
86-
data["unique_stories"] = this.unique_stories;
87-
data["room_3ds"] = this.room_3ds;
90+
data["type"] = this.type ?? "Building";
91+
data["unique_stories"] = this.uniqueStories;
92+
data["room_3ds"] = this.room3ds;
8893
data["roof"] = this.roof;
8994
data = super.toJSON(data);
90-
return instanceToPlain(data);
95+
return instanceToPlain(data, { exposeUnsetFields: false });
9196
}
9297

9398
async validate(): Promise<boolean> {

src/TypeScriptSDK/src/models/BuildingEnergyPropertiesAbridged.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
11
import { IsString, IsOptional, Matches, MinLength, MaxLength, validate, ValidationError as TsValidationError } from 'class-validator';
2-
import { Type, plainToClass, instanceToPlain, Transform } from 'class-transformer';
2+
import { Type, plainToClass, instanceToPlain, Expose, Transform } from 'class-transformer';
33
import { _OpenAPIGenBaseModel } from "./_OpenAPIGenBaseModel";
44

55
/** Base class for all objects that are not extensible with additional keys.\n\nThis effectively includes all objects except for the Properties classes\nthat are assigned to geometry objects. */
66
export class BuildingEnergyPropertiesAbridged extends _OpenAPIGenBaseModel {
77
@IsString()
88
@IsOptional()
99
@Matches(/^BuildingEnergyPropertiesAbridged$/)
10-
/** Type */
11-
Type: string = "BuildingEnergyPropertiesAbridged";
10+
@Expose({ name: "type" })
11+
/** type */
12+
type: string = "BuildingEnergyPropertiesAbridged";
1213

1314
@IsString()
1415
@IsOptional()
1516
@MinLength(1)
1617
@MaxLength(100)
18+
@Expose({ name: "construction_set" })
1719
/** Name of a ConstructionSet to specify all constructions for the Building. If None, the Model global_construction_set will be used. */
18-
ConstructionSet?: string;
20+
constructionSet?: string;
1921

2022
@IsString()
2123
@IsOptional()
2224
@MinLength(1)
2325
@MaxLength(100)
26+
@Expose({ name: "ceiling_plenum_construction" })
2427
/** Identifier of an OpaqueConstruction for the bottoms of ceiling plenums. Materials should be ordered from the plenum side to the room side. By default, this is a simple acoustic tile construction. */
25-
CeilingPlenumConstruction?: string;
28+
ceilingPlenumConstruction?: string;
2629

2730
@IsString()
2831
@IsOptional()
2932
@MinLength(1)
3033
@MaxLength(100)
34+
@Expose({ name: "floor_plenum_construction" })
3135
/** Identifier of an OpaqueConstruction for the tops of floor plenums. Materials should be ordered from the plenum side to the room side. By default, this is a simple wood plank construction. */
32-
FloorPlenumConstruction?: string;
36+
floorPlenumConstruction?: string;
3337

3438

3539
constructor() {
3640
super();
37-
this.Type = "BuildingEnergyPropertiesAbridged";
41+
this.type = "BuildingEnergyPropertiesAbridged";
3842
}
3943

4044

4145
override init(_data?: any) {
4246
super.init(_data);
4347
if (_data) {
44-
const obj = plainToClass(BuildingEnergyPropertiesAbridged, _data, { enableImplicitConversion: true });
45-
this.type = obj.type;
46-
this.construction_set = obj.construction_set;
47-
this.ceiling_plenum_construction = obj.ceiling_plenum_construction;
48-
this.floor_plenum_construction = obj.floor_plenum_construction;
48+
const obj = plainToClass(BuildingEnergyPropertiesAbridged, _data, { enableImplicitConversion: true, exposeUnsetFields: false });
49+
this.type = obj.type ?? "BuildingEnergyPropertiesAbridged";
50+
this.constructionSet = obj.constructionSet;
51+
this.ceilingPlenumConstruction = obj.ceilingPlenumConstruction;
52+
this.floorPlenumConstruction = obj.floorPlenumConstruction;
4953
}
5054
}
5155

@@ -67,12 +71,12 @@ export class BuildingEnergyPropertiesAbridged extends _OpenAPIGenBaseModel {
6771

6872
override toJSON(data?: any) {
6973
data = typeof data === 'object' ? data : {};
70-
data["type"] = this.type;
71-
data["construction_set"] = this.construction_set;
72-
data["ceiling_plenum_construction"] = this.ceiling_plenum_construction;
73-
data["floor_plenum_construction"] = this.floor_plenum_construction;
74+
data["type"] = this.type ?? "BuildingEnergyPropertiesAbridged";
75+
data["construction_set"] = this.constructionSet;
76+
data["ceiling_plenum_construction"] = this.ceilingPlenumConstruction;
77+
data["floor_plenum_construction"] = this.floorPlenumConstruction;
7478
data = super.toJSON(data);
75-
return instanceToPlain(data);
79+
return instanceToPlain(data, { exposeUnsetFields: false });
7680
}
7781

7882
async validate(): Promise<boolean> {

src/TypeScriptSDK/src/models/BuildingPropertiesAbridged.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IsString, IsOptional, Matches, IsInstance, ValidateNested, validate, ValidationError as TsValidationError } from 'class-validator';
2-
import { Type, plainToClass, instanceToPlain, Transform } from 'class-transformer';
2+
import { Type, plainToClass, instanceToPlain, Expose, Transform } from 'class-transformer';
33
import { _OpenAPIGenBaseModel } from "./_OpenAPIGenBaseModel";
44
import { BuildingEnergyPropertiesAbridged } from "./BuildingEnergyPropertiesAbridged";
55
import { BuildingRadiancePropertiesAbridged } from "./BuildingRadiancePropertiesAbridged";
@@ -8,35 +8,38 @@ export class BuildingPropertiesAbridged extends _OpenAPIGenBaseModel {
88
@IsString()
99
@IsOptional()
1010
@Matches(/^BuildingPropertiesAbridged$/)
11-
/** Type */
12-
Type: string = "BuildingPropertiesAbridged";
11+
@Expose({ name: "type" })
12+
/** type */
13+
type: string = "BuildingPropertiesAbridged";
1314

1415
@IsInstance(BuildingEnergyPropertiesAbridged)
1516
@Type(() => BuildingEnergyPropertiesAbridged)
1617
@ValidateNested()
1718
@IsOptional()
18-
/** Energy */
19-
Energy?: BuildingEnergyPropertiesAbridged;
19+
@Expose({ name: "energy" })
20+
/** energy */
21+
energy?: BuildingEnergyPropertiesAbridged;
2022

2123
@IsInstance(BuildingRadiancePropertiesAbridged)
2224
@Type(() => BuildingRadiancePropertiesAbridged)
2325
@ValidateNested()
2426
@IsOptional()
25-
/** Radiance */
26-
Radiance?: BuildingRadiancePropertiesAbridged;
27+
@Expose({ name: "radiance" })
28+
/** radiance */
29+
radiance?: BuildingRadiancePropertiesAbridged;
2730

2831

2932
constructor() {
3033
super();
31-
this.Type = "BuildingPropertiesAbridged";
34+
this.type = "BuildingPropertiesAbridged";
3235
}
3336

3437

3538
override init(_data?: any) {
3639
super.init(_data);
3740
if (_data) {
38-
const obj = plainToClass(BuildingPropertiesAbridged, _data, { enableImplicitConversion: true });
39-
this.type = obj.type;
41+
const obj = plainToClass(BuildingPropertiesAbridged, _data, { enableImplicitConversion: true, exposeUnsetFields: false });
42+
this.type = obj.type ?? "BuildingPropertiesAbridged";
4043
this.energy = obj.energy;
4144
this.radiance = obj.radiance;
4245
}
@@ -60,11 +63,11 @@ export class BuildingPropertiesAbridged extends _OpenAPIGenBaseModel {
6063

6164
override toJSON(data?: any) {
6265
data = typeof data === 'object' ? data : {};
63-
data["type"] = this.type;
66+
data["type"] = this.type ?? "BuildingPropertiesAbridged";
6467
data["energy"] = this.energy;
6568
data["radiance"] = this.radiance;
6669
data = super.toJSON(data);
67-
return instanceToPlain(data);
70+
return instanceToPlain(data, { exposeUnsetFields: false });
6871
}
6972

7073
async validate(): Promise<boolean> {

src/TypeScriptSDK/src/models/BuildingRadiancePropertiesAbridged.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import { IsString, IsOptional, Matches, validate, ValidationError as TsValidationError } from 'class-validator';
2-
import { Type, plainToClass, instanceToPlain, Transform } from 'class-transformer';
2+
import { Type, plainToClass, instanceToPlain, Expose, Transform } from 'class-transformer';
33
import { _OpenAPIGenBaseModel } from "./_OpenAPIGenBaseModel";
44

55
/** Base class for all objects that are not extensible with additional keys.\n\nThis effectively includes all objects except for the Properties classes\nthat are assigned to geometry objects. */
66
export class BuildingRadiancePropertiesAbridged extends _OpenAPIGenBaseModel {
77
@IsString()
88
@IsOptional()
99
@Matches(/^BuildingRadiancePropertiesAbridged$/)
10-
/** Type */
11-
Type: string = "BuildingRadiancePropertiesAbridged";
10+
@Expose({ name: "type" })
11+
/** type */
12+
type: string = "BuildingRadiancePropertiesAbridged";
1213

1314
@IsString()
1415
@IsOptional()
16+
@Expose({ name: "modifier_set" })
1517
/** Name of a ModifierSet to specify all modifiers for the Building. If None, the Model global_modifier_set will be used. */
16-
ModifierSet?: string;
18+
modifierSet?: string;
1719

1820

1921
constructor() {
2022
super();
21-
this.Type = "BuildingRadiancePropertiesAbridged";
23+
this.type = "BuildingRadiancePropertiesAbridged";
2224
}
2325

2426

2527
override init(_data?: any) {
2628
super.init(_data);
2729
if (_data) {
28-
const obj = plainToClass(BuildingRadiancePropertiesAbridged, _data, { enableImplicitConversion: true });
29-
this.type = obj.type;
30-
this.modifier_set = obj.modifier_set;
30+
const obj = plainToClass(BuildingRadiancePropertiesAbridged, _data, { enableImplicitConversion: true, exposeUnsetFields: false });
31+
this.type = obj.type ?? "BuildingRadiancePropertiesAbridged";
32+
this.modifierSet = obj.modifierSet;
3133
}
3234
}
3335

@@ -49,10 +51,10 @@ export class BuildingRadiancePropertiesAbridged extends _OpenAPIGenBaseModel {
4951

5052
override toJSON(data?: any) {
5153
data = typeof data === 'object' ? data : {};
52-
data["type"] = this.type;
53-
data["modifier_set"] = this.modifier_set;
54+
data["type"] = this.type ?? "BuildingRadiancePropertiesAbridged";
55+
data["modifier_set"] = this.modifierSet;
5456
data = super.toJSON(data);
55-
return instanceToPlain(data);
57+
return instanceToPlain(data, { exposeUnsetFields: false });
5658
}
5759

5860
async validate(): Promise<boolean> {

0 commit comments

Comments
 (0)