diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js index 4c399430c..c35fdfdda 100644 --- a/lib/utils/validation-utils.js +++ b/lib/utils/validation-utils.js @@ -1,104 +1,85 @@ // @flow -import t, { TUnion } from 'tcomb'; +import t from 'tcomb'; import type { TStructProps, TIrreducible, TRefinement, TEnums, TInterface, } from 'tcomb'; import { validEmailRegex, oldValidUsernameRegex, validHexColorRegex, } from '../shared/account-utils'; function tBool(value: boolean): TIrreducible { return t.irreducible('literal bool', x => x === value); } function tString(value: string): TIrreducible { return t.irreducible('literal string', x => x === value); } function tNumber(value: number): TIrreducible { return t.irreducible('literal number', x => x === value); } function tShape(spec: TStructProps): TInterface { return t.interface(spec, { strict: true }); } type TRegex = TRefinement; function tRegex(regex: RegExp): TRegex { return t.refinement(t.String, val => regex.test(val)); } function tNumEnum(nums: $ReadOnlyArray): TRefinement { return t.refinement(t.Number, (input: number) => { for (const num of nums) { if (input === num) { return true; } } return false; }); } const tDate: TRegex = tRegex(/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$/); const tColor: TRegex = tRegex(validHexColorRegex); // we don't include # char const tPlatform: TEnums = t.enums.of(['ios', 'android', 'web']); const tDeviceType: TEnums = t.enums.of(['ios', 'android']); const tPlatformDetails: TInterface = tShape({ platform: tPlatform, codeVersion: t.maybe(t.Number), stateVersion: t.maybe(t.Number), }); const tPassword: TRefinement = t.refinement( t.String, (password: string) => !!password, ); const tCookie: TRegex = tRegex(/^(user|anonymous)=[0-9]+:[0-9a-f]+$/); const tEmail: TRegex = tRegex(validEmailRegex); const tOldValidUsername: TRegex = tRegex(oldValidUsernameRegex); const tID: TRefinement = t.refinement(t.String, (id: string) => !!id); -const tMediaMessagePhoto: TInterface = tShape({ - type: tString('photo'), - uploadID: t.String, -}); - -const tMediaMessageVideo: TInterface = tShape({ - type: tString('video'), - uploadID: t.String, - thumbnailUploadID: t.String, -}); - -const tMediaMessageMedia: TUnion = t.union([ - tMediaMessagePhoto, - tMediaMessageVideo, -]); - export { tBool, tString, tNumber, tShape, tRegex, tNumEnum, tDate, tColor, tPlatform, tDeviceType, tPlatformDetails, tPassword, tCookie, tEmail, tOldValidUsername, tID, - tMediaMessagePhoto, - tMediaMessageVideo, - tMediaMessageMedia, };