feat: generate Supabase TypeScript types for typed database client#4658
feat: generate Supabase TypeScript types for typed database client#4658GMetaxakis wants to merge 5 commits intoONEARMY:masterfrom
Conversation
onearmy-community-platform
|
||||||||||||||||||||||||||||
| Project |
onearmy-community-platform
|
| Branch Review |
pull/4658
|
| Run status |
|
| Run duration | 06m 57s |
| Commit |
|
| Committer | Georgios Metaxakis |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
1
|
|
|
0
|
|
|
0
|
|
|
90
|
| View all changes introduced in this branch ↗︎ | |
| .from('projects') | ||
| .update({ | ||
| modified_at: new Date(), | ||
| modified_at: new Date().toISOString(), |
There was a problem hiding this comment.
does this still work, or fixes a bug?
There was a problem hiding this comment.
Still works the same — the Supabase client serializes Date objects to ISO strings internally, so the runtime behavior is unchanged. The explicit .toISOString() is needed because the typed client expects string for timestamp columns, not Date.
|
I've tried this before, adding all those casts didn't feel great.
|
|
Good points. The main wins right now are on inserts/updates and RPC calls — those get real type checking (correct column names, enum values, etc.). The read-side casts are ugly and don't add much. Let me give it a try to remove the DB types like DBProfile, DBComment, etc. and replace them with the generated types ( |
- Align DB model date types with Supabase returns (Date → string) - Create supabase.types.ts with toJson, fromJson, fromJsonArray, dbResult, dbResultArray helpers - Replace all 56 as unknown as casts in route files with helpers - Update IDBDocSB base interface and all implementing types - Fix mock data and test factories for string date types
- Move database.types.ts from src/ to shared/ (enables DB models to derive from generated types in the future) - Export Database, Tables, Json types from oa-shared package - Convert all DB model classes to interfaces (DBProfile, DBNews, DBComment, DBQuestion, DBResearchItem, DBResearchUpdate, DBProject, DBProjectStep, DBCategory, DBTag, DBProfileTag, DBProfileBadge, DBProfileType, DBMedia, DBNotification, DBMapPin, DBBanner) - Remove fake Object.assign constructors from DB types - Replace new DB*() instantiation patterns with plain object literals - Update all imports to use oa-shared instead of src/database.types - Update db:types script target path
|
Updated the PR based on feedback. Here's what changed: Eliminated all
Converted all DB model classes to interfaces:
Moved
Aligned DB date types with Supabase returns:
The |
|
great work! I need to look into this carefully |
PR Checklist
PR Type
What is the new behavior?
src/database.types.tswith generated TypeScript types for all 26 tables, 14 RPC functions, and 6 enumssupabase.server.tsis now typed withcreateServerClient<Database>(...), giving compile-time checks on table names, column names, insert/update payloads, and RPC function signaturesdb:typesscript topackage.jsonfor regenerating types from a local Supabase instance (yarn db:types)Does this PR introduce a DB Schema Change or Migration?
Git Issues
Closes #4344