Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/validation-utils.js
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
); | ); | ||||
const tCookie: TRegex = tRegex(/^(user|anonymous)=[0-9]+:[0-9a-f]+$/); | const tCookie: TRegex = tRegex(/^(user|anonymous)=[0-9]+:[0-9a-f]+$/); | ||||
const tEmail: TRegex = tRegex(validEmailRegex); | const tEmail: TRegex = tRegex(validEmailRegex); | ||||
const tOldValidUsername: TRegex = tRegex(oldValidUsernameRegex); | const tOldValidUsername: TRegex = tRegex(oldValidUsernameRegex); | ||||
const tID: TRefinement<string> = t.refinement(t.String, (id: string) => !!id); | const tID: TRefinement<string> = t.refinement(t.String, (id: string) => !!id); | ||||
const tMediaMessagePhoto: TInterface<PhotoMessageServerDBContent> = tShape({ | const tMediaMessagePhoto: TInterface<PhotoMessageServerDBContent> = tShape({ | ||||
type: tString('photo'), | type: tString('photo'), | ||||
uploadID: t.String, | uploadID: tID, | ||||
}); | }); | ||||
const tMediaMessageVideo: TInterface<VideoMessageServerDBContent> = tShape({ | const tMediaMessageVideo: TInterface<VideoMessageServerDBContent> = tShape({ | ||||
type: tString('video'), | type: tString('video'), | ||||
uploadID: t.String, | uploadID: tID, | ||||
thumbnailUploadID: t.String, | thumbnailUploadID: tID, | ||||
}); | }); | ||||
const tMediaMessageMedia: TUnion<MediaMessageServerDBContent> = t.union([ | const tMediaMessageMedia: TUnion<MediaMessageServerDBContent> = t.union([ | ||||
tMediaMessagePhoto, | tMediaMessagePhoto, | ||||
tMediaMessageVideo, | tMediaMessageVideo, | ||||
]); | ]); | ||||
function assertWithValidator<T>(data: mixed, validator: TType<T>): T { | function assertWithValidator<T>(data: mixed, validator: TType<T>): T { | ||||
Show All 27 Lines |