Skip to content

Commit

Permalink
use io-ts exact
Browse files Browse the repository at this point in the history
  • Loading branch information
promatty committed Feb 1, 2025
1 parent bb23730 commit 135956b
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 326 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"test": "lerna run test"
},
"dependencies": {
"esbuild": "^0.23.0"
"esbuild": "^0.23.0",
"uuid": "^11.0.5"
},
"devDependencies": {
"@types/eslint": "^9.6.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/datasources/DynamoDB/DynamoDB.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { v4 as uuidv4 } from "uuid";

import { type BackendController } from "@/controllers/BackendController/BackendController";

import {
Expand Down Expand Up @@ -60,6 +62,7 @@ export class DynamoDB implements DynamoDBtypes {
try {
const command = new GetItemCommand({
Key: {
id: { S: "packet" },
timestamp: { N: timestamp },
},
TableName: this.packetTableName,
Expand Down Expand Up @@ -158,6 +161,7 @@ export class DynamoDB implements DynamoDBtypes {
const command = new PutCommand({
Item: {
data: packet,
id: uuidv4(),
timestamp: packet.TimeStamp,
},
TableName: this.packetTableName,
Expand All @@ -179,6 +183,7 @@ export class DynamoDB implements DynamoDBtypes {
const command = new PutCommand({
Item: {
data: packet,
id: uuidv4(),
timestamp: packet.timeStamp,
},
TableName: this.lapTableName,
Expand Down
7 changes: 3 additions & 4 deletions packages/shared/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,11 @@ export function generateFakeTelemetryData(): ITelemetryData {
};
}

export function validateTelemetryData(packet: any) {
export function validateTelemetryData(packet: unknown) {
const validationResult = ITelemetryDataType.decode(packet);
if (isRight(validationResult)) {
return validationResult.right;
} else {
const errorMessages = PathReporter.report(validationResult).join(", ");
throw new Error(`Invalid packet format: ${errorMessages}`);
}
const errorMessages = PathReporter.report(validationResult).join(", ");
throw new Error(`Invalid packet format: ${errorMessages}`);
}
Loading

0 comments on commit 135956b

Please sign in to comment.