Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix: use type from the reply nested content directly
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccartney committed Aug 4, 2023
1 parent 4f72afa commit a1a32e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions packages/content-type-reply/src/Reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ export type Reply = {
contentType: ContentTypeId;
};

export type ReplyParameters = Pick<Reply, "reference"> & {
contentType: string;
};

export class ReplyCodec implements ContentCodec<Reply> {
get contentType(): ContentTypeId {
return ContentTypeReply;
Expand All @@ -40,7 +36,7 @@ export class ReplyCodec implements ContentCodec<Reply> {
encode(
content: Reply,
codecs: CodecRegistry,
): EncodedContent<ReplyParameters> {
): EncodedContent {
const codec = codecs.codecFor(content.contentType);
if (!codec) {
throw new Error(
Expand All @@ -54,6 +50,7 @@ export class ReplyCodec implements ContentCodec<Reply> {
return {
type: ContentTypeReply,
parameters: {
// TODO: cut when we're certain no one is looking for "contentType" here.
contentType: content.contentType.toString(),
reference: content.reference,
},
Expand All @@ -62,18 +59,16 @@ export class ReplyCodec implements ContentCodec<Reply> {
}

decode(
content: EncodedContent<ReplyParameters>,
content: EncodedContent,
codecs: CodecRegistry,
): Reply {
const decodedContent = proto.EncodedContent.decode(content.content);
const contentType = ContentTypeId.fromString(
content.parameters.contentType,
);
const contentType = 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()}"`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/content-type-reply/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { ReplyCodec, ContentTypeReply } from "./Reply";
export type { Reply, ReplyParameters } from "./Reply";
export type { Reply } from "./Reply";

0 comments on commit a1a32e1

Please sign in to comment.