diff --git a/keyserver/src/shared/state-sync/current-user-state-sync-spec.js b/keyserver/src/shared/state-sync/current-user-state-sync-spec.js index d9da2413c..c1f5f2303 100644 --- a/keyserver/src/shared/state-sync/current-user-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/current-user-state-sync-spec.js @@ -1,21 +1,22 @@ // @flow import { currentUserStateSyncSpec as libSpec } from 'lib/shared/state-sync/current-user-state-sync-spec.js'; import type { CurrentUserInfo } from 'lib/types/user-types.js'; import type { ServerStateSyncSpec } from './state-sync-spec.js'; import { fetchCurrentUserInfo } from '../../fetchers/user-fetchers.js'; import type { Viewer } from '../../session/viewer.js'; export const currentUserStateSyncSpec: ServerStateSyncSpec< CurrentUserInfo, CurrentUserInfo, + CurrentUserInfo, > = Object.freeze({ fetch(viewer: Viewer) { return fetchCurrentUserInfo(viewer); }, fetchFullSocketSyncPayload(viewer: Viewer) { return fetchCurrentUserInfo(viewer); }, ...libSpec, }); diff --git a/keyserver/src/shared/state-sync/entries-state-sync-spec.js b/keyserver/src/shared/state-sync/entries-state-sync-spec.js index b215ef5ba..110ee928b 100644 --- a/keyserver/src/shared/state-sync/entries-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/entries-state-sync-spec.js @@ -1,38 +1,39 @@ // @flow import { serverEntryInfosObject } from 'lib/shared/entry-utils.js'; import { entriesStateSyncSpec as libSpec } from 'lib/shared/state-sync/entries-state-sync-spec.js'; import type { CalendarQuery, RawEntryInfo, RawEntryInfos, } from 'lib/types/entry-types.js'; import type { ServerStateSyncSpec } from './state-sync-spec.js'; import { fetchEntryInfos, fetchEntryInfosByID, } from '../../fetchers/entry-fetchers.js'; import type { Viewer } from '../../session/viewer.js'; export const entriesStateSyncSpec: ServerStateSyncSpec< RawEntryInfos, $ReadOnlyArray, + RawEntryInfo, > = Object.freeze({ async fetch(viewer: Viewer, ids?: $ReadOnlySet) { if (ids) { return fetchEntryInfosByID(viewer, ids); } const query = [viewer.calendarQuery]; const entriesResult = await fetchEntryInfos(viewer, query); return serverEntryInfosObject(entriesResult.rawEntryInfos); }, async fetchFullSocketSyncPayload( viewer: Viewer, query: $ReadOnlyArray, ) { const result = await fetchEntryInfos(viewer, query); return result.rawEntryInfos; }, ...libSpec, }); diff --git a/keyserver/src/shared/state-sync/state-sync-spec.js b/keyserver/src/shared/state-sync/state-sync-spec.js index 6899cbd6a..7a158a15c 100644 --- a/keyserver/src/shared/state-sync/state-sync-spec.js +++ b/keyserver/src/shared/state-sync/state-sync-spec.js @@ -1,15 +1,15 @@ // @flow import type { StateSyncSpec } from 'lib/shared/state-sync/state-sync-spec.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; import type { Viewer } from '../../session/viewer.js'; -export type ServerStateSyncSpec = { +export type ServerStateSyncSpec = { +fetch: (viewer: Viewer, ids?: $ReadOnlySet) => Promise, +fetchFullSocketSyncPayload: ( viewer: Viewer, calendarQuery: $ReadOnlyArray, ) => Promise, ...StateSyncSpec, }; diff --git a/keyserver/src/shared/state-sync/threads-state-sync-spec.js b/keyserver/src/shared/state-sync/threads-state-sync-spec.js index fe968d246..5812de123 100644 --- a/keyserver/src/shared/state-sync/threads-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/threads-state-sync-spec.js @@ -1,24 +1,28 @@ // @flow import { threadsStateSyncSpec as libSpec } from 'lib/shared/state-sync/threads-state-sync-spec.js'; -import type { RawThreadInfos } from 'lib/types/thread-types.js'; +import { + type RawThreadInfos, + type RawThreadInfo, +} from 'lib/types/thread-types.js'; import type { ServerStateSyncSpec } from './state-sync-spec.js'; import { fetchThreadInfos } from '../../fetchers/thread-fetchers.js'; import type { Viewer } from '../../session/viewer.js'; export const threadsStateSyncSpec: ServerStateSyncSpec< RawThreadInfos, RawThreadInfos, + RawThreadInfo, > = Object.freeze({ async fetch(viewer: Viewer, ids?: $ReadOnlySet) { const filter = ids ? { threadIDs: ids } : undefined; const result = await fetchThreadInfos(viewer, filter); return result.threadInfos; }, async fetchFullSocketSyncPayload(viewer: Viewer) { const result = await fetchThreadInfos(viewer); return result.threadInfos; }, ...libSpec, }); diff --git a/lib/shared/state-sync/current-user-state-sync-spec.js b/lib/shared/state-sync/current-user-state-sync-spec.js index 7399cd328..81414a150 100644 --- a/lib/shared/state-sync/current-user-state-sync-spec.js +++ b/lib/shared/state-sync/current-user-state-sync-spec.js @@ -1,21 +1,23 @@ // @flow import type { StateSyncSpec } from './state-sync-spec.js'; import { type CurrentUserInfo, currentUserInfoValidator, } from '../../types/user-types.js'; import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js'; import { ashoatKeyserverID } from '../../utils/validation-utils.js'; -export const currentUserStateSyncSpec: StateSyncSpec = - Object.freeze({ - hashKey: 'currentUserInfo', - convertClientToServerInfos(info: CurrentUserInfo) { - return convertClientIDsToServerIDs( - ashoatKeyserverID, - currentUserInfoValidator, - info, - ); - }, - }); +export const currentUserStateSyncSpec: StateSyncSpec< + CurrentUserInfo, + CurrentUserInfo, +> = Object.freeze({ + hashKey: 'currentUserInfo', + convertClientToServerInfos(info: CurrentUserInfo) { + return convertClientIDsToServerIDs( + ashoatKeyserverID, + currentUserInfoValidator, + info, + ); + }, +}); diff --git a/lib/shared/state-sync/entries-state-sync-spec.js b/lib/shared/state-sync/entries-state-sync-spec.js index 4023e242c..cc98e0f2d 100644 --- a/lib/shared/state-sync/entries-state-sync-spec.js +++ b/lib/shared/state-sync/entries-state-sync-spec.js @@ -1,43 +1,43 @@ // @flow import t from 'tcomb'; import type { StateSyncSpec } from './state-sync-spec.js'; import { type CalendarQuery, type RawEntryInfos, rawEntryInfoValidator, + type RawEntryInfo, } from '../../types/entry-types.js'; import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js'; import { values } from '../../utils/objects.js'; import { ashoatKeyserverID, tID } from '../../utils/validation-utils.js'; import { filterRawEntryInfosByCalendarQuery, serverEntryInfosObject, } from '../entry-utils.js'; -export const entriesStateSyncSpec: StateSyncSpec = Object.freeze( - { +export const entriesStateSyncSpec: StateSyncSpec = + Object.freeze({ hashKey: 'entryInfos', innerHashSpec: { hashKey: 'entryInfo', deleteKey: 'deleteEntryIDs', rawInfosKey: 'rawEntryInfos', }, convertClientToServerInfos( infos: RawEntryInfos, calendarQuery: CalendarQuery, ) { const filteredEntryInfos = filterRawEntryInfosByCalendarQuery( serverEntryInfosObject(values(infos)), calendarQuery, ); return convertClientIDsToServerIDs( ashoatKeyserverID, t.dict(tID, rawEntryInfoValidator), filteredEntryInfos, ); }, - }, -); + }); diff --git a/lib/shared/state-sync/state-sync-spec.js b/lib/shared/state-sync/state-sync-spec.js index a40eaa6f1..f8f7cd218 100644 --- a/lib/shared/state-sync/state-sync-spec.js +++ b/lib/shared/state-sync/state-sync-spec.js @@ -1,17 +1,17 @@ // @flow import type { CalendarQuery } from '../../types/entry-types.js'; -export type StateSyncSpec = { +export type StateSyncSpec = { +hashKey: string, +innerHashSpec?: { +hashKey: string, +deleteKey: string, +rawInfosKey: string, +additionalDeleteCondition?: Info => boolean, }, +convertClientToServerInfos: ( infos: Infos, calendarQuery: CalendarQuery, ) => Infos, }; diff --git a/lib/shared/state-sync/state-sync-specs.js b/lib/shared/state-sync/state-sync-specs.js index 99256699e..6a2edcb42 100644 --- a/lib/shared/state-sync/state-sync-specs.js +++ b/lib/shared/state-sync/state-sync-specs.js @@ -1,18 +1,18 @@ // @flow import { currentUserStateSyncSpec } from './current-user-state-sync-spec.js'; import { entriesStateSyncSpec } from './entries-state-sync-spec.js'; import type { StateSyncSpec } from './state-sync-spec.js'; import { threadsStateSyncSpec } from './threads-state-sync-spec.js'; import { usersStateSyncSpec } from './users-state-sync-spec.js'; export const stateSyncSpecs = Object.freeze({ threads: threadsStateSyncSpec, entries: entriesStateSyncSpec, currentUser: currentUserStateSyncSpec, users: usersStateSyncSpec, }); (stateSyncSpecs: { - +[string]: StateSyncSpec, + +[string]: StateSyncSpec, }); diff --git a/lib/shared/state-sync/threads-state-sync-spec.js b/lib/shared/state-sync/threads-state-sync-spec.js index aace2dbc1..9e611b773 100644 --- a/lib/shared/state-sync/threads-state-sync-spec.js +++ b/lib/shared/state-sync/threads-state-sync-spec.js @@ -1,28 +1,31 @@ // @flow import t from 'tcomb'; import type { StateSyncSpec } from './state-sync-spec.js'; import { type RawThreadInfos, + type RawThreadInfo, rawThreadInfoValidator, } from '../../types/thread-types.js'; import { convertClientIDsToServerIDs } from '../../utils/conversion-utils.js'; import { ashoatKeyserverID, tID } from '../../utils/validation-utils.js'; -export const threadsStateSyncSpec: StateSyncSpec = - Object.freeze({ - hashKey: 'threadInfos', - innerHashSpec: { - hashKey: 'threadInfo', - deleteKey: 'deleteThreadIDs', - rawInfosKey: 'rawThreadInfos', - }, - convertClientToServerInfos(infos: RawThreadInfos) { - return convertClientIDsToServerIDs( - ashoatKeyserverID, - t.dict(tID, rawThreadInfoValidator), - infos, - ); - }, - }); +export const threadsStateSyncSpec: StateSyncSpec< + RawThreadInfos, + RawThreadInfo, +> = Object.freeze({ + hashKey: 'threadInfos', + innerHashSpec: { + hashKey: 'threadInfo', + deleteKey: 'deleteThreadIDs', + rawInfosKey: 'rawThreadInfos', + }, + convertClientToServerInfos(infos: RawThreadInfos) { + return convertClientIDsToServerIDs( + ashoatKeyserverID, + t.dict(tID, rawThreadInfoValidator), + infos, + ); + }, +});