diff --git a/lib/types/entry-types.js b/lib/types/entry-types.js index 8fc974a8b..2d628bb59 100644 --- a/lib/types/entry-types.js +++ b/lib/types/entry-types.js @@ -1,256 +1,256 @@ // @flow import t, { type TInterface } from 'tcomb'; import { type Platform, isWebPlatform } from './device-types.js'; import { type CalendarFilter, calendarFilterValidator, defaultCalendarFilters, } from './filter-types.js'; import type { RawMessageInfo } from './message-types.js'; import type { ServerCreateUpdatesResponse, ClientCreateUpdatesResponse, } from './update-types.js'; import type { UserInfo, AccountUserInfo } from './user-types.js'; import { fifteenDaysEarlier, fifteenDaysLater, thisMonthDates, } from '../utils/date-utils.js'; -import { tID, tShape } from '../utils/validation-utils.js'; +import { tUserID, tID, tShape } from '../utils/validation-utils.js'; export type RawEntryInfo = { id?: string, // null if local copy without ID yet localID?: string, // for optimistic creations threadID: string, text: string, year: number, month: number, // 1-indexed day: number, // 1-indexed creationTime: number, // millisecond timestamp creatorID: string, deleted: boolean, }; export type RawEntryInfos = { +[id: string]: RawEntryInfo, }; export const rawEntryInfoValidator: TInterface = tShape({ id: t.maybe(tID), localID: t.maybe(t.String), threadID: tID, text: t.String, year: t.Number, month: t.Number, day: t.Number, creationTime: t.Number, - creatorID: t.String, + creatorID: tUserID, deleted: t.Boolean, }); export type EntryInfo = { id?: string, // null if local copy without ID yet localID?: string, // for optimistic creations threadID: string, text: string, year: number, month: number, // 1-indexed day: number, // 1-indexed creationTime: number, // millisecond timestamp creator: ?UserInfo, deleted: boolean, }; export type EntryStore = { +entryInfos: { +[id: string]: RawEntryInfo }, +daysToEntries: { +[day: string]: string[] }, +lastUserInteractionCalendar: number, }; export const entryStoreValidator: TInterface = tShape({ entryInfos: t.dict(tID, rawEntryInfoValidator), daysToEntries: t.dict(t.String, t.list(tID)), lastUserInteractionCalendar: t.Number, }); export type CalendarQuery = { +startDate: string, +endDate: string, +filters: $ReadOnlyArray, }; export const calendarQueryValidator: TInterface = tShape({ startDate: t.String, endDate: t.String, filters: t.list(calendarFilterValidator), }); export const defaultCalendarQuery = ( platform: ?Platform, timeZone?: ?string, ): CalendarQuery => { if (isWebPlatform(platform)) { return { ...thisMonthDates(timeZone), filters: defaultCalendarFilters, }; } else { return { startDate: fifteenDaysEarlier(timeZone).valueOf(), endDate: fifteenDaysLater(timeZone).valueOf(), filters: defaultCalendarFilters, }; } }; export type SaveEntryInfo = { +entryID: string, +text: string, +prevText: string, +timestamp: number, +calendarQuery: CalendarQuery, }; export type SaveEntryRequest = { +entryID: string, +sessionID?: empty, +text: string, +prevText: string, +timestamp: number, +calendarQuery?: CalendarQuery, }; export type SaveEntryResponse = { +entryID: string, +newMessageInfos: $ReadOnlyArray, +updatesResult: ServerCreateUpdatesResponse, }; export type SaveEntryResult = { +entryID: string, +newMessageInfos: $ReadOnlyArray, +updatesResult: ClientCreateUpdatesResponse, }; export type SaveEntryPayload = { ...SaveEntryResult, +threadID: string, }; export type CreateEntryInfo = { +text: string, +timestamp: number, +date: string, +threadID: string, +localID: string, +calendarQuery: CalendarQuery, }; export type CreateEntryRequest = { +text: string, +sessionID?: empty, +timestamp: number, +date: string, +threadID: string, +localID?: string, +calendarQuery?: CalendarQuery, }; export type CreateEntryPayload = { ...SaveEntryPayload, +localID: string, }; export type DeleteEntryInfo = { +entryID: string, +prevText: string, +calendarQuery: CalendarQuery, }; export type DeleteEntryRequest = { +entryID: string, +sessionID?: empty, +prevText: string, +timestamp: number, +calendarQuery?: CalendarQuery, }; export type RestoreEntryInfo = { +entryID: string, +calendarQuery: CalendarQuery, }; export type RestoreEntryRequest = { +entryID: string, +sessionID?: empty, +timestamp: number, +calendarQuery?: CalendarQuery, }; export type DeleteEntryResponse = { +newMessageInfos: $ReadOnlyArray, +threadID: string, +updatesResult: ServerCreateUpdatesResponse, }; export type DeleteEntryResult = { +newMessageInfos: $ReadOnlyArray, +threadID: string, +updatesResult: ClientCreateUpdatesResponse, }; export type RestoreEntryResponse = { +newMessageInfos: $ReadOnlyArray, +updatesResult: ServerCreateUpdatesResponse, }; export type RestoreEntryResult = { +newMessageInfos: $ReadOnlyArray, +updatesResult: ClientCreateUpdatesResponse, }; export type RestoreEntryPayload = { ...RestoreEntryResult, +threadID: string, }; export type FetchEntryInfosBase = { +rawEntryInfos: $ReadOnlyArray, }; export type FetchEntryInfosResponse = { ...FetchEntryInfosBase, +userInfos: { [id: string]: AccountUserInfo }, }; export type FetchEntryInfosResult = FetchEntryInfosBase; export type DeltaEntryInfosResponse = { +rawEntryInfos: $ReadOnlyArray, +deletedEntryIDs: $ReadOnlyArray, }; export type DeltaEntryInfosResult = { +rawEntryInfos: $ReadOnlyArray, +deletedEntryIDs: $ReadOnlyArray, +userInfos: $ReadOnlyArray, }; export type CalendarResult = { +rawEntryInfos: $ReadOnlyArray, +calendarQuery: CalendarQuery, }; export type CalendarQueryUpdateStartingPayload = { +calendarQuery?: CalendarQuery, }; export type CalendarQueryUpdateResult = { +rawEntryInfos: $ReadOnlyArray, +deletedEntryIDs: $ReadOnlyArray, +calendarQuery: CalendarQuery, +calendarQueryAlreadyUpdated: boolean, +keyserverIDs: $ReadOnlyArray, }; export type FetchRevisionsForEntryPayload = { +entryID: string, +text: string, +deleted: boolean, }; diff --git a/lib/types/history-types.js b/lib/types/history-types.js index d6749b402..fb0646ce6 100644 --- a/lib/types/history-types.js +++ b/lib/types/history-types.js @@ -1,34 +1,34 @@ // @flow import t, { type TInterface } from 'tcomb'; -import { tID, tShape } from '../utils/validation-utils.js'; +import { tID, tShape, tUserID } from '../utils/validation-utils.js'; export type HistoryMode = 'day' | 'entry'; export type HistoryRevisionInfo = { +id: string, +entryID: string, +authorID: string, +text: string, +lastUpdate: number, +deleted: boolean, +threadID: string, }; export const historyRevisionInfoValidator: TInterface = tShape({ id: tID, entryID: tID, - authorID: t.String, + authorID: tUserID, text: t.String, lastUpdate: t.Number, deleted: t.Boolean, threadID: tID, }); export type FetchEntryRevisionInfosRequest = { +id: string, }; export type FetchEntryRevisionInfosResult = { +result: $ReadOnlyArray, }; diff --git a/lib/types/user-types.js b/lib/types/user-types.js index cb94e8bdf..a5bb3711b 100644 --- a/lib/types/user-types.js +++ b/lib/types/user-types.js @@ -1,120 +1,120 @@ // @flow import t, { type TInterface, type TDict, type TUnion } from 'tcomb'; import { type DefaultNotificationPayload, defaultNotificationPayloadValidator, } from './account-types.js'; import { type ClientAvatar, clientAvatarValidator } from './avatar-types.js'; import { type UserRelationshipStatus, userRelationshipStatusValidator, } from './relationship-types.js'; -import { tBool, tShape } from '../utils/validation-utils.js'; +import { tBool, tShape, tUserID } from '../utils/validation-utils.js'; export type GlobalUserInfo = { +id: string, +username: ?string, +avatar?: ?ClientAvatar, }; export type GlobalAccountUserInfo = { +id: string, +username: string, +avatar?: ?ClientAvatar, }; export const globalAccountUserInfoValidator: TInterface = tShape({ id: t.String, username: t.String, avatar: t.maybe(clientAvatarValidator), }); export type UserInfo = { +id: string, +username: ?string, +relationshipStatus?: UserRelationshipStatus, +avatar?: ?ClientAvatar, }; export const userInfoValidator: TInterface = tShape({ id: t.String, username: t.maybe(t.String), relationshipStatus: t.maybe(userRelationshipStatusValidator), avatar: t.maybe(clientAvatarValidator), }); export type UserInfos = { +[id: string]: UserInfo }; export const userInfosValidator: TDict = t.dict( t.String, userInfoValidator, ); export type AccountUserInfo = { +id: string, +username: string, +relationshipStatus?: UserRelationshipStatus, +avatar?: ?ClientAvatar, }; export const accountUserInfoValidator: TInterface = tShape({ - id: t.String, + id: tUserID, username: t.String, relationshipStatus: t.maybe(userRelationshipStatusValidator), avatar: t.maybe(clientAvatarValidator), }); export type UserStore = { +userInfos: UserInfos, }; export type RelativeUserInfo = { +id: string, +username: ?string, +isViewer: boolean, +avatar?: ?ClientAvatar, }; export type LoggedInUserInfo = { +id: string, +username: string, +settings?: DefaultNotificationPayload, +avatar?: ?ClientAvatar, }; export const loggedInUserInfoValidator: TInterface = tShape({ id: t.String, username: t.String, settings: t.maybe(defaultNotificationPayloadValidator), avatar: t.maybe(clientAvatarValidator), }); export type LoggedOutUserInfo = { +anonymous: true, }; export const loggedOutUserInfoValidator: TInterface = tShape({ anonymous: tBool(true) }); export type CurrentUserInfo = LoggedInUserInfo | LoggedOutUserInfo; export const currentUserInfoValidator: TUnion = t.union([ loggedInUserInfoValidator, loggedOutUserInfoValidator, ]); export type PasswordUpdate = { +updatedFields: { +password?: ?string, +email?: empty, }, +currentPassword: string, }; export type UserListItem = { ...AccountUserInfo, +disabled?: boolean, +notice?: string, +alert?: { +text: string, +title: string, }, +avatar?: ?ClientAvatar, }; diff --git a/lib/types/validators/entry-validators.js b/lib/types/validators/entry-validators.js index 3fa9adf0f..e9c7d0462 100644 --- a/lib/types/validators/entry-validators.js +++ b/lib/types/validators/entry-validators.js @@ -1,59 +1,59 @@ // @flow import t from 'tcomb'; import type { TInterface } from 'tcomb'; -import { tShape, tID } from '../../utils/validation-utils.js'; +import { tShape, tID, tUserID } from '../../utils/validation-utils.js'; import { type DeleteEntryResponse, type RestoreEntryResponse, type FetchEntryInfosResponse, type DeltaEntryInfosResult, type SaveEntryResponse, rawEntryInfoValidator, } from '../entry-types.js'; import { type FetchEntryRevisionInfosResult, historyRevisionInfoValidator, } from '../history-types.js'; import { rawMessageInfoValidator } from '../message-types.js'; import { serverCreateUpdatesResponseValidator } from '../update-types.js'; import { accountUserInfoValidator } from '../user-types.js'; export const fetchEntryInfosResponseValidator: TInterface = tShape({ rawEntryInfos: t.list(rawEntryInfoValidator), - userInfos: t.dict(t.String, accountUserInfoValidator), + userInfos: t.dict(tUserID, accountUserInfoValidator), }); export const fetchEntryRevisionInfosResultValidator: TInterface = tShape({ result: t.list(historyRevisionInfoValidator), }); export const saveEntryResponseValidator: TInterface = tShape({ entryID: tID, newMessageInfos: t.list(rawMessageInfoValidator), updatesResult: serverCreateUpdatesResponseValidator, }); export const deleteEntryResponseValidator: TInterface = tShape({ newMessageInfos: t.list(rawMessageInfoValidator), threadID: tID, updatesResult: serverCreateUpdatesResponseValidator, }); export const restoreEntryResponseValidator: TInterface = tShape({ newMessageInfos: t.list(rawMessageInfoValidator), updatesResult: serverCreateUpdatesResponseValidator, }); export const deltaEntryInfosResultValidator: TInterface = tShape({ rawEntryInfos: t.list(rawEntryInfoValidator), deletedEntryIDs: t.list(tID), userInfos: t.list(accountUserInfoValidator), });