Skip to content

refactor: add typed helpers for Supabase join queries (#1047)#1051

Merged
sw-factory-automations merged 1 commit into
mainfrom
feat/1047-typed-supabase-join-helpers
May 12, 2026
Merged

refactor: add typed helpers for Supabase join queries (#1047)#1051
sw-factory-automations merged 1 commit into
mainfrom
feat/1047-typed-supabase-join-helpers

Conversation

@sw-factory-automations
Copy link
Copy Markdown
Collaborator

Closes #1047

What

Adds src/lib/supabase/typed-queries.ts with typed query builders and result casters for the 3 recurring Supabase join patterns. Replaces all 11 inline as unknown as casts across 10 files with calls to these centralized helpers.

How

Each join pattern is defined once with four co-located pieces:

  • Row type — TypeScript interface for the join result shape
  • Select string — the .select() argument as a constant
  • Query builder — function that calls .from().select() and returns the chainable query
  • Result caster — function that applies the as unknown as cast in one place

Call sites import the query builder (chain .eq(), .limit(), etc.) and the result caster (get typed rows back). The cast is centralized so a schema change only needs updating in one file.

Helpers added

Query builder Result caster Join pattern
membersWithProfiles asMemberProfileRows members → profiles (id, display_name, email, avatar_url)
membersWithProfileEmail asMemberProfileEmailRows members → profiles (email only)
membersWithWorkspace asMemberWorkspaceFullRows members → workspaces (*)
membersWithWorkspaceSlug asMemberWorkspaceSlugRow members → workspaces (slug)
membersWithWorkspaceSlugPersonal asMemberWorkspaceSlugPersonalRows members → workspaces (slug, is_personal)
pageVisitsWithPages asPageVisitRows page_visits → pages (title, icon, is_database)

Files changed (11 cast sites across 10 files)

  • src/lib/database.ts — 1 cast
  • src/app/(app)/[workspaceSlug]/[pageId]/page.tsx — 1 cast
  • src/app/(app)/[workspaceSlug]/page.tsx — 1 cast
  • src/app/(auth)/sign-in/sign-in-form.tsx — 1 cast
  • src/app/(auth)/sign-up/sign-up-form.tsx — 1 cast
  • src/app/auth/callback/route.ts — 1 cast
  • src/components/delete-workspace-section.tsx — 2 casts
  • src/components/members/invite-form.tsx — 1 cast
  • src/components/sidebar/workspace-switcher.tsx — 1 cast
  • src/components/database/property-types/person.tsx — 1 cast

Knowledge base updates

  • .agents/architecture.md — added typed-queries.ts to the Component Map
  • .agents/conventions.md — added "Typed join queries" pattern with usage example

Testing

  • pnpm lint — 0 errors ✅
  • pnpm typecheck — passes ✅
  • pnpm test — 139 files, 1877 tests pass ✅
  • No behavior changes — pure type-safety refactor, no new UI or interactions

Notes

Three additional Supabase join casts exist outside the issue's scope (settings/members/page.tsx × 2, page-backlinks.tsx × 1). These use different join patterns (members with * + profiles, workspace_invites with profiles, page_links with pages) and could be addressed in a follow-up.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
memo Ready Ready Preview, Comment May 12, 2026 10:17am

Request Review

@sw-factory-automations sw-factory-automations merged commit 2b23d98 into main May 12, 2026
9 checks passed
@sw-factory-automations sw-factory-automations deleted the feat/1047-typed-supabase-join-helpers branch May 12, 2026 10:32
@sw-factory-automations
Copy link
Copy Markdown
Collaborator Author

✅ Post-merge verification skipped — refactor: PRs don't affect the live app. No smoke tests needed.

@sw-factory-automations
Copy link
Copy Markdown
Collaborator Author

✅ UI verification passed — no visual changes detected.

This PR modifies src/components/* and src/app/**/page.tsx files, but all changes are limited to TypeScript imports, Supabase query builders, and type casts. No JSX, CSS classes, Tailwind utilities, or rendering logic was modified. The visual output of all affected components is identical before and after this PR.

Skipping Storybook visual regression, live site screenshots, and design spec compliance checks — not applicable for a pure type-safety refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: add typed helpers for Supabase join queries to eliminate as unknown as casts

1 participant