Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3522253
D9856.id33221.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D9856.id33221.diff
View Options
diff --git a/lib/permissions/minimally-encoded-thread-permissions-validators.js b/lib/permissions/minimally-encoded-thread-permissions-validators.js
new file mode 100644
--- /dev/null
+++ b/lib/permissions/minimally-encoded-thread-permissions-validators.js
@@ -0,0 +1,78 @@
+// @flow
+import t, { type TInterface } from 'tcomb';
+
+import {
+ tHexEncodedPermissionsBitmask,
+ tHexEncodedRolePermission,
+} from './minimally-encoded-thread-permissions.js';
+import type {
+ MinimallyEncodedMemberInfo,
+ MinimallyEncodedRawThreadInfo,
+ MinimallyEncodedRelativeMemberInfo,
+ MinimallyEncodedRoleInfo,
+ MinimallyEncodedThreadCurrentUserInfo,
+ MinimallyEncodedThreadInfo,
+} from '../types/minimally-encoded-thread-permissions-types.js';
+import {
+ memberInfoValidator,
+ rawThreadInfoValidator,
+ roleInfoValidator,
+ threadCurrentUserInfoValidator,
+ threadInfoValidator,
+} from '../types/thread-types.js';
+import { tBool, tID, tShape } from '../utils/validation-utils.js';
+
+const minimallyEncodedRoleInfoValidator: TInterface<MinimallyEncodedRoleInfo> =
+ tShape<MinimallyEncodedRoleInfo>({
+ ...roleInfoValidator.meta.props,
+ minimallyEncoded: tBool(true),
+ permissions: t.list(tHexEncodedRolePermission),
+ });
+
+const minimallyEncodedThreadCurrentUserInfoValidator: TInterface<MinimallyEncodedThreadCurrentUserInfo> =
+ tShape<MinimallyEncodedThreadCurrentUserInfo>({
+ ...threadCurrentUserInfoValidator.meta.props,
+ minimallyEncoded: tBool(true),
+ permissions: tHexEncodedPermissionsBitmask,
+ });
+
+const minimallyEncodedMemberInfoValidator: TInterface<MinimallyEncodedMemberInfo> =
+ tShape<MinimallyEncodedMemberInfo>({
+ ...memberInfoValidator.meta.props,
+ minimallyEncoded: tBool(true),
+ permissions: tHexEncodedPermissionsBitmask,
+ });
+
+const minimallyEncodedRelativeMemberInfoValidator: TInterface<MinimallyEncodedRelativeMemberInfo> =
+ tShape<MinimallyEncodedRelativeMemberInfo>({
+ ...minimallyEncodedMemberInfoValidator.meta.props,
+ username: t.maybe(t.String),
+ isViewer: t.Boolean,
+ });
+
+const minimallyEncodedThreadInfoValidator: TInterface<MinimallyEncodedThreadInfo> =
+ tShape<MinimallyEncodedThreadInfo>({
+ ...threadInfoValidator.meta.props,
+ minimallyEncoded: tBool(true),
+ members: t.list(minimallyEncodedRelativeMemberInfoValidator),
+ roles: t.dict(tID, minimallyEncodedRoleInfoValidator),
+ currentUser: minimallyEncodedThreadCurrentUserInfoValidator,
+ });
+
+const minimallyEncodedRawThreadInfoValidator: TInterface<MinimallyEncodedRawThreadInfo> =
+ tShape<MinimallyEncodedRawThreadInfo>({
+ ...rawThreadInfoValidator.meta.props,
+ minimallyEncoded: tBool(true),
+ members: t.list(minimallyEncodedMemberInfoValidator),
+ roles: t.dict(tID, minimallyEncodedRoleInfoValidator),
+ currentUser: minimallyEncodedThreadCurrentUserInfoValidator,
+ });
+
+export {
+ minimallyEncodedRoleInfoValidator,
+ minimallyEncodedThreadCurrentUserInfoValidator,
+ minimallyEncodedMemberInfoValidator,
+ minimallyEncodedRelativeMemberInfoValidator,
+ minimallyEncodedThreadInfoValidator,
+ minimallyEncodedRawThreadInfoValidator,
+};
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
@@ -5,6 +5,12 @@
exampleRawThreadInfoA,
expectedDecodedExampleRawThreadInfoA,
} from './minimally-encoded-thread-permissions-test-data.js';
+import {
+ minimallyEncodedMemberInfoValidator,
+ minimallyEncodedRawThreadInfoValidator,
+ minimallyEncodedRoleInfoValidator,
+ minimallyEncodedThreadCurrentUserInfoValidator,
+} from './minimally-encoded-thread-permissions-validators.js';
import {
decodeRolePermissionBitmask,
decodeThreadRolePermissionsBitmaskArray,
@@ -15,10 +21,6 @@
threadRolePermissionsBlobToBitmaskArray,
} from './minimally-encoded-thread-permissions.js';
import {
- minimallyEncodedMemberInfoValidator,
- minimallyEncodedThreadCurrentUserInfoValidator,
- minimallyEncodedRawThreadInfoValidator,
- minimallyEncodedRoleInfoValidator,
minimallyEncodeRawThreadInfo,
decodeMinimallyEncodedRawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
diff --git a/lib/types/minimally-encoded-thread-permissions-types.js b/lib/types/minimally-encoded-thread-permissions-types.js
--- a/lib/types/minimally-encoded-thread-permissions-types.js
+++ b/lib/types/minimally-encoded-thread-permissions-types.js
@@ -1,16 +1,7 @@
// @flow
import _mapValues from 'lodash/fp/mapValues.js';
-import type { TInterface } from 'tcomb';
-import t from 'tcomb';
-import {
- memberInfoValidator,
- rawThreadInfoValidator,
- roleInfoValidator,
- threadCurrentUserInfoValidator,
- threadInfoValidator,
-} from './thread-types.js';
import type {
MemberInfo,
RawThreadInfo,
@@ -24,10 +15,7 @@
permissionsToBitmaskHex,
threadPermissionsFromBitmaskHex,
threadRolePermissionsBlobToBitmaskArray,
- tHexEncodedRolePermission,
- tHexEncodedPermissionsBitmask,
} from '../permissions/minimally-encoded-thread-permissions.js';
-import { tBool, tID, tShape } from '../utils/validation-utils.js';
export type MinimallyEncodedRoleInfo = $ReadOnly<{
...RoleInfo,
@@ -35,13 +23,6 @@
+permissions: $ReadOnlyArray<string>,
}>;
-const minimallyEncodedRoleInfoValidator: TInterface<MinimallyEncodedRoleInfo> =
- tShape<MinimallyEncodedRoleInfo>({
- ...roleInfoValidator.meta.props,
- minimallyEncoded: tBool(true),
- permissions: t.list(tHexEncodedRolePermission),
- });
-
const minimallyEncodeRoleInfo = (
roleInfo: RoleInfo,
): MinimallyEncodedRoleInfo => ({
@@ -68,13 +49,6 @@
+permissions: string,
}>;
-const minimallyEncodedThreadCurrentUserInfoValidator: TInterface<MinimallyEncodedThreadCurrentUserInfo> =
- tShape<MinimallyEncodedThreadCurrentUserInfo>({
- ...threadCurrentUserInfoValidator.meta.props,
- minimallyEncoded: tBool(true),
- permissions: tHexEncodedPermissionsBitmask,
- });
-
const minimallyEncodeThreadCurrentUserInfo = (
threadCurrentUserInfo: ThreadCurrentUserInfo,
): MinimallyEncodedThreadCurrentUserInfo => ({
@@ -101,13 +75,6 @@
+permissions: string,
}>;
-const minimallyEncodedMemberInfoValidator: TInterface<MinimallyEncodedMemberInfo> =
- tShape<MinimallyEncodedMemberInfo>({
- ...memberInfoValidator.meta.props,
- minimallyEncoded: tBool(true),
- permissions: tHexEncodedPermissionsBitmask,
- });
-
const minimallyEncodeMemberInfo = (
memberInfo: MemberInfo,
): MinimallyEncodedMemberInfo => ({
@@ -134,13 +101,6 @@
+isViewer: boolean,
}>;
-const minimallyEncodedRelativeMemberInfoValidator: TInterface<MinimallyEncodedRelativeMemberInfo> =
- tShape<MinimallyEncodedRelativeMemberInfo>({
- ...minimallyEncodedMemberInfoValidator.meta.props,
- username: t.maybe(t.String),
- isViewer: t.Boolean,
- });
-
const minimallyEncodeRelativeMemberInfo = (
relativeMemberInfo: RelativeMemberInfo,
): MinimallyEncodedRelativeMemberInfo => ({
@@ -169,15 +129,6 @@
+currentUser: MinimallyEncodedThreadCurrentUserInfo,
}>;
-const minimallyEncodedRawThreadInfoValidator: TInterface<MinimallyEncodedRawThreadInfo> =
- tShape<MinimallyEncodedRawThreadInfo>({
- ...rawThreadInfoValidator.meta.props,
- minimallyEncoded: tBool(true),
- members: t.list(minimallyEncodedMemberInfoValidator),
- roles: t.dict(tID, minimallyEncodedRoleInfoValidator),
- currentUser: minimallyEncodedThreadCurrentUserInfoValidator,
- });
-
const minimallyEncodeRawThreadInfo = (
rawThreadInfo: RawThreadInfo,
): MinimallyEncodedRawThreadInfo => {
@@ -212,15 +163,6 @@
+currentUser: MinimallyEncodedThreadCurrentUserInfo,
}>;
-const minimallyEncodedThreadInfoValidator: TInterface<MinimallyEncodedThreadInfo> =
- tShape<MinimallyEncodedThreadInfo>({
- ...threadInfoValidator.meta.props,
- minimallyEncoded: tBool(true),
- members: t.list(minimallyEncodedRelativeMemberInfoValidator),
- roles: t.dict(tID, minimallyEncodedRoleInfoValidator),
- currentUser: minimallyEncodedThreadCurrentUserInfoValidator,
- });
-
const minimallyEncodeThreadInfo = (
threadInfo: ThreadInfo,
): MinimallyEncodedThreadInfo => {
@@ -248,22 +190,16 @@
};
export {
- minimallyEncodedRoleInfoValidator,
minimallyEncodeRoleInfo,
decodeMinimallyEncodedRoleInfo,
- minimallyEncodedThreadCurrentUserInfoValidator,
minimallyEncodeThreadCurrentUserInfo,
decodeMinimallyEncodedThreadCurrentUserInfo,
- minimallyEncodedMemberInfoValidator,
minimallyEncodeMemberInfo,
decodeMinimallyEncodedMemberInfo,
- minimallyEncodedRawThreadInfoValidator,
minimallyEncodeRawThreadInfo,
decodeMinimallyEncodedRawThreadInfo,
- minimallyEncodedRelativeMemberInfoValidator,
minimallyEncodeRelativeMemberInfo,
decodeMinimallyEncodedRelativeMemberInfo,
- minimallyEncodedThreadInfoValidator,
minimallyEncodeThreadInfo,
decodeMinimallyEncodedThreadInfo,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 6:12 AM (19 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2697996
Default Alt Text
D9856.id33221.diff (8 KB)
Attached To
Mode
D9856: [lib] Move `MinimallyEncoded*` validators to their own file
Attached
Detach File
Event Timeline
Log In to Comment