Setup getConfig with typebox validations

This commit is contained in:
Dominic Ferrando
2026-07-04 01:12:15 -04:00
parent d042340c8b
commit 1da9795d84
8 changed files with 52 additions and 34 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"dependencies": {
"ml-levenberg-marquardt": "^5.0.0",
"ml-levenberg-marquardt": "^5.0.1",
"@blade-and-brawn/domain": "workspace:*"
},
"exports": {
+23 -20
View File
@@ -11,6 +11,8 @@ import {
type StandardUnit,
} from "@blade-and-brawn/domain";
import { levenbergMarquardt as LM } from "ml-levenberg-marquardt";
import { Type, type Static } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
import defaultConfig from "./config.json" with { type: "json" };
import defaultStandardsJson from "./data/default-standards.json" with { type: "json" };
import { getAvgWeight } from "./avg-weights";
@@ -211,26 +213,27 @@ export class LevelCalculator {
}
}
export type StandardsConfig = {
global: {
maxLevel: number;
};
activity: Record<
Activity,
{
weightModifier: number;
weightSkew: number;
ageModifier: number;
enableGeneration: boolean;
difficultyModifier: number;
peakAge: number;
stretch: {
upper: number;
lower: number;
};
}
>;
};
const StandardsActivityConfigSchema = Type.Object({
weightModifier: Type.Number(),
weightSkew: Type.Number(),
ageModifier: Type.Number(),
enableGeneration: Type.Boolean(),
difficultyModifier: Type.Number(),
peakAge: Type.Number(),
stretch: Type.Object({
upper: Type.Number(),
lower: Type.Number(),
}),
});
export const StandardsConfigSchema = Type.Object({
global: Type.Object({
maxLevel: Type.Number(),
}),
activity: Type.Record(Type.Enum(Activity), StandardsActivityConfigSchema),
});
export type StandardsConfig = Static<typeof StandardsConfigSchema>;
export class Standards {
readonly cfg: StandardsConfig;
+1 -3
View File
@@ -6,7 +6,5 @@
"exports": {
".": "./src/index.ts"
},
"dependencies": {
"pino": "^10.3.1"
}
"dependencies": {}
}
+1 -2
View File
@@ -4,8 +4,7 @@
"version": "0.0.0",
"type": "module",
"dependencies": {
"@blade-and-brawn/domain": "workspace:*",
"@sinclair/typebox": "^0.34.48"
"@blade-and-brawn/domain": "workspace:*"
},
"exports": {
".": "./src/index.ts"