Skip to content

Commit

Permalink
Fix type returned by DatabaseTable.with method
Browse files Browse the repository at this point in the history
  • Loading branch information
drogus committed Dec 13, 2023
1 parent b6cb681 commit cea5b2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/database_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export class DatabaseTable {
public static tableName: string;

public static with<T extends DatabaseTable>(
this: T,
client: SpacetimeDBClient
): ThisType<T> {
return _tableProxy<T>(this, client) as unknown as ThisType<T>;
): T {
return _tableProxy<T>(this, client) as unknown as T;
}

public static getDB(): ClientDB {
Expand Down
19 changes: 19 additions & 0 deletions tests/spacetimedb_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,23 @@ describe("SpacetimeDBClient", () => {
expect(updates[1]["oldUser"].username).toBe("jaime");
expect(updates[1]["newUser"].username).toBe("kingslayer");
});

test("Filtering works", async () => {
const client = new SpacetimeDBClient(
"ws://127.0.0.1:1234",
"db",
undefined,
"json"
);
const db = client.db;
const user1 = new User(new Identity("bobs-idenitty"), "bob");
const user2 = new User(new Identity("sallys-identity"), "sally");
const users = db.getTable("User").instances;
users.set("abc123", user1);
users.set("def456", user2);

const filteredUsers = User.with(client).filterByUsername("sally");
expect(filteredUsers).toHaveLength(1);
expect(filteredUsers[0].username).toBe("sally");
});
});

0 comments on commit cea5b2f

Please sign in to comment.