diff --git a/apps/web/vitest/powersync-sync-rules.test.ts b/apps/web/vitest/powersync-sync-rules.test.ts index 70b94fb2..468e2b49 100644 --- a/apps/web/vitest/powersync-sync-rules.test.ts +++ b/apps/web/vitest/powersync-sync-rules.test.ts @@ -1,17 +1,20 @@ import { readFileSync } from "node:fs"; -import { resolve } from "node:path"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; +const syncRulesPath = resolve( + dirname(fileURLToPath(import.meta.url)), + "../../../powersync/config/sync-rules.yaml" +); + function readSyncRules() { - return readFileSync( - resolve(process.cwd(), "../../powersync/config/sync-rules.yaml"), - "utf8" - ); + return readFileSync(syncRulesPath, "utf8"); } function getStreamRule(name: string) { const match = readSyncRules().match( - new RegExp(` {2}${name}:[\\s\\S]*?(?=\\n\\n {2}[a-z_]+:)`) + new RegExp(` {2}${name}:[\\s\\S]*?(?=\\n\\n {2}[a-z_]+:|\\n*$)`) ); return match?.[0] ?? ""; } @@ -39,4 +42,15 @@ describe("PowerSync sync rules", () => { "investos_notification_schedules.canceled_at IS NULL" ); }); + + it("limits synced user profiles to room peers", () => { + const rule = getStreamRule("user_profiles"); + + expect(rule.match(/FROM user_profiles/g)).toHaveLength(1); + expect(rule).toContain("INNER JOIN index_room_members AS peer_membership"); + expect(rule).toContain("INNER JOIN index_room_members AS my_membership"); + expect(rule).not.toContain( + "WHERE user_profiles.user_id::text = auth.user_id()" + ); + }); }); diff --git a/powersync/config/sync-rules.yaml b/powersync/config/sync-rules.yaml index b15a3423..b62c643e 100644 --- a/powersync/config/sync-rules.yaml +++ b/powersync/config/sync-rules.yaml @@ -436,23 +436,6 @@ streams: user_profiles: auto_subscribe: true queries: - - > - SELECT - user_profiles.id::text AS id, - user_profiles.user_id::text AS user_id, - user_profiles.photo_path, - user_profiles.username, - user_profiles.created_at::text AS created_at, - user_profiles.updated_at::text AS updated_at, - user_profiles.profile_picture_filter, - user_profiles.banner_path, - user_profiles.social_links::text AS social_links, - user_profiles.display_name, - CASE WHEN user_profiles.is_promoted THEN 1 ELSE 0 END AS is_promoted, - CASE WHEN user_profiles.is_verified THEN 1 ELSE 0 END AS is_verified, - user_profiles.expert_entity_uuid - FROM user_profiles - WHERE user_profiles.user_id::text = auth.user_id() - > SELECT user_profiles.id::text AS id,