TeaSpeak-Client/modules/core/app-updater/AppInfoFile.validator.ts
2020-12-02 18:08:49 +01:00

75 lines
1.8 KiB
TypeScript

/* tslint:disable */
// generated by typescript-json-validator
import {inspect} from 'util';
import Ajv = require('ajv');
import AppInfoFile from './AppInfoFile';
export const ajv = new Ajv({"allErrors":true,"coerceTypes":false,"format":"fast","nullable":true,"unicode":true,"uniqueItems":true,"useDefaults":true});
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
export {AppInfoFile};
export const AppVersionFileSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"defaultProperties": [
],
"properties": {
"clientVersion": {
"defaultProperties": [
],
"properties": {
"buildIndex": {
"type": "number"
},
"major": {
"type": "number"
},
"minor": {
"type": "number"
},
"patch": {
"type": "number"
},
"timestamp": {
"type": "number"
}
},
"required": [
"buildIndex",
"major",
"minor",
"patch",
"timestamp"
],
"type": "object"
},
"uiPackChannel": {
"type": "string"
},
"version": {
"enum": [
2
],
"type": "number"
}
},
"required": [
"clientVersion",
"uiPackChannel",
"version"
],
"type": "object"
};
export type ValidateFunction<T> = ((data: unknown) => data is T) & Pick<Ajv.ValidateFunction, 'errors'>
export const isAppVersionFile = ajv.compile(AppVersionFileSchema) as ValidateFunction<AppInfoFile>;
export default function validate(value: unknown): AppInfoFile {
if (isAppVersionFile(value)) {
return value;
} else {
throw new Error(
ajv.errorsText(isAppVersionFile.errors!.filter((e: any) => e.keyword !== 'if'), {dataVar: 'AppVersionFile'}) +
'\n\n' +
inspect(value),
);
}
}