@xmtp/content-type-primitives
Version:
Primitives for building custom XMTP content types
37 lines (34 loc) • 1.33 kB
TypeScript
import { ContentTypeId, EncodedContent } from '@xmtp/node-bindings';
export { ContentTypeId, EncodedContent } from '@xmtp/node-bindings';
type ContentCodec<ContentType = unknown> = {
contentType: ContentTypeId;
encode(content: ContentType): EncodedContent;
decode(content: EncodedContent): ContentType;
fallback(content: ContentType): string | undefined;
shouldPush: (content: ContentType) => boolean;
};
/**
* Compares two content type IDs for equality
*
* @param a - First content type ID
* @param b - Second content type ID
* @returns True if the content type IDs are equal
*/
declare const contentTypesAreEqual: (a: ContentTypeId, b: ContentTypeId) => boolean;
/**
* Converts a content type ID to a string
*
* @param contentType - Content type ID
* @returns String representation of the content type ID
*/
declare const contentTypeToString: (contentType: ContentTypeId) => string;
/**
* Converts a string to a content type ID
*
* @param contentTypeString - String representation of the content type ID
* @returns Content type ID
* @throws Error if the string does not match the expected format
*/
declare const contentTypeFromString: (contentTypeString: string) => ContentTypeId;
export { contentTypeFromString, contentTypeToString, contentTypesAreEqual };
export type { ContentCodec };