Skip to content

Commit

Permalink
[lib] Introduce rawThreadInfoValidator and consume in `threads-stat…
Browse files Browse the repository at this point in the history
…e-sync-spec`

Summary:
Introduce validator that can handle both `LegacyRawThreadInfo` and `MinimallyEncodedRawThreadInfo` because `keyserver` will be handling both.

Updated validator was required to update `threads-state-sync-spec` which will allow us to update rest of thread update/thread "ops" code.

---

Depends on D10210

Test Plan: Flow/CI/validator will fail during testing if not defined correctly.

Reviewers: ashoat, ginsu, tomek, rohan

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D10211
  • Loading branch information
atulsmadhugiri committed Dec 13, 2023
1 parent 9b34dc0 commit c8c3cea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions keyserver/src/shared/state-sync/threads-state-sync-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// @flow

import { rawThreadInfoValidator } from 'lib/permissions/minimally-encoded-thread-permissions-validators.js';
import { threadsStateSyncSpec as libSpec } from 'lib/shared/state-sync/threads-state-sync-spec.js';
import type { ClientThreadInconsistencyReportCreationRequest } from 'lib/types/report-types.js';
import {
type LegacyRawThreadInfos,
type LegacyRawThreadInfo,
legacyRawThreadInfoValidator,
type RawThreadInfo,
type RawThreadInfos,
} from 'lib/types/thread-types.js';
import { hash, combineUnorderedHashes, values } from 'lib/utils/objects.js';

Expand Down Expand Up @@ -40,10 +42,10 @@ async function fetch(viewer: Viewer, ids?: $ReadOnlySet<string>) {
return result.threadInfos;
}

function getServerInfosHash(infos: LegacyRawThreadInfos) {
function getServerInfosHash(infos: RawThreadInfos) {
return combineUnorderedHashes(values(infos).map(getServerInfoHash));
}

function getServerInfoHash(info: LegacyRawThreadInfo) {
return hash(validateOutput(null, legacyRawThreadInfoValidator, info));
function getServerInfoHash(info: RawThreadInfo) {
return hash(validateOutput(null, rawThreadInfoValidator, info));
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import t, { type TInterface } from 'tcomb';

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

import {
tHexEncodedPermissionsBitmask,
Expand All @@ -21,6 +22,7 @@ import {
threadCurrentUserInfoValidator,
legacyThreadInfoValidator,
} from '../types/thread-types.js';
import type { RawThreadInfo } from '../types/thread-types.js';
import { tBool, tID, tShape } from '../utils/validation-utils.js';

const minimallyEncodedRoleInfoValidator: TInterface<MinimallyEncodedRoleInfo> =
Expand Down Expand Up @@ -75,6 +77,11 @@ const minimallyEncodedRawThreadInfoValidator: TInterface<MinimallyEncodedRawThre
currentUser: minimallyEncodedThreadCurrentUserInfoValidator,
});

export const rawThreadInfoValidator: TUnion<RawThreadInfo> = t.union([
legacyRawThreadInfoValidator,
minimallyEncodedRawThreadInfoValidator,
]);

export {
minimallyEncodedRoleInfoValidator,
minimallyEncodedThreadCurrentUserInfoValidator,
Expand Down
3 changes: 3 additions & 0 deletions lib/types/thread-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export const legacyRawThreadInfoValidator: TInterface<LegacyRawThreadInfo> =
});

export type RawThreadInfo = LegacyRawThreadInfo | MinimallyEncodedRawThreadInfo;
export type RawThreadInfos = {
+[id: string]: RawThreadInfo,
};

export type LegacyThreadInfo = {
+id: string,
Expand Down

0 comments on commit c8c3cea

Please sign in to comment.