supabase-type-safety

Type Supabase queries with DbRpcRow guards and JsonToUnknown wrappers.

2|1|Updated Aug 24, 2024
One-click install
npx skills add https://github.com/armanisadeghi/ai-matrx --skill supabase-type-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-type-safety
Source: https://github.com/armanisadeghi/ai-matrx/tree/main/.cursor/skills/supabase-type-safety
Command: npx skills add https://github.com/armanisadeghi/ai-matrx --skill supabase-type-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Supabase returns Json for JSONB columns, which can break strict TypeScript interfaces. This Skill provides patterns to safely type Supabase calls by guiding the use of DB shape guards and Json-to-Unknown conversions, ensuring runtime correctness.

Core Features & Use Cases

  • RPC calls with DbRpcRow guards to validate DB row shape at compile time.
  • Table queries typed via Tables to avoid Json in row data.
  • JsonToUnknown utility to safely convert Json fields to unknown for complex schemas.
  • Guidance on when not to add guards and how to cast results safely.

Quick Start

Use the supabase-type-safety skill to enforce type-safety when integrating Supabase in a TS project.

Frequently Asked Questions about supabase-type-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle Supabase JSONB columns that break TypeScript interfaces?

Supabase returns Json for JSONB columns, which breaks strict TypeScript interfaces. You can enforce runtime correctness by applying DbRpcRow guards and JsonToUnknown wrappers to safely type Supabase calls.

What is the best way to type Supabase RPC responses in TypeScript?

Type Supabase RPC responses by applying DbRpcRow guards to validate the database row shape at compile time. This pattern ensures your RPC calls return data that aligns with strict TypeScript interfaces.

How do I type Supabase table queries to avoid Json in row data?

Use precise Table Row types when querying via the supabase.from pattern to avoid Json in row data. This ensures type-safe Supabase queries that compile and align with TypeScript interfaces.

Do I need type guards for every Supabase query in my TypeScript project?

No, you do not need type guards for every Supabase query. This approach provides specific guidance on when not to add guards and how to cast results safely, preventing unnecessary overhead for simple table queries.

Why does Supabase return Json for JSONB columns and how can I enforce type safety?

Supabase returns Json for JSONB columns because the database format maps directly to generic Json. You enforce type safety by applying DbRpcRow guards, JsonToUnknown wrappers, and precise Table Row types with safe casting.