Improving code security by adding stricter typings
This commit is contained in:
parent
bbef3b3eaf
commit
2fff6ae41e
12 changed files with 45 additions and 23 deletions
11
messages/JsonMessages/CharacterTexture.ts
Normal file
11
messages/JsonMessages/CharacterTexture.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isCharacterTexture = new tg.IsInterface()
|
||||
.withProperties({
|
||||
id: tg.isNumber,
|
||||
level: tg.isNumber,
|
||||
url: tg.isString,
|
||||
rights: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export type CharacterTexture = tg.GuardedType<typeof isCharacterTexture>;
|
23
messages/JsonMessages/MapDetailsData.ts
Normal file
23
messages/JsonMessages/MapDetailsData.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
import { isCharacterTexture } from "./CharacterTexture";
|
||||
import { isNumber } from "generic-type-guard";
|
||||
|
||||
/*const isNumericEnum =
|
||||
<T extends { [n: number]: string }>(vs: T) =>
|
||||
(v: any): v is T =>
|
||||
typeof v === "number" && v in vs;*/
|
||||
|
||||
export const isMapDetailsData = new tg.IsInterface()
|
||||
.withProperties({
|
||||
roomSlug: tg.isOptional(tg.isString), // deprecated
|
||||
mapUrl: tg.isString,
|
||||
policy_type: isNumber, //isNumericEnum(GameRoomPolicyTypes),
|
||||
tags: tg.isArray(tg.isString),
|
||||
textures: tg.isArray(isCharacterTexture),
|
||||
contactPage: tg.isUnion(tg.isString, tg.isUndefined),
|
||||
authenticationMandatory: tg.isUnion(tg.isBoolean, tg.isUndefined),
|
||||
group: tg.isString,
|
||||
})
|
||||
.get();
|
||||
|
||||
export type MapDetailsData = tg.GuardedType<typeof isMapDetailsData>;
|
8
messages/JsonMessages/RoomRedirect.ts
Normal file
8
messages/JsonMessages/RoomRedirect.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isRoomRedirect = new tg.IsInterface()
|
||||
.withProperties({
|
||||
redirectUrl: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export type RoomRedirect = tg.GuardedType<typeof isRoomRedirect>;
|
Loading…
Add table
Add a link
Reference in a new issue