diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 830265f..982388a 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -18,7 +18,6 @@ "@formkit/auto-animate": "^0.8.2", "@inlang/paraglide-sveltekit": "0.16.0", "@kksh/extension": "workspace:*", - "@kksh/sdk": "^0.0.1", "@kksh/svelte5": "^0.1.15", "@kksh/ui": "workspace:*", "@kksh/utils": "workspace:*", diff --git a/apps/desktop/src/lib/supabase.ts b/apps/desktop/src/lib/supabase.ts index 19c62d4..9cf8e37 100644 --- a/apps/desktop/src/lib/supabase.ts +++ b/apps/desktop/src/lib/supabase.ts @@ -1,19 +1,15 @@ -import { SupabaseAPI } from "@kksh/supabase/api" -import type { Database } from "@kksh/supabase/types" +// import { SupabaseAPI } from "@kksh/supabase/api" +// import type { Database } from "@kksh/supabase/types" import * as sb from "@supabase/supabase-js" import { SUPABASE_ANON_KEY, SUPABASE_URL } from "./constants" // export const supabase = createSB(SUPABASE_URL, SUPABASE_ANON_KEY) -export const supabase: sb.SupabaseClient = sb.createClient( - SUPABASE_URL, - SUPABASE_ANON_KEY, - { - auth: { - flowType: "pkce" - } +export const supabase: sb.SupabaseClient = sb.createClient(SUPABASE_URL, SUPABASE_ANON_KEY, { + auth: { + flowType: "pkce" } -) +}) export const storage = supabase.storage export const supabaseExtensionsStorage = supabase.storage.from("extensions") -export const supabaseAPI = new SupabaseAPI(supabase) +// export const supabaseAPI = new SupabaseAPI(supabase) diff --git a/package.json b/package.json index 10b036c..6235cba 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "dependencies": { "@changesets/cli": "^2.28.1", "@iconify/svelte": "^4.2.0", + "@kksh/sdk": "^0.0.1", "@supabase/supabase-js": "^2.49.1", "@tauri-apps/api": "^2.3.0", "@tauri-apps/cli": "^2.3.1", diff --git a/packages/api/src/models/index.ts b/packages/api/src/models/index.ts index 9c76e45..471f291 100644 --- a/packages/api/src/models/index.ts +++ b/packages/api/src/models/index.ts @@ -13,3 +13,4 @@ export { Markdown as MarkdownSchema } from "../ui/template/schema/markdown" export * as ListSchema from "../ui/template/schema/list" export * as FormSchema from "../ui/template/schema/form" export * from "./file-transfer" +export * from "./server" diff --git a/packages/supabase/src/models.ts b/packages/api/src/models/server.ts similarity index 80% rename from packages/supabase/src/models.ts rename to packages/api/src/models/server.ts index 8f8a6cc..13d5e91 100644 --- a/packages/supabase/src/models.ts +++ b/packages/api/src/models/server.ts @@ -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 { BaseIcon } from "./icon" export enum ExtPublishSourceTypeEnum { jsr = "jsr", @@ -32,7 +28,7 @@ export type ExtPublishMetadata = v.InferOutput /*** * Correspond to `extensions` table in supabase */ -export const SBExt = v.object({ +export const ExtensionStoreListItem = v.object({ identifier: v.string(), name: v.string(), created_at: v.string(), @@ -41,7 +37,7 @@ export const SBExt = v.object({ long_description: v.string(), version: v.string(), api_version: v.optional(v.string()), - icon: Icon + icon: BaseIcon }) -export type SBExt = v.InferOutput +export type ExtensionStoreListItem = v.InferOutput diff --git a/packages/supabase/.gitignore b/packages/supabase/.gitignore deleted file mode 100644 index 9b1ee42..0000000 --- a/packages/supabase/.gitignore +++ /dev/null @@ -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 diff --git a/packages/supabase/README.md b/packages/supabase/README.md deleted file mode 100644 index 72503d0..0000000 --- a/packages/supabase/README.md +++ /dev/null @@ -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 -``` diff --git a/packages/supabase/package.json b/packages/supabase/package.json deleted file mode 100644 index 35f1be8..0000000 --- a/packages/supabase/package.json +++ /dev/null @@ -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" - } -} diff --git a/packages/supabase/setup.ts b/packages/supabase/setup.ts deleted file mode 100644 index e69de29..0000000 diff --git a/packages/supabase/src/api.ts b/packages/supabase/src/api.ts deleted file mode 100644 index 710d378..0000000 --- a/packages/supabase/src/api.ts +++ /dev/null @@ -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) {} - async getExtList(): Promise { - 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>> { - 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 { - 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 - } -} diff --git a/packages/supabase/src/database.types.ts b/packages/supabase/src/database.types.ts deleted file mode 100644 index 8cd7968..0000000 --- a/packages/supabase/src/database.types.ts +++ /dev/null @@ -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 - Returns: { - identifier: string - total_downloads: number - }[] - } - get_aggregated_downloads_with_details: { - Args: Record - 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] - -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 diff --git a/packages/supabase/src/index.ts b/packages/supabase/src/index.ts deleted file mode 100644 index a6cf570..0000000 --- a/packages/supabase/src/index.ts +++ /dev/null @@ -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(supabaseUrl, supabaseAnonKey, { -// auth: { -// flowType: "pkce" -// } -// }) -// } diff --git a/packages/supabase/tsconfig.json b/packages/supabase/tsconfig.json deleted file mode 100644 index 238655f..0000000 --- a/packages/supabase/tsconfig.json +++ /dev/null @@ -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 - } -} diff --git a/packages/typescript-config/path-alias.json b/packages/typescript-config/path-alias.json index 11440f1..6ee0782 100644 --- a/packages/typescript-config/path-alias.json +++ b/packages/typescript-config/path-alias.json @@ -11,7 +11,6 @@ "@kksh/desktop": ["./apps/desktop"], "@kksh/ci/*": ["./packages/ci/*"], "@kksh/ci": ["./packages/ci"], - "@kksh/supabase/*": ["./packages/supabase/*"], "@kksh/schema/*": ["./packages/schema/*"], "@kksh/schema": ["./packages/schema"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18291a2..699a96d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@iconify/svelte': specifier: ^4.2.0 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': specifier: ^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) autoprefixer: specifier: ^10.4.20 - version: 10.4.20(postcss@8.4.49) + version: 10.4.20(postcss@8.5.3) bits-ui: specifier: 1.0.0-next.86 version: 1.0.0-next.86(svelte@5.20.5) @@ -14629,6 +14632,10 @@ snapshots: dependencies: 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)': dependencies: '@tanstack/table-core': 8.21.2 @@ -18864,6 +18871,16 @@ snapshots: postcss: 8.5.1 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: dependencies: possible-typed-array-names: 1.0.0