From 6cb5ed8a29932316a047455759b5b72a999afcf7 Mon Sep 17 00:00:00 2001 From: Daniel McCartney Date: Fri, 4 Aug 2023 04:29:06 -0400 Subject: [PATCH 1/2] fix: use type from the reply nested content directly --- packages/content-type-reply/src/Reply.ts | 25 ++++++++---------------- packages/content-type-reply/src/index.ts | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/content-type-reply/src/Reply.ts b/packages/content-type-reply/src/Reply.ts index b9ea875..c58c9ca 100644 --- a/packages/content-type-reply/src/Reply.ts +++ b/packages/content-type-reply/src/Reply.ts @@ -28,19 +28,12 @@ export type Reply = { contentType: ContentTypeId; }; -export type ReplyParameters = Pick & { - contentType: string; -}; - export class ReplyCodec implements ContentCodec { get contentType(): ContentTypeId { return ContentTypeReply; } - encode( - content: Reply, - codecs: CodecRegistry, - ): EncodedContent { + encode(content: Reply, codecs: CodecRegistry): EncodedContent { const codec = codecs.codecFor(content.contentType); if (!codec) { throw new Error( @@ -54,6 +47,7 @@ export class ReplyCodec implements ContentCodec { return { type: ContentTypeReply, parameters: { + // TODO: cut when we're certain no one is looking for "contentType" here. contentType: content.contentType.toString(), reference: content.reference, }, @@ -61,19 +55,16 @@ export class ReplyCodec implements ContentCodec { }; } - decode( - content: EncodedContent, - codecs: CodecRegistry, - ): Reply { + decode(content: EncodedContent, codecs: CodecRegistry): Reply { const decodedContent = proto.EncodedContent.decode(content.content); - const contentType = ContentTypeId.fromString( - content.parameters.contentType, - ); - + if (!decodedContent.type) { + throw new Error("missing content type"); + } + const contentType = new ContentTypeId(decodedContent.type); const codec = codecs.codecFor(contentType); if (!codec) { throw new Error( - `missing codec for content type "${content.parameters.contentType}"`, + `missing codec for content type "${contentType.toString()}"`, ); } diff --git a/packages/content-type-reply/src/index.ts b/packages/content-type-reply/src/index.ts index acc5508..6496455 100644 --- a/packages/content-type-reply/src/index.ts +++ b/packages/content-type-reply/src/index.ts @@ -1,2 +1,2 @@ export { ReplyCodec, ContentTypeReply } from "./Reply"; -export type { Reply, ReplyParameters } from "./Reply"; +export type { Reply } from "./Reply"; From ae4fcdaa68ea5b1f4430d14f02f73231e194fd57 Mon Sep 17 00:00:00 2001 From: daria-github Date: Tue, 5 Sep 2023 16:10:47 -0700 Subject: [PATCH 2/2] add changeset --- .changeset/wise-coins-change.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wise-coins-change.md diff --git a/.changeset/wise-coins-change.md b/.changeset/wise-coins-change.md new file mode 100644 index 0000000..b4a372f --- /dev/null +++ b/.changeset/wise-coins-change.md @@ -0,0 +1,5 @@ +--- +"@xmtp/content-type-reply": patch +--- + +Gets the nested type of a reply from the deserialized EncodedContent instead of inspecting the parameter map