@xmtp/content-type-primitives
Version:
Primitives for building custom XMTP content types
36 lines (33 loc) • 1.28 kB
TypeScript
import { content } from '@xmtp/proto';
declare class ContentTypeId {
authorityId: string;
typeId: string;
versionMajor: number;
versionMinor: number;
constructor(obj: content.ContentTypeId);
toString(): string;
static fromString(contentTypeString: string): ContentTypeId;
sameAs(id: ContentTypeId): boolean;
}
type EncodedContent<Parameters = Record<string, string>> = {
type: ContentTypeId;
parameters: Parameters;
fallback?: string;
compression?: number;
content: Uint8Array;
};
type ContentCodec<ContentType = unknown, Parameters = Record<string, string>> = {
contentType: ContentTypeId;
encode(content: ContentType, registry: CodecRegistry): EncodedContent<Parameters>;
decode(content: EncodedContent<Parameters>, registry: CodecRegistry): ContentType;
fallback(content: ContentType): string | undefined;
shouldPush: (content: ContentType) => boolean;
};
/**
* An interface implemented for accessing codecs by content type.
*/
interface CodecRegistry<T = unknown> {
codecFor(contentType: ContentTypeId): ContentCodec<T> | undefined;
}
type CodecMap<T = unknown> = Map<string, ContentCodec<T>>;
export { type CodecMap, type CodecRegistry, type ContentCodec, ContentTypeId, type EncodedContent };