diff --git a/packages/server/package.json b/packages/server/package.json index 9c880e9f..a3728fbb 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -43,7 +43,7 @@ "unittest:vitest": "vitest run", "unittest:playwright": "playwright-test '**/*.browsertest.ts' --runner mocha", "test": "npm run unittest:vitest && npm run unittest:playwright", - "gentypes": "./supabase.sh gen types typescript --local --schema public > ../shared/src/schema.ts", + "gentypes": "./supabase.sh gen types typescript --db-url=postgresql://postgres:postgres@localhost:54322 --schema public > ../shared/src/schema.ts", "migrate": "./supabase.sh migration new newmigation_file", "diff": "./supabase.sh db diff", "lint": "eslint src" diff --git a/packages/shared/src/schema.ts b/packages/shared/src/schema.ts index 7e2db58b..73e2624c 100644 --- a/packages/shared/src/schema.ts +++ b/packages/shared/src/schema.ts @@ -6,7 +6,7 @@ export type Json = | { [key: string]: Json | undefined } | Json[] -export interface Database { +export type Database = { public: { Tables: { document_permissions: { @@ -29,15 +29,17 @@ export interface Database { { foreignKeyName: "document_permissions_document_id_fkey" columns: ["document_id"] + isOneToOne: false referencedRelation: "documents" referencedColumns: ["id"] }, { foreignKeyName: "document_permissions_user_id_fkey" columns: ["user_id"] + isOneToOne: false referencedRelation: "users" referencedColumns: ["id"] - } + }, ] } document_relations: { @@ -57,15 +59,17 @@ export interface Database { { foreignKeyName: "document_relations_child_id_fkey" columns: ["child_id"] + isOneToOne: false referencedRelation: "documents" referencedColumns: ["id"] }, { foreignKeyName: "document_relations_parent_id_fkey" columns: ["parent_id"] + isOneToOne: false referencedRelation: "documents" referencedColumns: ["id"] - } + }, ] } documents: { @@ -100,9 +104,10 @@ export interface Database { { foreignKeyName: "documents_user_id_fkey" columns: ["user_id"] + isOneToOne: false referencedRelation: "users" referencedColumns: ["id"] - } + }, ] } workspaces: { @@ -134,15 +139,17 @@ export interface Database { { foreignKeyName: "workspaces_document_nano_id_fkey" columns: ["document_nano_id"] + isOneToOne: false referencedRelation: "documents" referencedColumns: ["nano_id"] }, { foreignKeyName: "workspaces_owner_user_id_fkey" columns: ["owner_user_id"] + isOneToOne: false referencedRelation: "users" referencedColumns: ["id"] - } + }, ] } } @@ -167,3 +174,85 @@ export interface Database { } } +type PublicSchema = Database[Extract] + +export type Tables< + PublicTableNameOrOptions extends + | keyof (PublicSchema["Tables"] & PublicSchema["Views"]) + | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] & + Database[PublicTableNameOrOptions["schema"]]["Views"]) + : never = never, +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? (Database[PublicTableNameOrOptions["schema"]]["Tables"] & + Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends { + Row: infer R + } + ? R + : never + : PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & + PublicSchema["Views"]) + ? (PublicSchema["Tables"] & + PublicSchema["Views"])[PublicTableNameOrOptions] extends { + Row: infer R + } + ? R + : never + : never + +export type TablesInsert< + PublicTableNameOrOptions extends + | keyof PublicSchema["Tables"] + | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] + : never = never, +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { + Insert: infer I + } + ? I + : never + : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] + ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { + Insert: infer I + } + ? I + : never + : never + +export type TablesUpdate< + PublicTableNameOrOptions extends + | keyof PublicSchema["Tables"] + | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] + : never = never, +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { + Update: infer U + } + ? U + : never + : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] + ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { + Update: infer U + } + ? U + : never + : never + +export type Enums< + PublicEnumNameOrOptions extends + | keyof PublicSchema["Enums"] + | { schema: keyof Database }, + EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database } + ? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"] + : never = never, +> = PublicEnumNameOrOptions extends { schema: keyof Database } + ? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName] + : PublicEnumNameOrOptions extends keyof PublicSchema["Enums"] + ? PublicSchema["Enums"][PublicEnumNameOrOptions] + : never +