Skip to content

Commit

Permalink
[lib] Add connectionInfoValidator
Browse files Browse the repository at this point in the history
Summary:
https://linear.app/comm/issue/ENG-3995/create-functions-for-migrating-the-client-stores

These validators will be used for generating converters (D8355) for schema id migration

Test Plan: Tested with later diffs if the generated converters converted the redux correctly.

Reviewers: kamil, tomek

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8381
  • Loading branch information
MichalGniadek committed Jul 11, 2023
1 parent 43f9115 commit 3a64d45
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/types/activity-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export type ActivityUpdate = {
+threadID: string,
+latestMessage: ?string,
};
export const activityUpdateValidator: TInterface<ActivityUpdate> =
tShape<ActivityUpdate>({
focus: t.Boolean,
threadID: tID,
latestMessage: t.maybe(tID),
});

export type UpdateActivityRequest = {
+updates: $ReadOnlyArray<ActivityUpdate>,
Expand Down
13 changes: 12 additions & 1 deletion lib/types/entry-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import t, { type TInterface } from 'tcomb';

import { type Platform, isWebPlatform } from './device-types.js';
import { type CalendarFilter, defaultCalendarFilters } from './filter-types.js';
import {
type CalendarFilter,
calendarFilterValidator,
defaultCalendarFilters,
} from './filter-types.js';
import type { RawMessageInfo } from './message-types.js';
import type {
ServerCreateUpdatesResponse,
Expand Down Expand Up @@ -73,6 +77,13 @@ export type CalendarQuery = {
+filters: $ReadOnlyArray<CalendarFilter>,
};

export const calendarQueryValidator: TInterface<CalendarQuery> =
tShape<CalendarQuery>({
startDate: t.String,
endDate: t.String,
filters: t.list(calendarFilterValidator),
});

export const defaultCalendarQuery = (
platform: ?Platform,
timeZone?: ?string,
Expand Down
11 changes: 11 additions & 0 deletions lib/types/filter-types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// @flow

import t, { type TUnion } from 'tcomb';

import type { ResolvedThreadInfo } from './thread-types.js';
import { tID, tShape, tString } from '../utils/validation-utils.js';

export const calendarThreadFilterTypes = Object.freeze({
THREAD_LIST: 'threads',
Expand All @@ -16,6 +19,14 @@ export type CalendarThreadFilter = {
};
export type CalendarFilter = { +type: 'not_deleted' } | CalendarThreadFilter;

export const calendarFilterValidator: TUnion<CalendarFilter> = t.union([
tShape<CalendarThreadFilter>({
type: tString('threads'),
threadIDs: t.list(tID),
}),
tShape({ type: tString('not_deleted') }),
]);

export const defaultCalendarFilters: $ReadOnlyArray<CalendarFilter> = [
{ type: calendarThreadFilterTypes.NOT_DELETED },
];
Expand Down
17 changes: 17 additions & 0 deletions lib/types/socket-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import t, { type TInterface, type TUnion } from 'tcomb';

import {
type ActivityUpdate,
activityUpdateValidator,
type UpdateActivityResult,
updateActivityResultValidator,
} from './activity-types.js';
Expand All @@ -14,6 +15,7 @@ import {
type RawEntryInfo,
rawEntryInfoValidator,
type CalendarQuery,
calendarQueryValidator,
defaultCalendarQuery,
} from './entry-types.js';
import {
Expand Down Expand Up @@ -473,6 +475,21 @@ export type ConnectionInfo = {
+lateResponses: $ReadOnlyArray<number>,
+showDisconnectedBar: boolean,
};
export const connectionInfoValidator: TInterface<ConnectionInfo> =
tShape<ConnectionInfo>({
status: t.enums.of([
'connecting',
'connected',
'reconnecting',
'disconnecting',
'forcedDisconnecting',
'disconnected',
]),
queuedActivityUpdates: t.list(activityUpdateValidator),
actualizedCalendarQuery: calendarQueryValidator,
lateResponses: t.list(t.Number),
showDisconnectedBar: t.Boolean,
});
export const defaultConnectionInfo = (
platform: Platform,
timeZone?: ?string,
Expand Down

0 comments on commit 3a64d45

Please sign in to comment.