Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade bindings #756

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/four-bats-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@xmtp/browser-sdk": patch
"@xmtp/node-sdk": patch
---

Upgrade bindings
2 changes: 1 addition & 1 deletion sdks/browser-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@xmtp/content-type-primitives": "^2.0.0",
"@xmtp/content-type-text": "^2.0.0",
"@xmtp/proto": "^3.72.3",
"@xmtp/wasm-bindings": "^0.0.8",
"@xmtp/wasm-bindings": "^0.0.9",
"uuid": "^11.0.3"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions sdks/browser-sdk/src/WorkerConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export class WorkerConversation {
return this.#group.createdAtNs();
}

get metadata() {
const metadata = this.#group.groupMetadata();
async metadata() {
const metadata = await this.#group.groupMetadata();
return {
creatorInboxId: metadata.creatorInboxId(),
conversationType: metadata.conversationType(),
Expand Down Expand Up @@ -155,7 +155,7 @@ export class WorkerConversation {
return this.#group.send(encodedContent);
}

messages(options?: SafeListMessagesOptions) {
async messages(options?: SafeListMessagesOptions) {
return this.#group.findMessages(
options ? fromSafeListMessagesOptions(options) : undefined,
);
Expand Down
6 changes: 3 additions & 3 deletions sdks/browser-sdk/src/utils/conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ export type SafeConversation = {
createdAtNs: bigint;
};

export const toSafeConversation = (
export const toSafeConversation = async (
conversation: WorkerConversation,
): SafeConversation => ({
): Promise<SafeConversation> => ({
id: conversation.id,
name: conversation.name,
imageUrl: conversation.imageUrl,
Expand All @@ -332,7 +332,7 @@ export const toSafeConversation = (
},
isActive: conversation.isActive,
addedByInboxId: conversation.addedByInboxId,
metadata: conversation.metadata,
metadata: await conversation.metadata(),
admins: conversation.admins,
superAdmins: conversation.superAdmins,
createdAtNs: conversation.createdAtNs,
Expand Down
34 changes: 22 additions & 12 deletions sdks/browser-sdk/src/workers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: conversations.map((conversation) =>
toSafeConversation(conversation),
result: await Promise.all(
conversations.map((conversation) =>
toSafeConversation(conversation),
),
),
});
break;
Expand All @@ -272,8 +274,10 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: conversations.map((conversation) =>
toSafeConversation(conversation),
result: await Promise.all(
conversations.map((conversation) =>
toSafeConversation(conversation),
),
),
});
break;
Expand All @@ -283,8 +287,10 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: conversations.map((conversation) =>
toSafeConversation(conversation),
result: await Promise.all(
conversations.map((conversation) =>
toSafeConversation(conversation),
),
),
});
break;
Expand All @@ -302,7 +308,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: toSafeConversation(conversation),
result: await toSafeConversation(conversation),
});
break;
}
Expand All @@ -313,7 +319,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: toSafeConversation(conversation),
result: await toSafeConversation(conversation),
});
break;
}
Expand All @@ -340,7 +346,9 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: conversation ? toSafeConversation(conversation) : undefined,
result: conversation
? await toSafeConversation(conversation)
: undefined,
});
break;
}
Expand All @@ -358,7 +366,9 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: conversation ? toSafeConversation(conversation) : undefined,
result: conversation
? await toSafeConversation(conversation)
: undefined,
});
break;
}
Expand All @@ -372,7 +382,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
postMessage({
id,
action,
result: toSafeConversation(group),
result: await toSafeConversation(group),
});
} else {
postMessageError({
Expand Down Expand Up @@ -516,7 +526,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
case "getGroupMessages": {
const group = client.conversations.getConversationById(data.id);
if (group) {
const messages = group.messages(data.options);
const messages = await group.messages(data.options);
postMessage({
id,
action,
Expand Down
2 changes: 1 addition & 1 deletion sdks/node-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@xmtp/content-type-group-updated": "^2.0.0",
"@xmtp/content-type-primitives": "^2.0.0",
"@xmtp/content-type-text": "^2.0.0",
"@xmtp/node-bindings": "^0.0.29",
"@xmtp/node-bindings": "^0.0.30",
"@xmtp/proto": "^3.72.3"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions sdks/node-sdk/src/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class Conversation {
return nsToDate(this.createdAtNs);
}

get metadata() {
const metadata = this.#group.groupMetadata();
async metadata() {
const metadata = await this.#group.groupMetadata();
return {
creatorInboxId: metadata.creatorInboxId(),
conversationType: metadata.conversationType(),
Expand Down Expand Up @@ -194,10 +194,10 @@ export class Conversation {
return this.#group.send(encodedContent);
}

messages(options?: ListMessagesOptions): DecodedMessage[] {
async messages(options?: ListMessagesOptions): Promise<DecodedMessage[]> {
const messages = await this.#group.findMessages(options);
return (
this.#group
.findMessages(options)
messages
.map((message) => new DecodedMessage(this.#client, message))
// filter out messages without content
.filter((message) => message.content !== undefined)
Expand Down
30 changes: 17 additions & 13 deletions sdks/node-sdk/test/Conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Conversation", () => {
const newName = "foo";
await conversation.updateName(newName);
expect(conversation.name).toBe(newName);
const messages = conversation.messages();
const messages = await conversation.messages();
expect(messages.length).toBe(2);

await client2.conversations.sync();
Expand All @@ -31,7 +31,8 @@ describe("Conversation", () => {
await conversation2.sync();
expect(conversation2.id).toBe(conversation.id);
expect(conversation2.name).toBe(newName);
expect(conversation2.messages().length).toBe(1);
const messages2 = await conversation2.messages();
expect(messages2.length).toBe(1);
});

it("should update conversation image URL", async () => {
Expand All @@ -45,7 +46,7 @@ describe("Conversation", () => {
const imageUrl = "https://foo/bar.jpg";
await conversation.updateImageUrl(imageUrl);
expect(conversation.imageUrl).toBe(imageUrl);
const messages = conversation.messages();
const messages = await conversation.messages();
expect(messages.length).toBe(2);

await client2.conversations.sync();
Expand All @@ -57,7 +58,8 @@ describe("Conversation", () => {
await conversation2.sync();
expect(conversation2.id).toBe(conversation.id);
expect(conversation2.imageUrl).toBe(imageUrl);
expect(conversation2.messages().length).toBe(1);
const messages2 = await conversation2.messages();
expect(messages2.length).toBe(1);
});

it("should update conversation description", async () => {
Expand All @@ -71,7 +73,7 @@ describe("Conversation", () => {
const newDescription = "foo";
await conversation.updateDescription(newDescription);
expect(conversation.description).toBe(newDescription);
const messages = conversation.messages();
const messages = await conversation.messages();
expect(messages.length).toBe(2);

await client2.conversations.sync();
Expand All @@ -83,7 +85,8 @@ describe("Conversation", () => {
await conversation2.sync();
expect(conversation2.id).toBe(conversation.id);
expect(conversation2.description).toBe(newDescription);
expect(conversation2.messages().length).toBe(1);
const messages2 = await conversation2.messages();
expect(messages2.length).toBe(1);
});

it("should update conversation pinned frame URL", async () => {
Expand All @@ -97,7 +100,7 @@ describe("Conversation", () => {
const pinnedFrameUrl = "https://foo/bar";
await conversation.updatePinnedFrameUrl(pinnedFrameUrl);
expect(conversation.pinnedFrameUrl).toBe(pinnedFrameUrl);
const messages = conversation.messages();
const messages = await conversation.messages();
expect(messages.length).toBe(2);

await client2.conversations.sync();
Expand All @@ -109,7 +112,8 @@ describe("Conversation", () => {
await conversation2.sync();
expect(conversation2.id).toBe(conversation.id);
expect(conversation2.pinnedFrameUrl).toBe(pinnedFrameUrl);
expect(conversation2.messages().length).toBe(1);
const messages2 = await conversation2.messages();
expect(messages2.length).toBe(1);
});

it("should add and remove members", async () => {
Expand Down Expand Up @@ -201,7 +205,7 @@ describe("Conversation", () => {
const text = "gm";
await conversation.send(text);

const messages = conversation.messages();
const messages = await conversation.messages();
expect(messages.length).toBe(2);
expect(messages[1].content).toBe(text);

Expand All @@ -214,7 +218,7 @@ describe("Conversation", () => {
await conversation2.sync();
expect(conversation2.id).toBe(conversation.id);

const messages2 = conversation2.messages();
const messages2 = await conversation2.messages();
expect(messages2.length).toBe(1);
expect(messages2[0].content).toBe(text);
});
Expand Down Expand Up @@ -249,7 +253,7 @@ describe("Conversation", () => {
const text = "gm";
conversation.sendOptimistic(text);

const messages = conversation.messages();
const messages = await conversation.messages();
expect(messages.length).toBe(2);
expect(messages[1].content).toBe(text);

Expand All @@ -263,13 +267,13 @@ describe("Conversation", () => {
await conversation2.sync();
expect(conversation2.id).toBe(conversation.id);

const messages2 = conversation2.messages();
const messages2 = await conversation2.messages();
expect(messages2.length).toBe(0);

await conversation.publishMessages();
await conversation2.sync();

const messages4 = conversation2.messages();
const messages4 = await conversation2.messages();
expect(messages4.length).toBe(1);
expect(messages4[0].content).toBe(text);
});
Expand Down
10 changes: 5 additions & 5 deletions sdks/node-sdk/test/Conversations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ describe("Conversations", () => {
updateGroupPinnedFrameUrlPolicy: 0,
});
expect(conversation.addedByInboxId).toBe(client1.inboxId);
expect(conversation.messages().length).toBe(1);
expect((await conversation.messages()).length).toBe(1);

const members = await conversation.members();
expect(members.length).toBe(2);
const memberInboxIds = members.map((member) => member.inboxId);
expect(memberInboxIds).toContain(client1.inboxId);
expect(memberInboxIds).toContain(client2.inboxId);
expect(conversation.metadata).toEqual({
expect(await conversation.metadata()).toEqual({
conversationType: "group",
creatorInboxId: client1.inboxId,
});
Expand Down Expand Up @@ -97,14 +97,14 @@ describe("Conversations", () => {
updateGroupPinnedFrameUrlPolicy: 0,
});
expect(group.addedByInboxId).toBe(client1.inboxId);
expect(group.messages().length).toBe(0);
expect((await group.messages()).length).toBe(0);
const members = await group.members();
expect(members.length).toBe(2);
const memberInboxIds = members.map((member) => member.inboxId);
expect(memberInboxIds).toContain(client1.inboxId);
expect(memberInboxIds).toContain(client2.inboxId);
expect(group.metadata.conversationType).toBe("dm");
expect(group.metadata.creatorInboxId).toBe(client1.inboxId);
expect((await group.metadata()).conversationType).toBe("dm");
expect((await group.metadata()).creatorInboxId).toBe(client1.inboxId);

expect(group.consentState).toBe(ConsentState.Allowed);

Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4809,7 +4809,7 @@ __metadata:
"@xmtp/content-type-primitives": "npm:^2.0.0"
"@xmtp/content-type-text": "npm:^2.0.0"
"@xmtp/proto": "npm:^3.72.3"
"@xmtp/wasm-bindings": "npm:^0.0.8"
"@xmtp/wasm-bindings": "npm:^0.0.9"
playwright: "npm:^1.49.0"
rollup: "npm:^4.27.3"
rollup-plugin-dts: "npm:^6.1.1"
Expand Down Expand Up @@ -5114,10 +5114,10 @@ __metadata:
languageName: node
linkType: hard

"@xmtp/node-bindings@npm:^0.0.29":
version: 0.0.29
resolution: "@xmtp/node-bindings@npm:0.0.29"
checksum: 10/d6abb86a58517bffff07bda59b387318a9d60b2ba0ca13376ef60fe79aa9afefb8e2b07b218064738b07c4e699eac967f8aff64942017f8872f4fe982ac475ae
"@xmtp/node-bindings@npm:^0.0.30":
version: 0.0.30
resolution: "@xmtp/node-bindings@npm:0.0.30"
checksum: 10/a7bf581c038f811b38ea53690b1500bd931b3fb8c32798fc96cf852ab5e0fc0b837fdfc2f354943be45095f096c23467e8de5a96235409b2013fc49c27cb2644
languageName: node
linkType: hard

Expand Down Expand Up @@ -5145,7 +5145,7 @@ __metadata:
"@xmtp/content-type-group-updated": "npm:^2.0.0"
"@xmtp/content-type-primitives": "npm:^2.0.0"
"@xmtp/content-type-text": "npm:^2.0.0"
"@xmtp/node-bindings": "npm:^0.0.29"
"@xmtp/node-bindings": "npm:^0.0.30"
"@xmtp/proto": "npm:^3.72.3"
"@xmtp/xmtp-js": "workspace:^"
fast-glob: "npm:^3.3.2"
Expand Down Expand Up @@ -5256,10 +5256,10 @@ __metadata:
languageName: node
linkType: hard

"@xmtp/wasm-bindings@npm:^0.0.8":
version: 0.0.8
resolution: "@xmtp/wasm-bindings@npm:0.0.8"
checksum: 10/6020c15b56d3ac02fc76d86bb176c2504f1976aec7af2ae7f3aea7e159f2692db08c0d5501462f8ea4fb34530cacbd2568a3870d0a7b8189db33e7e7a49a9711
"@xmtp/wasm-bindings@npm:^0.0.9":
version: 0.0.9
resolution: "@xmtp/wasm-bindings@npm:0.0.9"
checksum: 10/02cb19cf4b610b040a52e48b324e712a84b6278834c68ce0f0f7d033a00e2188b58cc75c69a30c0b908505921cd9ef354bce51528105267141320378681280d1
languageName: node
linkType: hard

Expand Down
Loading