Skip to content

Commit

Permalink
Refactor/make toISO calls typesafe (#41)
Browse files Browse the repository at this point in the history
* chore: bump libs

* chore: remove any cast

* refactor: make toISO usage typesafe
  • Loading branch information
jkoenig134 committed Feb 29, 2024
1 parent 0f1c06d commit 8bcf439
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
21 changes: 11 additions & 10 deletions 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
Expand Up @@ -27,7 +27,7 @@
"@js-soft/eslint-config-ts": "^1.6.6",
"@js-soft/license-check": "^1.0.9",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.20",
"@types/node": "^20.11.22",
"copy-webpack-plugin": "^12.0.2",
"enhanced-publish": "^1.1.2",
"eslint": "^8.57.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@nmshd/consumption": "3.9.5",
"@nmshd/content": "2.8.7",
"@nmshd/crypto": "2.0.6",
"@nmshd/transport": "2.3.3",
"@nmshd/transport": "2.3.4",
"ajv": "^8.12.0",
"ajv-errors": "^3.0.0",
"ajv-formats": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/test/consumption/iqlQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("IQL Query", () => {
}
}
],
expiresAt: DateTime.now().plus({ hour: 1 }).toISO() as any
expiresAt: DateTime.now().plus({ hour: 1 }).toISO()
},
peer: (await rTransportServices.account.getIdentityInfo()).value.address
});
Expand Down
4 changes: 2 additions & 2 deletions packages/transport/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/transport",
"version": "2.3.3",
"version": "2.3.4",
"description": "The transport library handles backbone communication and content encryption.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down Expand Up @@ -93,7 +93,7 @@
"@types/json-stringify-safe": "^5.0.3",
"@types/lodash": "^4.14.202",
"@types/luxon": "^3.4.2",
"@types/qs": "^6.9.11",
"@types/qs": "^6.9.12",
"@types/uuid": "^9.0.8",
"expect": "^29.7.0",
"ts-mockito": "^2.6.1"
Expand Down
20 changes: 10 additions & 10 deletions packages/transport/src/core/types/CoreDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export class CoreDate extends CoreSerializable {
}

public get date(): string {
if (!this.dateTime.isValid) throw new TransportError("The date is invalid.");
return this.dateTime.toISODate()!;
return this.asValidDateTime.toISODate();
}

public constructor(dateTime: DateTime = DateTime.utc()) {
Expand Down Expand Up @@ -134,27 +133,28 @@ export class CoreDate extends CoreSerializable {
* Creates an ISO String.
*/
public override toString(): string {
if (!this.dateTime.isValid) throw new TransportError("The date is invalid.");
return this.dateTime.toISO()!;
return this.asValidDateTime.toISO();
}

public toISOString(): string {
if (!this.dateTime.isValid) throw new TransportError("The date is invalid.");
return this.dateTime.toISO()!;
return this.asValidDateTime.toISO();
}

public override toLocaleString(): string {
return this.dateTime.toLocaleString();
}

public override toJSON(): string {
if (!this.dateTime.isValid) throw new TransportError("The date is invalid.");
return this.dateTime.toISO()!;
return this.asValidDateTime.toISO();
}

public override serialize(): string {
return this.asValidDateTime.toISO();
}

private get asValidDateTime(): DateTime<true> {
if (!this.dateTime.isValid) throw new TransportError("The date is invalid.");
return this.dateTime.toISO()!;
return this.dateTime as DateTime<true>;
}

protected static override preFrom(value: any): any {
Expand Down Expand Up @@ -183,7 +183,7 @@ export class CoreDate extends CoreSerializable {
return DateTime.fromISO(value, { zone: "utc" }).toUTC();
}

throw new TransportError("The provided object is invalid cannot be deserialized.");
throw new TransportError("The provided object is invalid and cannot be deserialized.");
}

public static from(value: ICoreDate | string | number): CoreDate {
Expand Down

0 comments on commit 8bcf439

Please sign in to comment.