UNPKG

enkanetwork

Version:

API wrapper for enka.network written on TypeScript which provides localization, caching and convenience

76 lines (75 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAssets = void 0; // The keys every generated record must contain, mirroring the I*Data interfaces. // If a key is `undefined`/`null` (or the wrong type) after transformation it almost // always means an upstream game-data column was renamed/removed (schema drift). const schemas = { characters: [ { key: "id", type: "number" }, { key: "skillDepotId", type: "number" }, { key: "nameTextMapHash", type: "number" }, { key: "iconName", type: "string" }, { key: "sideIconName", type: "string" }, { key: "gachaIcon", type: "string" }, { key: "qualityStars", type: "number" }, { key: "element", type: "string" }, { key: "skills", type: "array" }, { key: "talents", type: "array" }, ], constellations: [ { key: "id", type: "number" }, { key: "nameTextMapHash", type: "number" }, { key: "icon", type: "string" }, ], costumes: [ { key: "id", type: "number" }, { key: "iconName", type: "string" }, { key: "sideIconName", type: "string" }, { key: "gachaIcon", type: "string" }, { key: "nameTextMapHash", type: "number" }, ], namecards: [ { key: "id", type: "number" }, { key: "nameTextMapHash", type: "number" }, { key: "icon", type: "string" }, { key: "navbar", type: "string", optional: true }, { key: "banner", type: "string" }, ], skills: [ { key: "id", type: "number" }, { key: "nameTextMapHash", type: "number" }, { key: "skillIcon", type: "string" }, { key: "proudSkillGroupId", type: "number" }, ], profilePictures: [ { key: "id", type: "number" }, { key: "iconName", type: "string" }, { key: "nameTextMapHash", type: "number" }, ], }; /** * Validates that every generated record contains all required keys with the right * primitive shape. Returns a (possibly empty) list of human-readable problems instead * of throwing, so callers decide how to react. */ function validateAssets(type, records) { const schema = schemas[type]; const problems = []; records.forEach((record, index) => { const id = record.id ?? `#${index}`; for (const { key, type: fieldType, optional } of schema) { const value = record[key]; if (value === undefined || value === null) { if (!optional) problems.push(`${type}[${id}].${key} is missing`); continue; } const actual = Array.isArray(value) ? "array" : typeof value; if (actual !== fieldType) problems.push(`${type}[${id}].${key} expected ${fieldType}, got ${actual}`); } }); return problems; } exports.validateAssets = validateAssets;