diff --git a/keyserver/src/responders/redux-state-responders.js b/keyserver/src/responders/redux-state-responders.js --- a/keyserver/src/responders/redux-state-responders.js +++ b/keyserver/src/responders/redux-state-responders.js @@ -4,7 +4,7 @@ import t, { type TInterface } from 'tcomb'; import { baseLegalPolicies } from 'lib/facts/policies.js'; -import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-raw-thread-info-validators.js'; import { daysToEntriesFromEntryInfos } from 'lib/reducers/entry-reducer.js'; import { freshMessageStore } from 'lib/reducers/message-reducer.js'; import { mostRecentlyReadThread } from 'lib/selectors/thread-selectors.js'; diff --git a/keyserver/src/responders/thread-responders.js b/keyserver/src/responders/thread-responders.js --- a/keyserver/src/responders/thread-responders.js +++ b/keyserver/src/responders/thread-responders.js @@ -3,7 +3,7 @@ import t from 'tcomb'; import type { TInterface, TUnion } from 'tcomb'; -import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-raw-thread-info-validators.js'; import { mediaValidator } from 'lib/types/media-types.js'; import { rawMessageInfoValidator, diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -12,7 +12,7 @@ policies, policyTypeValidator, } from 'lib/facts/policies.js'; -import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-raw-thread-info-validators.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import type { KeyserverAuthRequest, diff --git a/keyserver/src/shared/state-sync/threads-state-sync-spec.js b/keyserver/src/shared/state-sync/threads-state-sync-spec.js --- a/keyserver/src/shared/state-sync/threads-state-sync-spec.js +++ b/keyserver/src/shared/state-sync/threads-state-sync-spec.js @@ -1,6 +1,6 @@ // @flow -import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from 'lib/permissions/minimally-encoded-raw-thread-info-validators.js'; import { threadsStateSyncSpec as libSpec } from 'lib/shared/state-sync/threads-state-sync-spec.js'; import type { RawThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { ClientThreadInconsistencyReportCreationRequest } from 'lib/types/report-types.js'; diff --git a/lib/permissions/minimally-encoded-thread-permissions-validators.js b/lib/permissions/minimally-encoded-raw-thread-info-validators.js copy from lib/permissions/minimally-encoded-thread-permissions-validators.js copy to lib/permissions/minimally-encoded-raw-thread-info-validators.js --- a/lib/permissions/minimally-encoded-thread-permissions-validators.js +++ b/lib/permissions/minimally-encoded-raw-thread-info-validators.js @@ -7,33 +7,21 @@ tHexEncodedRolePermission, } from './minimally-encoded-thread-permissions.js'; import { specialRoleValidator } from './special-roles.js'; -import { clientAvatarValidator } from '../types/avatar-types.js'; import type { MemberInfo, ThreadCurrentUserInfo, RawThreadInfo, - RelativeMemberInfo, RoleInfo, - ThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; -import { threadTypeValidator } from '../types/thread-types-enum.js'; import { + type LegacyRawThreadInfo, legacyMemberInfoValidator, legacyRawThreadInfoValidator, legacyRoleInfoValidator, legacyThreadCurrentUserInfoValidator, } from '../types/thread-types.js'; -import type { LegacyRawThreadInfo } from '../types/thread-types.js'; -import { threadEntityValidator } from '../utils/entity-text.js'; import { tBool, tID, tShape } from '../utils/validation-utils.js'; -const roleInfoValidator: TInterface = tShape({ - ...legacyRoleInfoValidator.meta.props, - minimallyEncoded: tBool(true), - permissions: t.list(tHexEncodedRolePermission), - specialRole: t.maybe(specialRoleValidator), -}); - const threadCurrentUserInfoValidator: TInterface = tShape({ ...legacyThreadCurrentUserInfoValidator.meta.props, @@ -41,59 +29,36 @@ permissions: tHexEncodedPermissionsBitmask, }); -const MemberInfoValidator: TInterface = tShape({ - ...legacyMemberInfoValidator.meta.props, +const roleInfoValidator: TInterface = tShape({ + ...legacyRoleInfoValidator.meta.props, minimallyEncoded: tBool(true), - permissions: tHexEncodedPermissionsBitmask, + permissions: t.list(tHexEncodedRolePermission), + specialRole: t.maybe(specialRoleValidator), }); -const relativeMemberInfoValidator: TInterface = - tShape({ - ...MemberInfoValidator.meta.props, - username: t.maybe(t.String), - isViewer: t.Boolean, - }); - -const threadInfoValidator: TInterface = tShape({ +const memberInfoValidator: TInterface = tShape({ + ...legacyMemberInfoValidator.meta.props, minimallyEncoded: tBool(true), - id: tID, - type: threadTypeValidator, - name: t.maybe(t.String), - uiName: t.union([t.String, threadEntityValidator]), - avatar: t.maybe(clientAvatarValidator), - description: t.maybe(t.String), - color: t.String, - creationTime: t.Number, - parentThreadID: t.maybe(tID), - containingThreadID: t.maybe(tID), - community: t.maybe(tID), - members: t.list(relativeMemberInfoValidator), - roles: t.dict(tID, roleInfoValidator), - currentUser: threadCurrentUserInfoValidator, - sourceMessageID: t.maybe(tID), - repliesCount: t.Number, - pinnedCount: t.maybe(t.Number), + permissions: tHexEncodedPermissionsBitmask, }); const rawThreadInfoValidator: TInterface = tShape( { ...legacyRawThreadInfoValidator.meta.props, minimallyEncoded: tBool(true), - members: t.list(MemberInfoValidator), + members: t.list(memberInfoValidator), roles: t.dict(tID, roleInfoValidator), currentUser: threadCurrentUserInfoValidator, }, ); -export const mixedRawThreadInfoValidator: TUnion< - LegacyRawThreadInfo | RawThreadInfo, -> = t.union([legacyRawThreadInfoValidator, rawThreadInfoValidator]); +const mixedRawThreadInfoValidator: TUnion = + t.union([legacyRawThreadInfoValidator, rawThreadInfoValidator]); export { + memberInfoValidator, roleInfoValidator, threadCurrentUserInfoValidator, - MemberInfoValidator, - relativeMemberInfoValidator, - threadInfoValidator, rawThreadInfoValidator, + mixedRawThreadInfoValidator, }; diff --git a/lib/permissions/minimally-encoded-thread-permissions-validators.js b/lib/permissions/minimally-encoded-thread-permissions-validators.js --- a/lib/permissions/minimally-encoded-thread-permissions-validators.js +++ b/lib/permissions/minimally-encoded-thread-permissions-validators.js @@ -1,55 +1,24 @@ // @flow -import t, { type TInterface, type TUnion } from 'tcomb'; +import t, { type TInterface } from 'tcomb'; import { - tHexEncodedPermissionsBitmask, - tHexEncodedRolePermission, -} from './minimally-encoded-thread-permissions.js'; -import { specialRoleValidator } from './special-roles.js'; + roleInfoValidator, + threadCurrentUserInfoValidator, + memberInfoValidator, +} from './minimally-encoded-raw-thread-info-validators.js'; import { clientAvatarValidator } from '../types/avatar-types.js'; import type { - MemberInfo, - ThreadCurrentUserInfo, - RawThreadInfo, RelativeMemberInfo, - RoleInfo, ThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadTypeValidator } from '../types/thread-types-enum.js'; -import { - legacyMemberInfoValidator, - legacyRawThreadInfoValidator, - legacyRoleInfoValidator, - legacyThreadCurrentUserInfoValidator, -} from '../types/thread-types.js'; -import type { LegacyRawThreadInfo } from '../types/thread-types.js'; import { threadEntityValidator } from '../utils/entity-text.js'; import { tBool, tID, tShape } from '../utils/validation-utils.js'; -const roleInfoValidator: TInterface = tShape({ - ...legacyRoleInfoValidator.meta.props, - minimallyEncoded: tBool(true), - permissions: t.list(tHexEncodedRolePermission), - specialRole: t.maybe(specialRoleValidator), -}); - -const threadCurrentUserInfoValidator: TInterface = - tShape({ - ...legacyThreadCurrentUserInfoValidator.meta.props, - minimallyEncoded: tBool(true), - permissions: tHexEncodedPermissionsBitmask, - }); - -const MemberInfoValidator: TInterface = tShape({ - ...legacyMemberInfoValidator.meta.props, - minimallyEncoded: tBool(true), - permissions: tHexEncodedPermissionsBitmask, -}); - const relativeMemberInfoValidator: TInterface = tShape({ - ...MemberInfoValidator.meta.props, + ...memberInfoValidator.meta.props, username: t.maybe(t.String), isViewer: t.Boolean, }); @@ -75,25 +44,4 @@ pinnedCount: t.maybe(t.Number), }); -const rawThreadInfoValidator: TInterface = tShape( - { - ...legacyRawThreadInfoValidator.meta.props, - minimallyEncoded: tBool(true), - members: t.list(MemberInfoValidator), - roles: t.dict(tID, roleInfoValidator), - currentUser: threadCurrentUserInfoValidator, - }, -); - -export const mixedRawThreadInfoValidator: TUnion< - LegacyRawThreadInfo | RawThreadInfo, -> = t.union([legacyRawThreadInfoValidator, rawThreadInfoValidator]); - -export { - roleInfoValidator, - threadCurrentUserInfoValidator, - MemberInfoValidator, - relativeMemberInfoValidator, - threadInfoValidator, - rawThreadInfoValidator, -}; +export { relativeMemberInfoValidator, threadInfoValidator }; diff --git a/lib/permissions/minimally-encoded-thread-permissions.test.js b/lib/permissions/minimally-encoded-thread-permissions.test.js --- a/lib/permissions/minimally-encoded-thread-permissions.test.js +++ b/lib/permissions/minimally-encoded-thread-permissions.test.js @@ -1,16 +1,16 @@ // @flow +import { + memberInfoValidator, + rawThreadInfoValidator, + roleInfoValidator, + threadCurrentUserInfoValidator, +} from './minimally-encoded-raw-thread-info-validators.js'; import { exampleMinimallyEncodedRawThreadInfoA, exampleRawThreadInfoA, expectedDecodedExampleRawThreadInfoA, } from './minimally-encoded-thread-permissions-test-data.js'; -import { - MemberInfoValidator, - rawThreadInfoValidator, - roleInfoValidator, - threadCurrentUserInfoValidator, -} from './minimally-encoded-thread-permissions-validators.js'; import { decodeRolePermissionBitmask, decodeThreadRolePermissionsBitmaskArray, @@ -446,7 +446,7 @@ describe('minimallyEncodedMemberInfoValidator', () => { it('should validate correctly formed MinimallyEncodedMemberInfo', () => { expect( - MemberInfoValidator.is({ + memberInfoValidator.is({ minimallyEncoded: true, id: 'memberID', permissions: 'ABCDEF', @@ -455,7 +455,7 @@ ).toBe(true); expect( - MemberInfoValidator.is({ + memberInfoValidator.is({ minimallyEncoded: true, id: 'memberID', permissions: '01b', @@ -466,7 +466,7 @@ it('should NOT validate malformed MinimallyEncodedMemberInfo', () => { expect( - MemberInfoValidator.is({ + memberInfoValidator.is({ minimallyEncoded: true, id: 'memberID', permissions: 'INVALID', @@ -475,7 +475,7 @@ ).toBe(false); expect( - MemberInfoValidator.is({ + memberInfoValidator.is({ minimallyEncoded: true, id: 'memberID', permissions: 100, diff --git a/lib/shared/updates/join-thread-spec.js b/lib/shared/updates/join-thread-spec.js --- a/lib/shared/updates/join-thread-spec.js +++ b/lib/shared/updates/join-thread-spec.js @@ -5,7 +5,7 @@ import t from 'tcomb'; import type { UpdateInfoFromRawInfoParams, UpdateSpec } from './update-spec.js'; -import { mixedRawThreadInfoValidator } from '../../permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from '../../permissions/minimally-encoded-raw-thread-info-validators.js'; import { type RawEntryInfo, rawEntryInfoValidator, diff --git a/lib/shared/updates/update-thread-spec.js b/lib/shared/updates/update-thread-spec.js --- a/lib/shared/updates/update-thread-spec.js +++ b/lib/shared/updates/update-thread-spec.js @@ -5,7 +5,7 @@ import t from 'tcomb'; import type { UpdateInfoFromRawInfoParams, UpdateSpec } from './update-spec.js'; -import { mixedRawThreadInfoValidator } from '../../permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from '../../permissions/minimally-encoded-raw-thread-info-validators.js'; import type { RawThreadInfos } from '../../types/thread-types.js'; import { updateTypes } from '../../types/update-types-enum.js'; import type { diff --git a/lib/types/request-types.js b/lib/types/request-types.js --- a/lib/types/request-types.js +++ b/lib/types/request-types.js @@ -26,7 +26,7 @@ type AccountUserInfo, accountUserInfoValidator, } from './user-types.js'; -import { mixedRawThreadInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from '../permissions/minimally-encoded-raw-thread-info-validators.js'; import { tNumber, tShape, tID } from '../utils/validation-utils.js'; // "Server requests" are requests for information that the server delivers to diff --git a/lib/types/socket-types.js b/lib/types/socket-types.js --- a/lib/types/socket-types.js +++ b/lib/types/socket-types.js @@ -50,7 +50,7 @@ type LoggedOutUserInfo, loggedOutUserInfoValidator, } from './user-types.js'; -import { mixedRawThreadInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js'; +import { mixedRawThreadInfoValidator } from '../permissions/minimally-encoded-raw-thread-info-validators.js'; import { tShape, tNumber, tID } from '../utils/validation-utils.js'; // The types of messages that the client sends across the socket diff --git a/lib/utils/thread-ops-utils.js b/lib/utils/thread-ops-utils.js --- a/lib/utils/thread-ops-utils.js +++ b/lib/utils/thread-ops-utils.js @@ -3,10 +3,10 @@ import invariant from 'invariant'; import { - MemberInfoValidator, + memberInfoValidator, roleInfoValidator, threadCurrentUserInfoValidator, -} from '../permissions/minimally-encoded-thread-permissions-validators.js'; +} from '../permissions/minimally-encoded-raw-thread-info-validators.js'; import type { MemberInfo, RawThreadInfo, @@ -49,7 +49,7 @@ const minimallyEncodedMembers: $ReadOnlyArray = rawMembers.map( rawMember => { invariant( - MemberInfoValidator.is(rawMember) || + memberInfoValidator.is(rawMember) || legacyMemberInfoValidator.is(rawMember), 'rawMember must be valid [MinimallyEncoded/Legacy]MemberInfo', );