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 9dec02f99..c6371ac28 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,19 +1,20 @@ // @flow +import { currentUserStateSyncSpec as libSpec } from 'lib/shared/state-sync/current-user-state-sync-spec.js'; import type { CurrentUserInfo, OldCurrentUserInfo, } from 'lib/types/user-types.js'; -import type { StateSyncSpec } from './state-sync-spec.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: StateSyncSpec< +export const currentUserStateSyncSpec: ServerStateSyncSpec< OldCurrentUserInfo | CurrentUserInfo, > = Object.freeze({ fetch(viewer: Viewer) { return fetchCurrentUserInfo(viewer); }, - hashKey: 'currentUserInfo', + ...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 47f4e1b41..046183998 100644 --- a/keyserver/src/shared/state-sync/entries-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/entries-state-sync-spec.js @@ -1,33 +1,28 @@ // @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, RawEntryInfos } from 'lib/types/entry-types.js'; -import type { StateSyncSpec } from './state-sync-spec.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: StateSyncSpec = Object.freeze( - { +export const entriesStateSyncSpec: ServerStateSyncSpec = + Object.freeze({ async fetch( viewer: Viewer, query: $ReadOnlyArray, ids?: $ReadOnlySet, ) { if (ids) { return fetchEntryInfosByID(viewer, ids); } const entriesResult = await fetchEntryInfos(viewer, query); return serverEntryInfosObject(entriesResult.rawEntryInfos); }, - hashKey: 'entryInfos', - innerHashSpec: { - hashKey: 'entryInfo', - deleteKey: 'deleteEntryIDs', - rawInfosKey: '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 8879bf861..041a9cb7f 100644 --- a/keyserver/src/shared/state-sync/state-sync-spec.js +++ b/keyserver/src/shared/state-sync/state-sync-spec.js @@ -1,20 +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 StateSyncSpec = { +export type ServerStateSyncSpec = { +fetch: ( viewer: Viewer, calendarQuery: $ReadOnlyArray, ids?: $ReadOnlySet, ) => Promise, - +hashKey: string, - +innerHashSpec?: { - +hashKey: string, - +deleteKey: string, - +rawInfosKey: string, - +additionalDeleteCondition?: Info => boolean, - }, + ...StateSyncSpec, }; diff --git a/keyserver/src/shared/state-sync/state-sync-specs.js b/keyserver/src/shared/state-sync/state-sync-specs.js index 4aece4b60..1ee717d06 100644 --- a/keyserver/src/shared/state-sync/state-sync-specs.js +++ b/keyserver/src/shared/state-sync/state-sync-specs.js @@ -1,16 +1,16 @@ // @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 type { ServerStateSyncSpec } from './state-sync-spec.js'; import { threadsStateSyncSpec } from './threads-state-sync-spec.js'; import { usersStateSyncSpec } from './users-state-sync-spec.js'; export const serverStateSyncSpecs: { - +[string]: StateSyncSpec<*>, + +[string]: ServerStateSyncSpec<*, *>, } = Object.freeze({ threads: threadsStateSyncSpec, entries: entriesStateSyncSpec, currentUser: currentUserStateSyncSpec, users: usersStateSyncSpec, }); 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 87fcf06fa..99e3e70e8 100644 --- a/keyserver/src/shared/state-sync/threads-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/threads-state-sync-spec.js @@ -1,29 +1,25 @@ // @flow +import { threadsStateSyncSpec as libSpec } from 'lib/shared/state-sync/threads-state-sync-spec.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; -import type { StateSyncSpec } from './state-sync-spec.js'; +import type { ServerStateSyncSpec } from './state-sync-spec.js'; import { fetchThreadInfos, type RawThreadInfos, } from '../../fetchers/thread-fetchers.js'; import type { Viewer } from '../../session/viewer.js'; -export const threadsStateSyncSpec: StateSyncSpec = +export const threadsStateSyncSpec: ServerStateSyncSpec = Object.freeze({ async fetch( viewer: Viewer, query: $ReadOnlyArray, ids?: $ReadOnlySet, ) { const filter = ids ? { threadIDs: ids } : undefined; const result = await fetchThreadInfos(viewer, filter); return result.threadInfos; }, - hashKey: 'threadInfos', - innerHashSpec: { - hashKey: 'threadInfo', - deleteKey: 'deleteThreadIDs', - rawInfosKey: 'rawThreadInfos', - }, + ...libSpec, }); diff --git a/keyserver/src/shared/state-sync/users-state-sync-spec.js b/keyserver/src/shared/state-sync/users-state-sync-spec.js index b64975532..27729e308 100644 --- a/keyserver/src/shared/state-sync/users-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/users-state-sync-spec.js @@ -1,32 +1,25 @@ // @flow +import { usersStateSyncSpec as libSpec } from 'lib/shared/state-sync/users-state-sync-spec.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; import type { UserInfos, UserInfo } from 'lib/types/user-types.js'; -import type { StateSyncSpec } from './state-sync-spec.js'; +import type { ServerStateSyncSpec } from './state-sync-spec.js'; import { fetchKnownUserInfos } from '../../fetchers/user-fetchers.js'; import type { Viewer } from '../../session/viewer.js'; -export const usersStateSyncSpec: StateSyncSpec = +export const usersStateSyncSpec: ServerStateSyncSpec = Object.freeze({ fetch( viewer: Viewer, query: $ReadOnlyArray, ids?: $ReadOnlySet, ) { if (ids) { return fetchKnownUserInfos(viewer, [...ids]); } return fetchKnownUserInfos(viewer); }, - hashKey: 'userInfos', - innerHashSpec: { - hashKey: 'userInfo', - deleteKey: 'deleteUserInfoIDs', - rawInfosKey: 'userInfos', - additionalDeleteCondition(user: UserInfo) { - return !user.username; - }, - }, + ...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 new file mode 100644 index 000000000..b6a5a3e05 --- /dev/null +++ b/lib/shared/state-sync/current-user-state-sync-spec.js @@ -0,0 +1,7 @@ +// @flow + +import type { StateSyncSpec } from './state-sync-spec.js'; + +export const currentUserStateSyncSpec: StateSyncSpec<> = Object.freeze({ + hashKey: 'currentUserInfo', +}); diff --git a/lib/shared/state-sync/entries-state-sync-spec.js b/lib/shared/state-sync/entries-state-sync-spec.js new file mode 100644 index 000000000..435b780ee --- /dev/null +++ b/lib/shared/state-sync/entries-state-sync-spec.js @@ -0,0 +1,12 @@ +// @flow + +import type { StateSyncSpec } from './state-sync-spec.js'; + +export const entriesStateSyncSpec: StateSyncSpec<> = Object.freeze({ + hashKey: 'entryInfos', + innerHashSpec: { + hashKey: 'entryInfo', + deleteKey: 'deleteEntryIDs', + rawInfosKey: 'rawEntryInfos', + }, +}); diff --git a/lib/shared/state-sync/state-sync-spec.js b/lib/shared/state-sync/state-sync-spec.js new file mode 100644 index 000000000..0ad0d90bf --- /dev/null +++ b/lib/shared/state-sync/state-sync-spec.js @@ -0,0 +1,11 @@ +// @flow + +export type StateSyncSpec = { + +hashKey: string, + +innerHashSpec?: { + +hashKey: string, + +deleteKey: string, + +rawInfosKey: string, + +additionalDeleteCondition?: Info => boolean, + }, +}; diff --git a/keyserver/src/shared/state-sync/state-sync-specs.js b/lib/shared/state-sync/state-sync-specs.js similarity index 93% copy from keyserver/src/shared/state-sync/state-sync-specs.js copy to lib/shared/state-sync/state-sync-specs.js index 4aece4b60..facac7ab9 100644 --- a/keyserver/src/shared/state-sync/state-sync-specs.js +++ b/lib/shared/state-sync/state-sync-specs.js @@ -1,16 +1,16 @@ // @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 serverStateSyncSpecs: { +export const stateSyncSpecs: { +[string]: StateSyncSpec<*>, } = Object.freeze({ threads: threadsStateSyncSpec, entries: entriesStateSyncSpec, currentUser: currentUserStateSyncSpec, users: usersStateSyncSpec, }); diff --git a/lib/shared/state-sync/threads-state-sync-spec.js b/lib/shared/state-sync/threads-state-sync-spec.js new file mode 100644 index 000000000..04bf77f2d --- /dev/null +++ b/lib/shared/state-sync/threads-state-sync-spec.js @@ -0,0 +1,12 @@ +// @flow + +import type { StateSyncSpec } from './state-sync-spec.js'; + +export const threadsStateSyncSpec: StateSyncSpec<> = Object.freeze({ + hashKey: 'threadInfos', + innerHashSpec: { + hashKey: 'threadInfo', + deleteKey: 'deleteThreadIDs', + rawInfosKey: 'rawThreadInfos', + }, +}); diff --git a/lib/shared/state-sync/users-state-sync-spec.js b/lib/shared/state-sync/users-state-sync-spec.js new file mode 100644 index 000000000..0e54064cc --- /dev/null +++ b/lib/shared/state-sync/users-state-sync-spec.js @@ -0,0 +1,16 @@ +// @flow + +import type { StateSyncSpec } from './state-sync-spec.js'; +import type { UserInfo } from '../../types/user-types.js'; + +export const usersStateSyncSpec: StateSyncSpec = Object.freeze({ + hashKey: 'userInfos', + innerHashSpec: { + hashKey: 'userInfo', + deleteKey: 'deleteUserInfoIDs', + rawInfosKey: 'userInfos', + additionalDeleteCondition(user: UserInfo) { + return !user.username; + }, + }, +});