-
Notifications
You must be signed in to change notification settings - Fork 119
chore: supabase gen types #490
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
Conversation
WalkthroughThe generated TypeScript types file was updated to introduce a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
database/database-generated.types.ts (1)
2047-2126: Fixvisitor.ipnullability mismatch: column is nullable but typed as non-null.The
visitor.ipcolumn is nullable in the database ("ip" "inet"withoutNOT NULLconstraint) but currently typed asunknown(non-optional) in the Row type at line 4215. This will cause consumers to miss required null checks when accessing this field.Note:
search_tsvfields aretsvector GENERATED ALWAYS AS (...) STOREDwithcoalesce()fallbacks, so they are never NULL—the Row typing is correct. However, bothvisitor.ipandsearch_tsvare typed asunknownwhen they should have more specific types (e.g.,stringforip/search_tsv).Also applies to: 2214–2229, 2262–2277, 3764–3813, 4215–4232, 4266–4267
🤖 Fix all issues with AI agents
In @database/database-generated.types.ts:
- Around line 504-535: The RPC return types for
get_inventory_items_with_committed and get_inventory_with_committed are
incorrect: update the Returns object for both functions in
database-generated.types.ts so product_id and cost are nullable (product_id:
number | null and cost: number | null) to match the underlying inventory_item
column types; locate the Returns blocks for get_inventory_items_with_committed
and get_inventory_with_committed and change those two field types accordingly.
- Around line 4343-4366: The workspace_documents return type incorrectly marks
LEFT JOINable fields as required; update the Returns object for
workspace_documents so that form_id, organization_id, is_public, and
max_responses are optional (e.g., turn their types into possibly undefined or
add ?), leaving other fields unchanged; keep p_document_id in
workspace_mark_access as optional since it already matches the SQL DEFAULT NULL.
🧹 Nitpick comments (2)
database/database-generated.types.ts (2)
3254-3254:Args: nevercan be awkward with commonrpc(fn, args)wrappers.If your Supabase client wrapper expects an
argsobject parameter,Args: neveroften forces casts. Consider generatingArgs: Record<string, never>(or{}) instead—if compatible with your calling conventions.Also applies to: 4308-4310
4398-4513:DatabaseWithoutInternalswiring looks good; consider exporting + minor key extraction cleanup.The shift to
DatabaseWithoutInternalsin the public generic helpers is a nice way to hide internal Supabase keys. Two small polish items:
- Consider
export type DatabaseWithoutInternals = .../export type DefaultSchema = ...if you want consumers to reference them explicitly.DefaultSchemacan useExtract<keyof DatabaseWithoutInternals, "public">for consistency.Proposed diff
-type DatabaseWithoutInternals = Omit<Database, "__InternalSupabase"> +export type DatabaseWithoutInternals = Omit<Database, "__InternalSupabase"> -type DefaultSchema = DatabaseWithoutInternals[Extract<keyof Database, "public">] +export type DefaultSchema = + DatabaseWithoutInternals[Extract<keyof DatabaseWithoutInternals, "public">]
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
database/database-generated.types.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
🔇 Additional comments (3)
database/database-generated.types.ts (3)
1562-1566: RPC arg reordering / inline formatting: OK (no semantic change in TS).Object-property order changes for
Argsdon’t affect assignability; the one-line signature style is fine as long as this file is fully generator-owned.Also applies to: 1697-1699, 3586-3592
2223-2228: No action required. SetofOptions is structurally safe for all downstream uses. Searches found zero instances ofkeyof Database[...]["Functions"]or explicit key enumeration patterns that would break from the added field. TypeScript's structural typing and inference patterns already in use (likeextends { Args: infer A; Returns: infer R }) handle the new key automatically without issues.
4310-4319: Union-typed RPCgenerate_combinationsconfirmed—no wrapper issues found.The
Database["public"]["Functions"]["generate_combinations"]is correctly typed as a union of two{ Args; Returns }shapes. The codebase uses the standard Supabase client (@supabase/ssr), which handles union-typed RPCs natively via RPC name discrimination rather than type inference, so no inference degradation occurs with the current implementation.
| generate_combinations: { | ||
| Args: { options: Json; index: number; current: Json } | ||
| Args: { current: Json; index: number; options: Json } | ||
| Returns: Json | ||
| } | ||
| get_inventory_items_with_committed: { | ||
| Args: { p_store_id: number } | ||
| Returns: { | ||
| id: number | ||
| available: number | ||
| committed: number | ||
| cost: number | ||
| created_at: string | ||
| id: number | ||
| product_id: number | ||
| sku: string | ||
| store_id: number | ||
| product_id: number | ||
| variant_id: number | ||
| cost: number | ||
| available: number | ||
| committed: number | ||
| }[] | ||
| } | ||
| get_inventory_with_committed: { | ||
| Args: { p_store_id: number; p_sku: string } | ||
| Args: { p_sku: string; p_store_id: number } | ||
| Returns: { | ||
| id: number | ||
| available: number | ||
| committed: number | ||
| cost: number | ||
| created_at: string | ||
| id: number | ||
| product_id: number | ||
| sku: string | ||
| store_id: number | ||
| product_id: number | ||
| variant_id: number | ||
| cost: number | ||
| available: number | ||
| committed: number | ||
| }[] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
cd /tmp && find . -type f \( -name "*.sql" -o -name "*migration*" \) 2>/dev/null | head -20Repository: gridaco/grida
Length of output: 39
🏁 Script executed:
rg -tl sql 'get_inventory_items_with_committed|get_inventory_with_committed' --max-count=20Repository: gridaco/grida
Length of output: 82
🏁 Script executed:
rg 'create\s+(or\s+replace\s+)?function.*get_inventory.*with_committed' -A 30 -iRepository: gridaco/grida
Length of output: 5734
🏁 Script executed:
rg 'create\s+table.*inventory_item|CREATE\s+TABLE.*inventory_item' -A 50 -iRepository: gridaco/grida
Length of output: 4550
Fix nullability mismatch in inventory RPC return types.
Both get_inventory_items_with_committed and get_inventory_with_committed return product_id and cost as non-null (number), but the SQL functions select these directly from inventory_item table columns that are nullable (product_id bigint and cost double precision without NOT NULL constraints). The generated TypeScript types must reflect that these fields can be null: product_id: number | null and cost: number | null.
🤖 Prompt for AI Agents
In @database/database-generated.types.ts around lines 504 - 535, The RPC return
types for get_inventory_items_with_committed and get_inventory_with_committed
are incorrect: update the Returns object for both functions in
database-generated.types.ts so product_id and cost are nullable (product_id:
number | null and cost: number | null) to match the underlying inventory_item
column types; locate the Returns blocks for get_inventory_items_with_committed
and get_inventory_with_committed and change those two field types accordingly.
| Args: { p_organization_id: number } | ||
| Returns: { | ||
| id: string | ||
| created_at: string | ||
| updated_at: string | ||
| doctype: Database["public"]["Enums"]["doctype"] | ||
| project_id: number | ||
| title: string | ||
| form_id: string | ||
| organization_id: number | ||
| has_connection_supabase: boolean | ||
| responses: number | ||
| max_responses: number | ||
| id: string | ||
| is_public: boolean | ||
| max_responses: number | ||
| organization_id: number | ||
| project_id: number | ||
| responses: number | ||
| title: string | ||
| updated_at: string | ||
| }[] | ||
| } | ||
| workspace_mark_access: { | ||
| Args: { | ||
| p_document_id?: string | ||
| p_organization_name: string | ||
| p_project_name: string | ||
| p_document_id?: string | ||
| } | ||
| Returns: undefined | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# Search for SQL function definitions
rg -A 50 'create\s+or\s+replace\s+function\s+workspace_documents\s*\(' -S --multilineRepository: gridaco/grida
Length of output: 5189
🏁 Script executed:
# Search for SQL function definitions
rg -A 50 'create\s+or\s+replace\s+function\s+workspace_mark_access\s*\(' -S --multilineRepository: gridaco/grida
Length of output: 39
🏁 Script executed:
rg -A 30 'create\s+or\s+replace\s+function\s+workspace_mark_access' -SRepository: gridaco/grida
Length of output: 39
🏁 Script executed:
rg 'workspace_mark_access' -SRepository: gridaco/grida
Length of output: 420
🏁 Script executed:
rg -A 20 'CREATE OR REPLACE FUNCTION public.workspace_mark_access' supabase/schemas/project.sqlRepository: gridaco/grida
Length of output: 649
🏁 Script executed:
rg -A 20 'CREATE OR REPLACE FUNCTION public.workspace_mark_access' supabase/migrations/20250418155207_user_project_access_state.sqlRepository: gridaco/grida
Length of output: 649
workspace_documents return fields from LEFT JOINs should be optional in TypeScript.
Fields that can return NULL due to LEFT JOINs (form_id, organization_id, is_public, max_responses) are typed as required. Update to mark these as optional.
workspace_mark_access.p_document_id is correctly optional in TypeScript and matches the SQL definition (DEFAULT NULL).
🤖 Prompt for AI Agents
In @database/database-generated.types.ts around lines 4343 - 4366, The
workspace_documents return type incorrectly marks LEFT JOINable fields as
required; update the Returns object for workspace_documents so that form_id,
organization_id, is_public, and max_responses are optional (e.g., turn their
types into possibly undefined or add ?), leaving other fields unchanged; keep
p_document_id in workspace_mark_access as optional since it already matches the
SQL DEFAULT NULL.
regular, non breaking local type sync (prep PR)
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.