From f0cd6c3ddeea2cbb72cd49299a334dc13abb0b66 Mon Sep 17 00:00:00 2001 From: Altay Date: Mon, 11 Dec 2023 18:33:22 +0300 Subject: [PATCH] feat: update supabase types (#12) * feat: update supabase types * feat: create utility types for supabase * chore: update supabase types --- .eslintignore | 1 + lib/services/supabase/auth.ts | 2 +- lib/services/supabase/browser.ts | 2 +- lib/services/supabase/server.ts | 2 +- lib/services/supabase/service.ts | 2 +- package.json | 3 +- pnpm-lock.yaml | 89 +++++ .../database-generated.ts} | 342 +++++++++--------- types/supabase/database.ts | 6 + 9 files changed, 275 insertions(+), 174 deletions(-) create mode 100644 .eslintignore rename types/{database.ts => supabase/database-generated.ts} (72%) create mode 100644 types/supabase/database.ts diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..64dba6c --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +types diff --git a/lib/services/supabase/auth.ts b/lib/services/supabase/auth.ts index 89b4a88..4c354ab 100644 --- a/lib/services/supabase/auth.ts +++ b/lib/services/supabase/auth.ts @@ -1,4 +1,4 @@ -import type { Database } from '@/types/database'; +import type { Database } from '@/types/supabase/database'; import type { CookieOptions } from '@supabase/ssr'; import type { NextRequest } from 'next/server'; diff --git a/lib/services/supabase/browser.ts b/lib/services/supabase/browser.ts index dbcd75e..6a45f10 100644 --- a/lib/services/supabase/browser.ts +++ b/lib/services/supabase/browser.ts @@ -1,5 +1,5 @@ 'use client'; -import type { Database } from '@/types/database'; +import type { Database } from '@/types/supabase/database'; import { env } from '@/env.mjs'; import { createBrowserClient } from '@supabase/ssr'; diff --git a/lib/services/supabase/server.ts b/lib/services/supabase/server.ts index 92e5c46..998db50 100644 --- a/lib/services/supabase/server.ts +++ b/lib/services/supabase/server.ts @@ -1,4 +1,4 @@ -import type { Database } from '@/types/database'; +import type { Database } from '@/types/supabase/database'; import type { CookieOptions } from '@supabase/ssr'; import type { cookies } from 'next/headers'; diff --git a/lib/services/supabase/service.ts b/lib/services/supabase/service.ts index 348ba40..9e1b828 100644 --- a/lib/services/supabase/service.ts +++ b/lib/services/supabase/service.ts @@ -1,4 +1,4 @@ -import type { Database } from '@/types/database'; +import type { Database } from '@/types/supabase/database'; import { env } from '@/env.mjs'; import { createClient } from '@supabase/supabase-js'; diff --git a/package.json b/package.json index e39013d..fab3e4a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start": "next start", "storybook": "storybook dev -p 6006", "supabase:login": "supabase login", - "supabase:types": "supabase gen types typescript --project-id zcetythxtznisfgaakyk > types/database.ts", + "supabase:types": "supabase gen types typescript --project-id zcetythxtznisfgaakyk > types/supabase/database-generated.ts", "typecheck": "tsc --noEmit" }, "prettier": "@vercel/style-guide/prettier", @@ -50,6 +50,7 @@ "lint-staged": "^15.2.0", "prettier": "^3.1.0", "storybook": "^7.6.4", + "supabase": "^1.115.5", "typescript": "^5" }, "packageManager": "pnpm@8.12.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4d10da5..713953b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -100,6 +100,9 @@ devDependencies: storybook: specifier: ^7.6.4 version: 7.6.4 + supabase: + specifier: ^1.115.5 + version: 1.115.5 typescript: specifier: ^5 version: 5.3.3 @@ -5877,6 +5880,16 @@ packages: resolution: {integrity: sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==} dev: true + /bin-links@4.0.3: + resolution: {integrity: sha512-obsRaULtJurnfox/MDwgq6Yo9kzbv1CPTk/1/s7Z/61Lezc8IKkFCOXNeVLXz0456WRzBQmSsDWlai2tIhBsfA==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dependencies: + cmd-shim: 6.0.2 + npm-normalize-package-bin: 3.0.1 + read-cmd-shim: 4.0.0 + write-file-atomic: 5.0.1 + dev: true + /binary-extensions@2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} engines: {node: '>=8'} @@ -6309,6 +6322,11 @@ packages: engines: {node: '>=0.8'} dev: true + /cmd-shim@6.0.2: + resolution: {integrity: sha512-+FFYbB0YLaAkhkcrjkyNLYDiOsFSfRjwjY19LXk/psmMx1z00xlCv7hhQoTGXXIKi+YXHL/iiFo8NqMVQX9nOw==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dev: true + /color-convert@1.9.3: resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} dependencies: @@ -6652,6 +6670,11 @@ packages: engines: {node: '>=8'} dev: true + /data-uri-to-buffer@4.0.1: + resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==} + engines: {node: '>= 12'} + dev: true + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -7906,6 +7929,14 @@ packages: pend: 1.2.0 dev: true + /fetch-blob@3.2.0: + resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} + engines: {node: ^12.20 || >= 14.13} + dependencies: + node-domexception: 1.0.0 + web-streams-polyfill: 3.2.1 + dev: true + /fetch-retry@5.0.6: resolution: {integrity: sha512-3yurQZ2hD9VISAhJJP9bpYFNQrHHBXE2JxxjY5aLEcDi46RmAzJE2OC9FAde0yis5ElW0jTTzs0zfg/Cca4XqQ==} dev: true @@ -8078,6 +8109,13 @@ packages: mime-types: 2.1.35 dev: true + /formdata-polyfill@4.0.10: + resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} + engines: {node: '>=12.20.0'} + dependencies: + fetch-blob: 3.2.0 + dev: true + /forwarded@0.2.0: resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} engines: {node: '>= 0.6'} @@ -9907,6 +9945,11 @@ packages: minimatch: 3.1.2 dev: true + /node-domexception@1.0.0: + resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} + engines: {node: '>=10.5.0'} + dev: true + /node-fetch-native@1.4.1: resolution: {integrity: sha512-NsXBU0UgBxo2rQLOeWNZqS3fvflWePMECr8CoSWoSTqCqGbVVsvl9vZu1HfQicYN0g5piV9Gh8RTEvo/uP752w==} dev: true @@ -9923,6 +9966,15 @@ packages: whatwg-url: 5.0.0 dev: true + /node-fetch@3.3.2: + resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + data-uri-to-buffer: 4.0.1 + fetch-blob: 3.2.0 + formdata-polyfill: 4.0.10 + dev: true + /node-int64@0.4.0: resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} dev: true @@ -9988,6 +10040,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /npm-normalize-package-bin@3.0.1: + resolution: {integrity: sha512-dMxCf+zZ+3zeQZXKxmyuCKlIDPGuv8EF940xbkC4kQVDTtqoh6rJFO+JTKSA6/Rwi0getWmtuy4Itup0AMcaDQ==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dev: true + /npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -10916,6 +10973,11 @@ packages: dependencies: loose-envify: 1.4.0 + /read-cmd-shim@4.0.0: + resolution: {integrity: sha512-yILWifhaSEEytfXI76kB9xEEiG1AiozaCJZ83A87ytjRiN+jVibXjedjCRNjoZviinhG+4UkalO3mWTd8u5O0Q==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dev: true + /read-pkg-up@7.0.1: resolution: {integrity: sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==} engines: {node: '>=8'} @@ -11819,6 +11881,20 @@ packages: client-only: 0.0.1 react: 18.2.0 + /supabase@1.115.5: + resolution: {integrity: sha512-jAJ/d3Dge1/mV284RHBp6dkGLJCmdMO3FE6hnyn1S1Si3Bx4/EUD3zXtkkSNs4lAx6jcyibwh3iULm6n4yFzZA==} + engines: {npm: '>=8'} + hasBin: true + requiresBuild: true + dependencies: + bin-links: 4.0.3 + https-proxy-agent: 7.0.2 + node-fetch: 3.3.2 + tar: 6.2.0 + transitivePeerDependencies: + - supports-color + dev: true + /supports-color@5.5.0: resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==} engines: {node: '>=4'} @@ -12475,6 +12551,11 @@ packages: defaults: 1.0.4 dev: true + /web-streams-polyfill@3.2.1: + resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==} + engines: {node: '>= 8'} + dev: true + /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} @@ -12669,6 +12750,14 @@ packages: signal-exit: 3.0.7 dev: true + /write-file-atomic@5.0.1: + resolution: {integrity: sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dependencies: + imurmurhash: 0.1.4 + signal-exit: 4.1.0 + dev: true + /ws@6.2.2: resolution: {integrity: sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==} peerDependencies: diff --git a/types/database.ts b/types/supabase/database-generated.ts similarity index 72% rename from types/database.ts rename to types/supabase/database-generated.ts index 07dbe5a..c64b275 100644 --- a/types/database.ts +++ b/types/supabase/database-generated.ts @@ -1,140 +1,187 @@ export type Json = - | { [key: string]: Json | undefined } - | Json[] + | string + | number | boolean | null - | number - | string; + | { [key: string]: Json | undefined } + | Json[]; -export type Database = { +export interface Database { public: { - CompositeTypes: { - [_ in never]: never; - }; - Enums: { - [_ in never]: never; - }; - Functions: { - [_ in never]: never; - }; Tables: { - episode: { + account: { + Row: { + ai_credit: number | null; + avatar_url: string | null; + created_at: string; + display_name: string | null; + id: number; + provider_refresh_token: string | null; + provider_token: string; + spotify_id: string; + user_id: string; + }; Insert: { - audio_url: string; + ai_credit?: number | null; + avatar_url?: string | null; created_at?: string; - description?: null | string; - duration: number; - episode_number: number; + display_name?: string | null; id?: number; - images?: null | string[]; - podcast_index_guid: string; + provider_refresh_token?: string | null; + provider_token: string; + spotify_id: string; + user_id: string; + }; + Update: { + ai_credit?: number | null; + avatar_url?: string | null; + created_at?: string; + display_name?: string | null; + id?: number; + provider_refresh_token?: string | null; + provider_token?: string; + spotify_id?: string; + user_id?: string; + }; + Relationships: [ + { + foreignKeyName: 'account_user_fkey'; + columns: ['user_id']; + isOneToOne: false; + referencedRelation: 'users'; + referencedColumns: ['id']; + }, + { + foreignKeyName: 'account_user_id_fkey'; + columns: ['user_id']; + isOneToOne: false; + referencedRelation: 'users'; + referencedColumns: ['id']; + }, + ]; + }; + account_show_relation: { + Row: { + account: number; + created_at: string; + id: number; show: number; - size?: null | number; - title: string; + }; + Insert: { + account: number; + created_at?: string; + id?: number; + show: number; + }; + Update: { + account?: number; + created_at?: string; + id?: number; + show?: number; }; Relationships: [ { - columns: ['show']; - foreignKeyName: 'episode_show_fkey'; + foreignKeyName: 'account_show_relation_account_fkey'; + columns: ['account']; isOneToOne: false; + referencedRelation: 'account'; referencedColumns: ['id']; + }, + { + foreignKeyName: 'account_show_relation_show_fkey'; + columns: ['show']; + isOneToOne: false; referencedRelation: 'show'; + referencedColumns: ['id']; }, ]; + }; + episode: { Row: { audio_url: string; created_at: string; - description: null | string; + description: string | null; duration: number; episode_number: number; id: number; - images: null | string[]; + images: string[] | null; podcast_index_guid: string; show: number; - size: null | number; + size: number | null; + title: string; + }; + Insert: { + audio_url: string; + created_at?: string; + description?: string | null; + duration: number; + episode_number: number; + id?: number; + images?: string[] | null; + podcast_index_guid: string; + show: number; + size?: number | null; title: string; }; Update: { audio_url?: string; created_at?: string; - description?: null | string; + description?: string | null; duration?: number; episode_number?: number; id?: number; - images?: null | string[]; + images?: string[] | null; podcast_index_guid?: string; show?: number; - size?: null | number; + size?: number | null; title?: string; }; - }; - episode_content: { - Insert: { - created_at?: string; - episode: number; - id?: number; - text_summary?: null | string; - transcription?: null | string; - user: number; - }; Relationships: [ { - columns: ['episode']; - foreignKeyName: 'episode_content_episode_fkey'; - isOneToOne: false; - referencedColumns: ['id']; - referencedRelation: 'episode'; - }, - { - columns: ['user']; - foreignKeyName: 'episode_content_user_fkey'; + foreignKeyName: 'episode_show_fkey'; + columns: ['show']; isOneToOne: false; + referencedRelation: 'show'; referencedColumns: ['id']; - referencedRelation: 'user'; }, ]; + }; + episode_content: { Row: { created_at: string; episode: number; id: number; - text_summary: null | string; - transcription: null | string; + text_summary: string | null; + transcription: string | null; user: number; }; - Update: { - created_at?: string; - episode?: number; - id?: number; - text_summary?: null | string; - transcription?: null | string; - user?: number; - }; - }; - episode_progress: { Insert: { - at: number; created_at?: string; episode: number; - finished?: boolean; id?: number; + text_summary?: string | null; + transcription?: string | null; user: number; }; + Update: { + created_at?: string; + episode?: number; + id?: number; + text_summary?: string | null; + transcription?: string | null; + user?: number; + }; Relationships: [ { + foreignKeyName: 'episode_content_episode_fkey'; columns: ['episode']; - foreignKeyName: 'episode_progress_episode_fkey'; isOneToOne: false; - referencedColumns: ['id']; referencedRelation: 'episode'; - }, - { - columns: ['user']; - foreignKeyName: 'episode_progress_user_fkey'; - isOneToOne: false; referencedColumns: ['id']; - referencedRelation: 'user'; }, ]; + }; + episode_progress: { Row: { at: number; created_at: string; @@ -143,6 +190,14 @@ export type Database = { id: number; user: number; }; + Insert: { + at: number; + created_at?: string; + episode: number; + finished?: boolean; + id?: number; + user: number; + }; Update: { at?: number; created_at?: string; @@ -151,126 +206,75 @@ export type Database = { id?: number; user?: number; }; + Relationships: [ + { + foreignKeyName: 'episode_progress_episode_fkey'; + columns: ['episode']; + isOneToOne: false; + referencedRelation: 'episode'; + referencedColumns: ['id']; + }, + ]; }; show: { - Insert: { - created_at?: string; - description?: null | string; - id?: number; - images?: null | string[]; - language?: null | string; + Row: { + created_at: string; + description: string | null; + id: number; + images: string[] | null; + language: string | null; podcast_index_guid: string; publisher: string; spotify_id: string; title: string; - total_episode?: null | number; + total_episode: number | null; }; - Relationships: []; - Row: { - created_at: string; - description: null | string; - id: number; - images: null | string[]; - language: null | string; + Insert: { + created_at?: string; + description?: string | null; + id?: number; + images?: string[] | null; + language?: string | null; podcast_index_guid: string; publisher: string; spotify_id: string; title: string; - total_episode: null | number; + total_episode?: number | null; }; Update: { created_at?: string; - description?: null | string; + description?: string | null; id?: number; - images?: null | string[]; - language?: null | string; + images?: string[] | null; + language?: string | null; podcast_index_guid?: string; publisher?: string; spotify_id?: string; title?: string; - total_episode?: null | number; - }; - }; - user: { - Insert: { - ai_credit?: null | number; - avatar?: null | string; - created_at?: string; - email?: null | string; - id?: number; - password?: null | string; - provider_token?: null | string; - username?: null | string; + total_episode?: number | null; }; Relationships: []; - Row: { - ai_credit: null | number; - avatar: null | string; - created_at: string; - email: null | string; - id: number; - password: null | string; - provider_token: null | string; - username: null | string; - }; - Update: { - ai_credit?: null | number; - avatar?: null | string; - created_at?: string; - email?: null | string; - id?: number; - password?: null | string; - provider_token?: null | string; - username?: null | string; - }; - }; - user_show_relation: { - Insert: { - created_at?: string; - id?: number; - show: number; - user: number; - }; - Relationships: [ - { - columns: ['show']; - foreignKeyName: 'user_show_relation_show_fkey'; - isOneToOne: false; - referencedColumns: ['id']; - referencedRelation: 'show'; - }, - { - columns: ['user']; - foreignKeyName: 'user_show_relation_user_fkey'; - isOneToOne: false; - referencedColumns: ['id']; - referencedRelation: 'user'; - }, - ]; - Row: { - created_at: string; - id: number; - show: number; - user: number; - }; - Update: { - created_at?: string; - id?: number; - show?: number; - user?: number; - }; }; }; Views: { [_ in never]: never; }; + Functions: { + [_ in never]: never; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; }; -}; +} export type Tables< PublicTableNameOrOptions extends - | { schema: keyof Database } - | keyof (Database['public']['Tables'] & Database['public']['Views']), + | keyof (Database['public']['Tables'] & Database['public']['Views']) + | { schema: keyof Database }, TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof (Database[PublicTableNameOrOptions['schema']]['Tables'] & Database[PublicTableNameOrOptions['schema']]['Views']) @@ -294,8 +298,8 @@ export type Tables< export type TablesInsert< PublicTableNameOrOptions extends - | { schema: keyof Database } - | keyof Database['public']['Tables'], + | keyof Database['public']['Tables'] + | { schema: keyof Database }, TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicTableNameOrOptions['schema']]['Tables'] : never = never, @@ -315,8 +319,8 @@ export type TablesInsert< export type TablesUpdate< PublicTableNameOrOptions extends - | { schema: keyof Database } - | keyof Database['public']['Tables'], + | keyof Database['public']['Tables'] + | { schema: keyof Database }, TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicTableNameOrOptions['schema']]['Tables'] : never = never, @@ -336,8 +340,8 @@ export type TablesUpdate< export type Enums< PublicEnumNameOrOptions extends - | { schema: keyof Database } - | keyof Database['public']['Enums'], + | keyof Database['public']['Enums'] + | { schema: keyof Database }, EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicEnumNameOrOptions['schema']]['Enums'] : never = never, diff --git a/types/supabase/database.ts b/types/supabase/database.ts new file mode 100644 index 0000000..8146f20 --- /dev/null +++ b/types/supabase/database.ts @@ -0,0 +1,6 @@ +import { Database as DatabaseGenerated } from './database-generated'; + +export type Database = DatabaseGenerated; + +export type Tables = + Database['public']['Tables'][T]['Row'];