removed supabase package

Migration not complete yet
This commit is contained in:
Huakun Shen 2025-03-26 02:11:42 -04:00
parent 369ba9d500
commit 5a6e1c2397
No known key found for this signature in database
15 changed files with 31 additions and 704 deletions

View File

@ -18,7 +18,6 @@
"@formkit/auto-animate": "^0.8.2", "@formkit/auto-animate": "^0.8.2",
"@inlang/paraglide-sveltekit": "0.16.0", "@inlang/paraglide-sveltekit": "0.16.0",
"@kksh/extension": "workspace:*", "@kksh/extension": "workspace:*",
"@kksh/sdk": "^0.0.1",
"@kksh/svelte5": "^0.1.15", "@kksh/svelte5": "^0.1.15",
"@kksh/ui": "workspace:*", "@kksh/ui": "workspace:*",
"@kksh/utils": "workspace:*", "@kksh/utils": "workspace:*",

View File

@ -1,19 +1,15 @@
import { SupabaseAPI } from "@kksh/supabase/api" // import { SupabaseAPI } from "@kksh/supabase/api"
import type { Database } from "@kksh/supabase/types" // import type { Database } from "@kksh/supabase/types"
import * as sb from "@supabase/supabase-js" import * as sb from "@supabase/supabase-js"
import { SUPABASE_ANON_KEY, SUPABASE_URL } from "./constants" import { SUPABASE_ANON_KEY, SUPABASE_URL } from "./constants"
// export const supabase = createSB(SUPABASE_URL, SUPABASE_ANON_KEY) // export const supabase = createSB(SUPABASE_URL, SUPABASE_ANON_KEY)
export const supabase: sb.SupabaseClient<Database> = sb.createClient<Database>( export const supabase: sb.SupabaseClient = sb.createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
SUPABASE_URL, auth: {
SUPABASE_ANON_KEY, flowType: "pkce"
{
auth: {
flowType: "pkce"
}
} }
) })
export const storage = supabase.storage export const storage = supabase.storage
export const supabaseExtensionsStorage = supabase.storage.from("extensions") export const supabaseExtensionsStorage = supabase.storage.from("extensions")
export const supabaseAPI = new SupabaseAPI(supabase) // export const supabaseAPI = new SupabaseAPI(supabase)

View File

@ -29,6 +29,7 @@
"dependencies": { "dependencies": {
"@changesets/cli": "^2.28.1", "@changesets/cli": "^2.28.1",
"@iconify/svelte": "^4.2.0", "@iconify/svelte": "^4.2.0",
"@kksh/sdk": "^0.0.1",
"@supabase/supabase-js": "^2.49.1", "@supabase/supabase-js": "^2.49.1",
"@tauri-apps/api": "^2.3.0", "@tauri-apps/api": "^2.3.0",
"@tauri-apps/cli": "^2.3.1", "@tauri-apps/cli": "^2.3.1",

View File

@ -13,3 +13,4 @@ export { Markdown as MarkdownSchema } from "../ui/template/schema/markdown"
export * as ListSchema from "../ui/template/schema/list" export * as ListSchema from "../ui/template/schema/list"
export * as FormSchema from "../ui/template/schema/form" export * as FormSchema from "../ui/template/schema/form"
export * from "./file-transfer" export * from "./file-transfer"
export * from "./server"

View File

@ -1,9 +1,5 @@
/**
* @module @kksh/supabase/models
* This module contains some models for supabase database that cannot be code generated, such as JSON fields.
*/
import { Icon } from "@kksh/api/models"
import * as v from "valibot" import * as v from "valibot"
import { BaseIcon } from "./icon"
export enum ExtPublishSourceTypeEnum { export enum ExtPublishSourceTypeEnum {
jsr = "jsr", jsr = "jsr",
@ -32,7 +28,7 @@ export type ExtPublishMetadata = v.InferOutput<typeof ExtPublishMetadata>
/*** /***
* Correspond to `extensions` table in supabase * Correspond to `extensions` table in supabase
*/ */
export const SBExt = v.object({ export const ExtensionStoreListItem = v.object({
identifier: v.string(), identifier: v.string(),
name: v.string(), name: v.string(),
created_at: v.string(), created_at: v.string(),
@ -41,7 +37,7 @@ export const SBExt = v.object({
long_description: v.string(), long_description: v.string(),
version: v.string(), version: v.string(),
api_version: v.optional(v.string()), api_version: v.optional(v.string()),
icon: Icon icon: BaseIcon
}) })
export type SBExt = v.InferOutput<typeof SBExt> export type ExtensionStoreListItem = v.InferOutput<typeof ExtensionStoreListItem>

View File

@ -1,175 +0,0 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Caches
.cache
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store

View File

@ -1,4 +0,0 @@
```bash
export PROJECT_REF=qzehioyfmxlgkeuujwlh
npx supabase gen types --lang=typescript --project-id $PROJECT_REF --schema public > ./src/database.types.ts
```

View File

@ -1,24 +0,0 @@
{
"name": "@kksh/supabase",
"type": "module",
"scripts": {
"prepare": "bun setup.ts"
},
"exports": {
".": "./src/index.ts",
"./api": "./src/api.ts",
"./models": "./src/models.ts",
"./types": "./src/database.types.ts"
},
"dependencies": {
"@kksh/api": "workspace:*",
"@supabase/ssr": "^0.5.2",
"@supabase/supabase-js": "^2.48.0"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}

View File

@ -1,107 +0,0 @@
import type { PostgrestSingleResponse, SupabaseClient } from "@supabase/supabase-js"
import * as v from "valibot"
import type { Database, Tables } from "./database.types"
import { SBExt } from "./models"
export class SupabaseAPI {
constructor(private supabase: SupabaseClient<Database>) {}
async getExtList(): Promise<SBExt[]> {
const res = await this.supabase
.from("extensions")
.select(
"identifier, version, api_version, name, downloads, short_description, long_description, icon, created_at"
)
.order("downloads", { ascending: false })
.select()
const dbExts: Tables<"extensions">[] = res.data ?? []
return dbExts
.map((x) => {
const parsedNode = v.safeParse(SBExt, x)
if (!parsedNode.success) {
console.error(`Fail to parse extension`, x)
console.warn(parsedNode.issues)
console.error(v.flatten(parsedNode.issues))
}
return parsedNode.success ? v.parse(SBExt, parsedNode.output) : null
})
.filter((x) => x !== null)
}
async getLatestExtPublish(
identifier: string
): Promise<PostgrestSingleResponse<Tables<"ext_publish">>> {
return this.supabase
.from("ext_publish")
.select(
"created_at, name, version, manifest, shasum, size, tarball_path, cmd_count, identifier, downloads, demo_images, api_version, metadata"
)
.order("created_at", { ascending: false })
.eq("identifier", identifier)
.select()
.limit(1)
.single()
}
getExtension(identifier: string) {
return this.supabase
.from("extensions")
.select("*")
.eq("identifier", identifier)
.limit(1)
.single()
}
async incrementDownloads({
identifier,
version
}: {
identifier: string
version: string
}): Promise<{ downloads: number }> {
return this.supabase.functions
.invoke("increment-downloads", {
body: { identifier, version }
})
.then(({ data, error }) => {
if (error) {
throw error
}
const parsed = v.safeParse(
v.object({
downloads: v.number()
}),
data
)
if (!parsed.success) {
throw new Error("Fail to parse increment downloads response")
}
return parsed.output
})
}
async publishExtFromJSR(payload: {
scope: string
version: string
name: string
}): Promise<void> {
return this.supabase.functions
.invoke("publish-jsr-ext", {
body: payload
})
.then(async ({ data, error }) => {
if (data && data.isValid) {
return
}
if (error?.name === "FunctionsHttpError") {
const errorMessage = await error.context.json()
throw new Error(errorMessage.error)
} else {
throw new Error(`Unknown error: ${error?.message}`)
}
})
}
translateExtensionFilePathToUrl(tarballPath: string): string {
return this.supabase.storage.from("extensions").getPublicUrl(tarballPath).data.publicUrl
}
}

View File

@ -1,335 +0,0 @@
export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[]
export type Database = {
public: {
Tables: {
cache: {
Row: {
created_at: string
data: Json | null
expiry_date: string | null
id: number
key: string
}
Insert: {
created_at?: string
data?: Json | null
expiry_date?: string | null
id?: number
key: string
}
Update: {
created_at?: string
data?: Json | null
expiry_date?: string | null
id?: number
key?: string
}
Relationships: []
}
events: {
Row: {
created_at: string
data: Json | null
event_type: Database["public"]["Enums"]["event_type"]
id: number
ip: string
}
Insert: {
created_at?: string
data?: Json | null
event_type: Database["public"]["Enums"]["event_type"]
id?: number
ip: string
}
Update: {
created_at?: string
data?: Json | null
event_type?: Database["public"]["Enums"]["event_type"]
id?: number
ip?: string
}
Relationships: []
}
ext_images: {
Row: {
created_at: string
image_path: string
sha512: string
}
Insert: {
created_at?: string
image_path: string
sha512: string
}
Update: {
created_at?: string
image_path?: string
sha512?: string
}
Relationships: []
}
ext_publish: {
Row: {
api_version: string | null
cmd_count: number
created_at: string
demo_images: string[]
downloads: number
extension_state: Database["public"]["Enums"]["extension_state"]
id: number
identifier: string
manifest: Json
metadata: Json | null
name: string
package_json: Json | null
readme: string | null
shasum: string
tarball_path: string
tarball_size: number
unpacked_size: number | null
version: string
}
Insert: {
api_version?: string | null
cmd_count: number
created_at?: string
demo_images: string[]
downloads: number
extension_state?: Database["public"]["Enums"]["extension_state"]
id?: number
identifier: string
manifest: Json
metadata?: Json | null
name: string
package_json?: Json | null
readme?: string | null
shasum: string
tarball_path: string
tarball_size: number
unpacked_size?: number | null
version: string
}
Update: {
api_version?: string | null
cmd_count?: number
created_at?: string
demo_images?: string[]
downloads?: number
extension_state?: Database["public"]["Enums"]["extension_state"]
id?: number
identifier?: string
manifest?: Json
metadata?: Json | null
name?: string
package_json?: Json | null
readme?: string | null
shasum?: string
tarball_path?: string
tarball_size?: number
unpacked_size?: number | null
version?: string
}
Relationships: [
{
foreignKeyName: "ext_publish_identifier_fkey"
columns: ["identifier"]
isOneToOne: false
referencedRelation: "extensions"
referencedColumns: ["identifier"]
}
]
}
extensions: {
Row: {
api_version: string
author_id: string | null
created_at: string
downloads: number
icon: Json | null
identifier: string
long_description: string | null
name: string
readme: string | null
short_description: string
tarball_size: number | null
version: string
}
Insert: {
api_version: string
author_id?: string | null
created_at?: string
downloads: number
icon?: Json | null
identifier: string
long_description?: string | null
name: string
readme?: string | null
short_description: string
tarball_size?: number | null
version: string
}
Update: {
api_version?: string
author_id?: string | null
created_at?: string
downloads?: number
icon?: Json | null
identifier?: string
long_description?: string | null
name?: string
readme?: string | null
short_description?: string
tarball_size?: number | null
version?: string
}
Relationships: []
}
stargazers: {
Row: {
created_at: string
id: number
star_date: string
username: string
}
Insert: {
created_at?: string
id?: number
star_date: string
username: string
}
Update: {
created_at?: string
id?: number
star_date?: string
username?: string
}
Relationships: []
}
}
Views: {
[_ in never]: never
}
Functions: {
get_aggregated_downloads: {
Args: Record<PropertyKey, never>
Returns: {
identifier: string
total_downloads: number
}[]
}
get_aggregated_downloads_with_details: {
Args: Record<PropertyKey, never>
Returns: {
identifier: string
total_downloads: number
name: string
short_description: string
}[]
}
increment_downloads: {
Args: {
t_identifier: string
t_version: string
}
Returns: number
}
}
Enums: {
event_type: "download" | "updater" | "schema" | "nightly_schema"
extension_state: "public" | "pending" | "under_review" | "private"
}
CompositeTypes: {
[_ in never]: never
}
}
}
type PublicSchema = Database[Extract<keyof Database, "public">]
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
export type CompositeTypes<
PublicCompositeTypeNameOrOptions extends
| keyof PublicSchema["CompositeTypes"]
| { schema: keyof Database },
CompositeTypeName extends PublicCompositeTypeNameOrOptions extends {
schema: keyof Database
}
? keyof Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"]
: never = never
> = PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
? Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName]
: PublicCompositeTypeNameOrOptions extends keyof PublicSchema["CompositeTypes"]
? PublicSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions]
: never

View File

@ -1,10 +0,0 @@
import { createClient } from "@supabase/supabase-js"
import type { Database } from "./database.types"
// export function createSB(supabaseUrl: string, supabaseAnonKey: string) {
// return createClient<Database>(supabaseUrl, supabaseAnonKey, {
// auth: {
// flowType: "pkce"
// }
// })
// }

View File

@ -1,27 +0,0 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}

View File

@ -11,7 +11,6 @@
"@kksh/desktop": ["./apps/desktop"], "@kksh/desktop": ["./apps/desktop"],
"@kksh/ci/*": ["./packages/ci/*"], "@kksh/ci/*": ["./packages/ci/*"],
"@kksh/ci": ["./packages/ci"], "@kksh/ci": ["./packages/ci"],
"@kksh/supabase/*": ["./packages/supabase/*"],
"@kksh/schema/*": ["./packages/schema/*"], "@kksh/schema/*": ["./packages/schema/*"],
"@kksh/schema": ["./packages/schema"] "@kksh/schema": ["./packages/schema"]
} }

19
pnpm-lock.yaml generated
View File

@ -14,6 +14,9 @@ importers:
'@iconify/svelte': '@iconify/svelte':
specifier: ^4.2.0 specifier: ^4.2.0
version: 4.2.0(svelte@5.20.5) version: 4.2.0(svelte@5.20.5)
'@kksh/sdk':
specifier: ^0.0.1
version: 0.0.1(typescript@5.7.3)
'@supabase/supabase-js': '@supabase/supabase-js':
specifier: ^2.49.1 specifier: ^2.49.1
version: 2.49.1 version: 2.49.1
@ -338,7 +341,7 @@ importers:
version: 8.25.0(eslint@9.21.0(jiti@2.4.0))(typescript@5.6.3) version: 8.25.0(eslint@9.21.0(jiti@2.4.0))(typescript@5.6.3)
autoprefixer: autoprefixer:
specifier: ^10.4.20 specifier: ^10.4.20
version: 10.4.20(postcss@8.4.49) version: 10.4.20(postcss@8.5.3)
bits-ui: bits-ui:
specifier: 1.0.0-next.86 specifier: 1.0.0-next.86
version: 1.0.0-next.86(svelte@5.20.5) version: 1.0.0-next.86(svelte@5.20.5)
@ -14629,6 +14632,10 @@ snapshots:
dependencies: dependencies:
typescript: 5.6.3 typescript: 5.6.3
'@kksh/sdk@0.0.1(typescript@5.7.3)':
dependencies:
typescript: 5.7.3
'@kksh/svelte5@0.1.15(lucide-svelte@0.469.0(svelte@5.16.6))(svelte-sonner@0.3.28(svelte@5.16.6))(svelte@5.16.6)(sveltekit-superforms@2.23.1(@sveltejs/kit@2.15.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.16.6)(vite@6.0.7(@types/node@22.13.1)(jiti@2.4.0)(terser@5.36.0)(yaml@2.6.1)))(svelte@5.16.6)(vite@6.0.7(@types/node@22.13.1)(jiti@2.4.0)(terser@5.36.0)(yaml@2.6.1)))(@types/json-schema@7.0.15)(svelte@5.16.6)(typescript@5.7.2))(typescript@5.7.2)': '@kksh/svelte5@0.1.15(lucide-svelte@0.469.0(svelte@5.16.6))(svelte-sonner@0.3.28(svelte@5.16.6))(svelte@5.16.6)(sveltekit-superforms@2.23.1(@sveltejs/kit@2.15.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.16.6)(vite@6.0.7(@types/node@22.13.1)(jiti@2.4.0)(terser@5.36.0)(yaml@2.6.1)))(svelte@5.16.6)(vite@6.0.7(@types/node@22.13.1)(jiti@2.4.0)(terser@5.36.0)(yaml@2.6.1)))(@types/json-schema@7.0.15)(svelte@5.16.6)(typescript@5.7.2))(typescript@5.7.2)':
dependencies: dependencies:
'@tanstack/table-core': 8.21.2 '@tanstack/table-core': 8.21.2
@ -18864,6 +18871,16 @@ snapshots:
postcss: 8.5.1 postcss: 8.5.1
postcss-value-parser: 4.2.0 postcss-value-parser: 4.2.0
autoprefixer@10.4.20(postcss@8.5.3):
dependencies:
browserslist: 4.24.2
caniuse-lite: 1.0.30001676
fraction.js: 4.3.7
normalize-range: 0.1.2
picocolors: 1.1.1
postcss: 8.5.3
postcss-value-parser: 4.2.0
available-typed-arrays@1.0.7: available-typed-arrays@1.0.7:
dependencies: dependencies:
possible-typed-array-names: 1.0.0 possible-typed-array-names: 1.0.0