Changeset View
Changeset View
Standalone View
Standalone View
lib/types/avatar-types.js
// @flow | // @flow | ||||
import t, { type TUnion } from 'tcomb'; | import t, { type TUnion, type TInterface } from 'tcomb'; | ||||
import type { CreateUpdatesResult } from './update-types.js'; | import type { CreateUpdatesResult } from './update-types.js'; | ||||
import { tShape, tString } from '../utils/validation-utils.js'; | import { validHexColorRegex } from '../shared/account-utils.js'; | ||||
import { onlyOneEmojiRegex } from '../shared/emojis.js'; | |||||
import { tRegex, tShape, tString } from '../utils/validation-utils.js'; | |||||
export type EmojiAvatarDBContent = { | export type EmojiAvatarDBContent = { | ||||
+type: 'emoji', | +type: 'emoji', | ||||
+emoji: string, | +emoji: string, | ||||
+color: string, // hex, without "#" or "0x" | +color: string, // hex, without "#" or "0x" | ||||
}; | }; | ||||
const emojiAvatarDBContentValidator = tShape<EmojiAvatarDBContent>({ | export const emojiAvatarDBContentValidator: TInterface<EmojiAvatarDBContent> = | ||||
tShape<EmojiAvatarDBContent>({ | |||||
type: tString('emoji'), | type: tString('emoji'), | ||||
emoji: t.String, | emoji: tRegex(onlyOneEmojiRegex), | ||||
color: t.String, | color: tRegex(validHexColorRegex), | ||||
}); | }); | ||||
export type ImageAvatarDBContent = { | export type ImageAvatarDBContent = { | ||||
+type: 'image', | +type: 'image', | ||||
+uploadID: string, | +uploadID: string, | ||||
}; | }; | ||||
export type ENSAvatarDBContent = { | export type ENSAvatarDBContent = { | ||||
+type: 'ens', | +type: 'ens', | ||||
}; | }; | ||||
const ensAvatarDBContentValidator = tShape({ type: tString('ens') }); | export const ensAvatarDBContentValidator: TInterface<ENSAvatarDBContent> = | ||||
tShape({ type: tString('ens') }); | |||||
export type AvatarDBContent = | export type AvatarDBContent = | ||||
| EmojiAvatarDBContent | | EmojiAvatarDBContent | ||||
| ImageAvatarDBContent | | ImageAvatarDBContent | ||||
| ENSAvatarDBContent; | | ENSAvatarDBContent; | ||||
export type UpdateUserAvatarRemoveRequest = { +type: 'remove' }; | export type UpdateUserAvatarRemoveRequest = { +type: 'remove' }; | ||||
Show All 40 Lines |