@battle-racing/br-common-lib
Version:
Common library for all Battle Racing Repositorios
51 lines (50 loc) • 2.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.kartLapTimesSchema = exports.raceWithDetailedRankingSchema = exports.raceSchema = exports.rankingWithKartsAndLapTimesSchema = exports.raceRankingItemSchema = exports.raceKartStateSchema = exports.lapTimeSchema = exports.kartProgressSchema = void 0;
const zod_1 = require("zod");
const Game_const_1 = require("../Game.const");
const Game_schema_1 = require("../Game.schema");
// --- Helper Schemas ---
exports.kartProgressSchema = zod_1.z.object({
checkpointId: zod_1.z.string(),
checkpointProgress: zod_1.z.number(),
timestampISO: zod_1.z.object({
origin: zod_1.z.string(),
server: zod_1.z.string(),
}),
lap: zod_1.z.number(),
totalProgress: zod_1.z.number(),
});
exports.lapTimeSchema = zod_1.z.object({
lap: zod_1.z.number(),
timeInSeconds: zod_1.z.number(),
completedAt: zod_1.z.string(),
completedAtCheckpointId: zod_1.z.string(),
completedAtCheckpointProgress: zod_1.z.number(),
});
exports.raceKartStateSchema = Game_schema_1.gameKartStateSchema.extend({
currentLap: zod_1.z.number(),
});
exports.raceRankingItemSchema = Game_schema_1.kartRankingItemSchema.extend({
progress: zod_1.z.number(),
lapsCompleted: zod_1.z.number(),
});
exports.rankingWithKartsAndLapTimesSchema = exports.raceRankingItemSchema.extend({
lapTimes: zod_1.z.array(exports.lapTimeSchema),
fastestLap: exports.lapTimeSchema.nullable(),
});
// --- Main Race Schema ---
exports.raceSchema = Game_schema_1.gameSchema.extend({
type: zod_1.z.literal(Game_const_1.GAME_TYPE.Race),
laps: zod_1.z.number(),
kartsState: zod_1.z.record(zod_1.z.string(), exports.raceKartStateSchema),
kartsProgress: zod_1.z.record(zod_1.z.string(), zod_1.z.array(exports.kartProgressSchema)),
gameRanking: zod_1.z.array(exports.raceRankingItemSchema),
});
exports.raceWithDetailedRankingSchema = exports.raceSchema.omit({ kartsProgress: true }).extend({
gameRanking: zod_1.z.array(exports.rankingWithKartsAndLapTimesSchema),
});
exports.kartLapTimesSchema = zod_1.z.object({
kartGuid: zod_1.z.string(),
lapTimes: zod_1.z.array(exports.lapTimeSchema),
});