Skip to content

Commit

Permalink
Remove CompositeContentType
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Jun 14, 2024
1 parent 0e75750 commit 308afca
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 192 deletions.
7 changes: 0 additions & 7 deletions packages/js-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,6 @@ As shown in the example above, you must provide a `contentFallback` value. Use i
Additional codecs can be configured through the `ClientOptions` parameter of `Client.create`. The `codecs` option is a list of codec instances that should be added to the default set of codecs (currently only the `TextCodec`). If a codec is added for a content type that is already in the default set, it will replace the original codec.

```ts
// Adding support for `xmtp.org/composite` content type
import { CompositeCodec } from '@xmtp/xmtp-js'

const xmtp = Client.create(wallet, { codecs: [new CompositeCodec()] })
```

To learn more about how to build a custom content type, see [Build a custom content type](https://xmtp.org/docs/content-types/introduction#create-custom-content-types).

Custom codecs and content types may be proposed as interoperable standards through XRCs. To learn about the custom content type proposal process, see [XIP-5](https://github.com/xmtp/XIPs/blob/main/XIPs/xip-5-message-content-types.md).
Expand Down
118 changes: 0 additions & 118 deletions packages/js-sdk/src/codecs/Composite.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/js-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export type {
} from './MessageContent'
export { ContentTypeId, ContentTypeFallback } from './MessageContent'
export { TextCodec, ContentTypeText } from './codecs/Text'
export type { Composite } from './codecs/Composite'
export { CompositeCodec, ContentTypeComposite } from './codecs/Composite'
export type {
ApiClient,
QueryParams,
Expand Down
46 changes: 43 additions & 3 deletions packages/js-sdk/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { mainnet } from 'viem/chains'
import { assert, vi } from 'vitest'
import HttpApiClient, { ApiUrls } from '@/ApiClient'
import Client, { Compression, type ClientOptions } from '@/Client'
import { CompositeCodec } from '@/codecs/Composite'
import { ContentTypeText, TextCodec } from '@/codecs/Text'
import { PrivateKey } from '@/crypto/PrivateKey'
import { PrivateKeyBundleV1 } from '@/crypto/PrivateKeyBundle'
Expand All @@ -16,6 +15,11 @@ import LocalStoragePonyfill from '@/keystore/persistence/LocalStoragePonyfill'
import TopicPersistence from '@/keystore/persistence/TopicPersistence'
import NetworkKeyManager from '@/keystore/providers/NetworkKeyManager'
import NetworkKeystoreProvider from '@/keystore/providers/NetworkKeystoreProvider'
import {
ContentTypeId,
type ContentCodec,
type EncodedContent,
} from '@/MessageContent'
import type { EnvelopeWithMessage } from '@/utils/async'
import { buildUserContactTopic } from '@/utils/topic'
import { ContentTypeTestKey, TestKeyCodec } from './ContentTypeTestKey'
Expand Down Expand Up @@ -420,15 +424,51 @@ describe('ClientOptions', () => {
})

it('allows you to use custom content types', async () => {
const ContentTypeCustom = new ContentTypeId({
authorityId: 'xmtp.org',
typeId: 'text',
versionMajor: 1,
versionMinor: 0,
})
class CustomCodec implements ContentCodec<{ custom: string }> {
get contentType(): ContentTypeId {
return ContentTypeCustom
}

encode(content: { custom: string }): EncodedContent {
return {
type: ContentTypeText,
parameters: {},
content: new TextEncoder().encode(JSON.stringify(content)),
}
}

decode(content: EncodedContent): { custom: string } {
const decodedContent = new TextDecoder().decode(content.content)
const parsedContent = JSON.parse(decodedContent) as { custom: string }
return {
custom: parsedContent.custom,
}
}

fallback() {
return undefined
}

shouldPush() {
return false
}
}

const client = await Client.create(newWallet(), {
codecs: [new CustomCodec()],
env: 'local',
codecs: [new CompositeCodec()],
})
const other = await Client.create(newWallet(), { env: 'local' })
const convo = await client.conversations.newConversation(other.address)
expect(convo).toBeTruthy()
// This will have a type error if the codecs field isn't being respected
await convo.send({ parts: [{ type: ContentTypeText, content: 'foo' }] })
await convo.send({ custom: 'test' })
})
})

Expand Down
62 changes: 0 additions & 62 deletions packages/js-sdk/test/codecs/Composite.test.ts

This file was deleted.

0 comments on commit 308afca

Please sign in to comment.