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 @@ -26,11 +26,17 @@ const minimallyEncodeRoleInfo = ( roleInfo: LegacyRoleInfo, -): MinimallyEncodedRoleInfo => ({ - ...roleInfo, - minimallyEncoded: true, - permissions: threadRolePermissionsBlobToBitmaskArray(roleInfo.permissions), -}); +): MinimallyEncodedRoleInfo => { + invariant( + !('minimallyEncoded' in roleInfo), + 'roleInfo is already minimally encoded.', + ); + return { + ...roleInfo, + minimallyEncoded: true, + permissions: threadRolePermissionsBlobToBitmaskArray(roleInfo.permissions), + }; +}; const decodeMinimallyEncodedRoleInfo = ( minimallyEncodedRoleInfo: MinimallyEncodedRoleInfo, @@ -84,11 +90,17 @@ const minimallyEncodeMemberInfo = ( memberInfo: LegacyMemberInfo, -): MinimallyEncodedMemberInfo => ({ - ...memberInfo, - minimallyEncoded: true, - permissions: permissionsToBitmaskHex(memberInfo.permissions), -}); +): MinimallyEncodedMemberInfo => { + invariant( + !('minimallyEncoded' in memberInfo), + 'memberInfo is already minimally encoded.', + ); + return { + ...memberInfo, + minimallyEncoded: true, + permissions: permissionsToBitmaskHex(memberInfo.permissions), + }; +}; const decodeMinimallyEncodedMemberInfo = ( minimallyEncodedMemberInfo: MinimallyEncodedMemberInfo, @@ -110,11 +122,17 @@ const minimallyEncodeRelativeMemberInfo = ( relativeMemberInfo: LegacyRelativeMemberInfo, -): MinimallyEncodedRelativeMemberInfo => ({ - ...relativeMemberInfo, - minimallyEncoded: true, - permissions: permissionsToBitmaskHex(relativeMemberInfo.permissions), -}); +): MinimallyEncodedRelativeMemberInfo => { + invariant( + !('minimallyEncoded' in relativeMemberInfo), + 'relativeMemberInfo is already minimally encoded.', + ); + return { + ...relativeMemberInfo, + minimallyEncoded: true, + permissions: permissionsToBitmaskHex(relativeMemberInfo.permissions), + }; +}; const decodeMinimallyEncodedRelativeMemberInfo = ( minimallyEncodedRelativeMemberInfo: MinimallyEncodedRelativeMemberInfo, @@ -139,6 +157,10 @@ const minimallyEncodeRawThreadInfo = ( rawThreadInfo: LegacyRawThreadInfo, ): MinimallyEncodedRawThreadInfo => { + invariant( + !('minimallyEncoded' in rawThreadInfo), + 'rawThreadInfo is already minimally encoded.', + ); const { members, roles, currentUser, ...rest } = rawThreadInfo; return { ...rest, @@ -173,6 +195,10 @@ const minimallyEncodeThreadInfo = ( threadInfo: LegacyThreadInfo, ): MinimallyEncodedThreadInfo => { + invariant( + !('minimallyEncoded' in threadInfo), + 'threadInfo is already minimally encoded.', + ); const { members, roles, currentUser, ...rest } = threadInfo; return { ...rest,