Skip to content

Commit

Permalink
Merge pull request #284 from xmtp/rygine/db-update
Browse files Browse the repository at this point in the history
Upgrade dexie, remove DB versioning
  • Loading branch information
rygine authored Jul 22, 2024
2 parents 6e2af06 + 85802e8 commit 36fecdf
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 157 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-radios-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/react-sdk": major
---

Upgrade dexie, remove DB versioning
6 changes: 1 addition & 5 deletions apps/react/src/controllers/AppController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
import { WalletProvider } from "../contexts/WalletContext";
import { App } from "../components/App";

const DB_VERSION = 1;

const contentTypeConfigs = [
attachmentContentTypeConfig,
reactionContentTypeConfig,
Expand All @@ -17,9 +15,7 @@ const contentTypeConfigs = [

export const AppController: React.FC = () => (
<WalletProvider>
<XMTPProvider
dbVersion={DB_VERSION}
contentTypeConfigs={contentTypeConfigs}>
<XMTPProvider contentTypeConfigs={contentTypeConfigs}>
<App />
</XMTPProvider>
</WalletProvider>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@xmtp/content-type-text": "^1.0.0",
"async-mutex": "^0.5.0",
"date-fns": "^3.6.0",
"dexie": "^3.2.6",
"dexie": "^4.0.8",
"dexie-react-hooks": "^1.1.7",
"uuid": "^10.0.0",
"zod": "^3.23.8"
Expand Down
5 changes: 2 additions & 3 deletions packages/react-sdk/src/contexts/XMTPContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import type { XMTPProviderProps } from "@/contexts/XMTPContext";
import { XMTPProvider } from "@/contexts/XMTPContext";

type TestWrapperProps = PropsWithChildren &
Pick<XMTPProviderProps, "dbVersion" | "contentTypeConfigs">;
Pick<XMTPProviderProps, "contentTypeConfigs">;

const TestWrapper: React.FC<TestWrapperProps> = ({
contentTypeConfigs,
children,
dbVersion,
}) => (
<XMTPProvider contentTypeConfigs={contentTypeConfigs} dbVersion={dbVersion}>
<XMTPProvider contentTypeConfigs={contentTypeConfigs}>
{children}
</XMTPProvider>
);
Expand Down
11 changes: 1 addition & 10 deletions packages/react-sdk/src/contexts/XMTPContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,12 @@ export type XMTPProviderProps = React.PropsWithChildren & {
* processing of messages
*/
contentTypeConfigs?: ContentTypeConfiguration[];
/**
* Database version to use for the local cache
*
* This number should be incremented when adding support for additional
* content types
*/
dbVersion?: number;
};

export const XMTPProvider: React.FC<XMTPProviderProps> = ({
children,
client: initialClient,
contentTypeConfigs,
dbVersion,
}) => {
const [client, setClient] = useState<Client | undefined>(initialClient);

Expand Down Expand Up @@ -112,9 +104,8 @@ export const XMTPProvider: React.FC<XMTPProviderProps> = ({
getDbInstance({
db: initialDb,
contentTypeConfigs,
version: dbVersion,
}),
[dbVersion, contentTypeConfigs],
[contentTypeConfigs],
);

// memo-ize the context value to prevent unnecessary re-renders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
hasAttachment,
attachmentContentTypeConfig,
} from "./attachment";
import { type CachedMessageWithId } from "@/helpers/caching/messages";
import { type CachedMessage } from "@/helpers/caching/messages";
import { createRandomWallet } from "@/helpers/testing";

const testWallet = createRandomWallet();
Expand Down Expand Up @@ -53,7 +53,7 @@ describe("ContentTypeRemoteAttachment caching", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId<Attachment>;
} satisfies CachedMessage<Attachment>;

const attachment = getAttachment(testMessage);
expect(attachment).toEqual(testContent);
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("ContentTypeRemoteAttachment caching", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId<RemoteAttachment>;
} satisfies CachedMessage<RemoteAttachment>;

const attachment2 = getAttachment(testMessage2);
expect(attachment2).toEqual(testContent2);
Expand All @@ -101,7 +101,7 @@ describe("ContentTypeRemoteAttachment caching", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const attachment3 = getAttachment(testMessage3);
expect(attachment3).toBeUndefined();
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("ContentTypeRemoteAttachment caching", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId<Attachment>;
} satisfies CachedMessage<Attachment>;

const attachment = hasAttachment(testMessage);
expect(attachment).toBe(true);
Expand All @@ -148,7 +148,7 @@ describe("ContentTypeRemoteAttachment caching", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const attachment2 = hasAttachment(testMessage2);
expect(attachment2).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {
} from "./reaction";
import {
saveMessage,
type CachedMessageWithId,
type CachedMessage,
getMessageByXmtpID,
} from "@/helpers/caching/messages";
import { getDbInstance, clearCache } from "@/helpers/caching/db";
import type { CachedConversationWithId } from "@/helpers/caching/conversations";
import type { CachedConversation } from "@/helpers/caching/conversations";
import { createRandomWallet } from "@/helpers/testing";

const testWallet = createRandomWallet();
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("ContentTypeReaction", () => {
topic: "testTopic",
peerAddress: "testPeerAddress",
walletAddress: testWallet.account.address,
} satisfies CachedConversationWithId;
} satisfies CachedConversation;
const testTextMessage = {
id: 1,
walletAddress: testWallet.account.address,
Expand All @@ -106,7 +106,7 @@ describe("ContentTypeReaction", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid1",
xmtpID: "testXmtpId1",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

await saveMessage(testTextMessage, db);

Expand All @@ -131,7 +131,7 @@ describe("ContentTypeReaction", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid2",
xmtpID: "testXmtpId2",
} satisfies CachedMessageWithId<Reaction>;
} satisfies CachedMessage<Reaction>;

const updateConversationMetadata = vi.fn();
await processReaction({
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("ContentTypeReaction", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid3",
xmtpID: "testXmtpId3",
} satisfies CachedMessageWithId<Reaction>;
} satisfies CachedMessage<Reaction>;

await processReaction({
client: testClient,
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("ContentTypeReaction", () => {
topic: "testTopic",
peerAddress: "testPeerAddress",
walletAddress: testWallet.account.address,
} satisfies CachedConversationWithId;
} satisfies CachedConversation;
const testMessage = {
id: 1,
walletAddress: testWallet.account.address,
Expand All @@ -216,7 +216,7 @@ describe("ContentTypeReaction", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const updateConversationMetadata = vi.fn();
await processReaction({
Expand Down
26 changes: 13 additions & 13 deletions packages/react-sdk/src/helpers/caching/contentTypes/reply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
} from "./reply";
import {
saveMessage,
type CachedMessageWithId,
type CachedMessage,
getMessageByXmtpID,
} from "@/helpers/caching/messages";
import { getDbInstance, clearCache } from "@/helpers/caching/db";
import type { CachedConversationWithId } from "@/helpers/caching/conversations";
import type { CachedConversation } from "@/helpers/caching/conversations";
import { createRandomWallet } from "@/helpers/testing";

const testWallet = createRandomWallet();
Expand Down Expand Up @@ -53,7 +53,7 @@ describe("ContentTypeReply", () => {
topic: "testTopic",
peerAddress: "testPeerAddress",
walletAddress: testWallet.account.address,
} satisfies CachedConversationWithId;
} satisfies CachedConversation;
const testTextMessage = {
id: 1,
walletAddress: testWallet.account.address,
Expand All @@ -68,7 +68,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid1",
xmtpID: "testXmtpId1",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

await saveMessage(testTextMessage, db);

Expand All @@ -92,7 +92,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid2",
xmtpID: "testXmtpId2",
} satisfies CachedMessageWithId<Reply>;
} satisfies CachedMessage<Reply>;

await saveMessage(testReplyMessage, db);

Expand Down Expand Up @@ -130,7 +130,7 @@ describe("ContentTypeReply", () => {
topic: "testTopic",
peerAddress: "testPeerAddress",
walletAddress: testWallet.account.address,
} satisfies CachedConversationWithId;
} satisfies CachedConversation;
const testMessage = {
id: 1,
walletAddress: testWallet.account.address,
Expand All @@ -145,7 +145,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid",
xmtpID: "testXmtpId",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const updateConversationMetadata = vi.fn();
await processReply({
Expand Down Expand Up @@ -175,7 +175,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid1",
xmtpID: "testXmtpId1",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const originalMessageFromReply = await getOriginalMessageFromReply(
testTextMessage,
Expand All @@ -201,7 +201,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid2",
xmtpID: "testXmtpId2",
} satisfies CachedMessageWithId<Reply>;
} satisfies CachedMessage<Reply>;

const originalMessageFromReply2 = await getOriginalMessageFromReply(
testReplyMessage,
Expand All @@ -227,7 +227,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid1",
xmtpID: "testXmtpId1",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const replies = await getReplies(testTextMessage, db);
expect(replies).toEqual([]);
Expand All @@ -250,7 +250,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid1",
xmtpID: "testXmtpId1",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

const testReplyMessage1 = {
id: 2,
Expand All @@ -270,7 +270,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid2",
xmtpID: "testXmtpId2",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

await saveMessage(testReplyMessage1, db);

Expand All @@ -292,7 +292,7 @@ describe("ContentTypeReply", () => {
senderAddress: "testWalletAddress",
uuid: "testUuid3",
xmtpID: "testXmtpId3",
} satisfies CachedMessageWithId;
} satisfies CachedMessage;

await saveMessage(testReplyMessage2, db);

Expand Down
3 changes: 1 addition & 2 deletions packages/react-sdk/src/helpers/caching/contentTypes/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { z } from "zod";
import { ContentTypeId } from "@xmtp/content-type-primitives";
import type {
CachedMessage,
CachedMessageWithId,
CachedMessagesTable,
} from "@/helpers/caching/messages";
import type {
Expand Down Expand Up @@ -75,7 +74,7 @@ export const getReplies = async (message: CachedMessage, db: Dexie) => {
.where("xmtpID")
.anyOf(replies.map((reply) => reply.xmtpID))
.sortBy("sentAt");
return replyMessages as CachedMessageWithId[];
return replyMessages;
}
return [];
};
Expand Down
Loading

0 comments on commit 36fecdf

Please sign in to comment.