fix channel schema `encode-url-data.ts` (#549)

* Update encode-url-data.ts

* Create slimy-keys-melt.md

* f

* f
This commit is contained in:
Felicio Mununga 2024-04-22 17:02:39 +02:00 committed by GitHub
parent 2d9dbdd49e
commit 13f7ed5415
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 27 deletions

View File

@ -0,0 +1,5 @@
---
"@status-im/js": patch
---
Update encode-url-data.ts

View File

@ -107,15 +107,6 @@ describe('Encode URL data', () => {
], ],
\\"message\\": \\"Required\\" \\"message\\": \\"Required\\"
}, },
{
\\"code\\": \\"invalid_type\\",
\\"expected\\": \\"string\\",
\\"received\\": \\"undefined\\",
\\"path\\": [
\\"emoji\\"
],
\\"message\\": \\"Required\\"
},
{ {
\\"code\\": \\"invalid_type\\", \\"code\\": \\"invalid_type\\",
\\"expected\\": \\"string\\", \\"expected\\": \\"string\\",
@ -188,15 +179,6 @@ describe('Encode URL data', () => {
], ],
\\"message\\": \\"Required\\" \\"message\\": \\"Required\\"
}, },
{
\\"code\\": \\"invalid_type\\",
\\"expected\\": \\"string\\",
\\"received\\": \\"undefined\\",
\\"path\\": [
\\"emoji\\"
],
\\"message\\": \\"Required\\"
},
{ {
\\"code\\": \\"invalid_type\\", \\"code\\": \\"invalid_type\\",
\\"expected\\": \\"string\\", \\"expected\\": \\"string\\",

View File

@ -25,8 +25,7 @@ export function encodeCommunityURLData(
return encodeURLData(new Community(data).toBinary()) as EncodedURLData return encodeURLData(new Community(data).toBinary()) as EncodedURLData
} }
// note: PlainMessage<T> type does not ensure returning of only own properties export function decodeCommunityURLData(data: string) {
export function decodeCommunityURLData(data: string): PlainMessage<Community> {
const deserialized = decodeURLData(data) const deserialized = decodeURLData(data)
const community = Community.fromBinary(deserialized.content).toJson() const community = Community.fromBinary(deserialized.content).toJson()
@ -37,7 +36,7 @@ export function decodeCommunityURLData(data: string): PlainMessage<Community> {
const channelSchema = z.object({ const channelSchema = z.object({
displayName: z.string().max(24).nonempty(), displayName: z.string().max(24).nonempty(),
description: z.string().max(140).nonempty(), description: z.string().max(140).nonempty(),
emoji: z.string().emoji(), emoji: z.string().emoji().optional(),
color: colorSchema, color: colorSchema,
community: z.object({ community: z.object({
displayName: communityDisplayName, displayName: communityDisplayName,
@ -51,12 +50,7 @@ export function encodeChannelURLData(
return encodeURLData(new Channel(data).toBinary()) as EncodedURLData return encodeURLData(new Channel(data).toBinary()) as EncodedURLData
} }
export function decodeChannelURLData(data: string): Omit< export function decodeChannelURLData(data: string) {
PlainMessage<Channel>,
'community'
> & {
community: Pick<PlainMessage<Community>, 'displayName'>
} {
const deserialized = decodeURLData(data) const deserialized = decodeURLData(data)
const channel = Channel.fromBinary(deserialized.content).toJson() const channel = Channel.fromBinary(deserialized.content).toJson()