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 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";