From 48e2e47f9697a040dc71c9e97fb486e2dbcae1b3 Mon Sep 17 00:00:00 2001 From: Huakun Date: Wed, 26 Mar 2025 08:50:55 -0400 Subject: [PATCH] Remove supabase (#263) * remove supabase package * upgrade valibot * removed supabase package Migration not complete yet * update submodule * fixed some supabase errors * Add new fields to extension models - Added `id` field to `ExtPublish` - Expanded `DBExtension` with multiple new properties: - `api_version`, `author_id`, `created_at`, - `downloads`, `icon`, `identifier`, - `long_description`, `name`, - `readme`, `short_description`, - and `tarball_size` * Refactor: clean up unused Supabase imports - Removed commented-out Supabase imports from various files to streamline the codebase. - Updated `created_at` type in `ExtPublish` model from `date` to `string` for consistency. * update icon enum to union * fix type errors after removing supabase * format * more types fixed * feat: enhance command handling and update SDK version --- .changeset/config.json | 2 - apps/cli/package.json | 2 +- apps/create-kunkun/package.json | 2 +- apps/desktop/dev.ts | 13 + apps/desktop/package.json | 1 - apps/desktop/src/lib/cmds/index.ts | 2 +- apps/desktop/src/lib/context/appConfig.ts | 6 +- apps/desktop/src/lib/context/appState.ts | 2 +- apps/desktop/src/lib/stores/apps.ts | 2 +- apps/desktop/src/lib/stores/quick-links.ts | 2 +- apps/desktop/src/lib/supabase.ts | 16 +- apps/desktop/src/lib/utils/updater.ts | 27 +- .../routes/app/extension/store/+page.svelte | 71 ++-- .../src/routes/app/extension/store/+page.ts | 32 +- .../extension/store/[identifier]/+page.svelte | 43 +-- .../app/extension/store/[identifier]/+page.ts | 62 ++-- .../extension/store/[identifier]/helper.ts | 18 +- apps/desktop/tsconfig.json | 3 +- package.json | 4 +- packages/api/package.json | 2 +- packages/api/src/models/extension.ts | 127 +++---- packages/api/src/models/icon.ts | 21 +- packages/api/src/models/index.ts | 1 + packages/api/src/models/manifest.ts | 41 +-- packages/api/src/models/server.ts | 91 +++++ packages/extension/package.json | 8 +- packages/extension/src/install.ts | 5 +- packages/extension/src/window.ts | 6 +- packages/schema/package.json | 6 +- .../scripts/upload-schema-to-supabase.ts | 3 +- packages/supabase/.gitignore | 175 --------- packages/supabase/README.md | 4 - packages/supabase/package.json | 24 -- packages/supabase/setup.ts | 0 packages/supabase/src/api.ts | 107 ------ packages/supabase/src/database.types.ts | 335 ------------------ packages/supabase/src/index.ts | 10 - packages/supabase/src/models.ts | 47 --- packages/supabase/tsconfig.json | 27 -- packages/tauri-plugins/jarvis/package.json | 1 - packages/tauri-plugins/jarvis/setup.ts | 3 +- packages/typescript-config/path-alias.json | 2 - packages/ui/package.json | 3 +- .../components/common/PlatformsIcons.svelte | 4 +- .../components/extension/ExtListItem.svelte | 5 +- .../extension/PermissionInspector.svelte | 8 +- .../extension/StoreExtDetail.svelte | 23 +- pnpm-lock.yaml | 230 +++++------- vendors/tauri-plugin-network | 2 +- vendors/tauri-plugin-user-input | 2 +- 50 files changed, 472 insertions(+), 1161 deletions(-) create mode 100644 apps/desktop/dev.ts create mode 100644 packages/api/src/models/server.ts delete mode 100644 packages/supabase/.gitignore delete mode 100644 packages/supabase/README.md delete mode 100644 packages/supabase/package.json delete mode 100644 packages/supabase/setup.ts delete mode 100644 packages/supabase/src/api.ts delete mode 100644 packages/supabase/src/database.types.ts delete mode 100644 packages/supabase/src/index.ts delete mode 100644 packages/supabase/src/models.ts delete mode 100644 packages/supabase/tsconfig.json diff --git a/.changeset/config.json b/.changeset/config.json index ee081b1..7fb5f45 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -11,11 +11,9 @@ "jarvis", "form-view", "@kksh/desktop", - "@kksh/supabase", "@kksh/utils", "@kksh/extension", "@kksh/schema", - "@kksh/supabase", "@kksh/ui" ] } diff --git a/apps/cli/package.json b/apps/cli/package.json index f7311f5..4dd050b 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -31,7 +31,7 @@ "debug": "^4.4.0", "fs-extra": "^11.2.0", "inquirer": "^10.1.2", - "valibot": "^1.0.0-rc.4" + "valibot": "^1.0.0" }, "files": [ "dist" diff --git a/apps/create-kunkun/package.json b/apps/create-kunkun/package.json index 7c1a90d..473e6de 100644 --- a/apps/create-kunkun/package.json +++ b/apps/create-kunkun/package.json @@ -27,7 +27,7 @@ "commander": "^12.1.0", "fs-extra": "^11.2.0", "handlebars": "^4.7.8", - "valibot": "^1.0.0-rc.4" + "valibot": "^1.0.0" }, "files": [ "dist" diff --git a/apps/desktop/dev.ts b/apps/desktop/dev.ts new file mode 100644 index 0000000..174ad49 --- /dev/null +++ b/apps/desktop/dev.ts @@ -0,0 +1,13 @@ +import { IconType } from "@kksh/api/models" +import { getExtensionsLatestPublishByIdentifier } from "@kksh/sdk" + +const latestPublish = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: "RAG1" + } +}) +console.log(latestPublish) +// latestPublish + +// console.log(typeof IconEnum.Iconify) +console.log(IconType.options) diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 5e2ed15..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/supabase": "workspace:*", "@kksh/svelte5": "^0.1.15", "@kksh/ui": "workspace:*", "@kksh/utils": "workspace:*", diff --git a/apps/desktop/src/lib/cmds/index.ts b/apps/desktop/src/lib/cmds/index.ts index 8e43019..3a77a98 100644 --- a/apps/desktop/src/lib/cmds/index.ts +++ b/apps/desktop/src/lib/cmds/index.ts @@ -12,7 +12,7 @@ import { onQuickLinkSelect } from "./quick-links" const onExtCmdSelect: OnExtCmdSelect = ( ext: ExtPackageJsonExtra, - cmd: CustomUiCmd | TemplateUiCmd, + cmd: CustomUiCmd | TemplateUiCmd | HeadlessCmd, { isDev, hmr }: { isDev: boolean; hmr: boolean } ) => { switch (cmd.type) { diff --git a/apps/desktop/src/lib/context/appConfig.ts b/apps/desktop/src/lib/context/appConfig.ts index 4537631..5f99a7e 100644 --- a/apps/desktop/src/lib/context/appConfig.ts +++ b/apps/desktop/src/lib/context/appConfig.ts @@ -3,16 +3,16 @@ * It's designed to allow all components to access a shared state. * With context, we can avoid prop drilling, and avoid using stores which makes components hard to encapsulate. */ -import type { AppConfig } from "@/types/appConfig" +import type { AppConfigState } from "@kksh/types" import { getContext, setContext } from "svelte" import type { Writable } from "svelte/store" export const APP_CONFIG_CONTEXT_KEY = Symbol("appConfig") -export function getAppConfigContext(): Writable { +export function getAppConfigContext(): Writable { return getContext(APP_CONFIG_CONTEXT_KEY) } -export function setAppConfigContext(appConfig: Writable) { +export function setAppConfigContext(appConfig: Writable) { setContext(APP_CONFIG_CONTEXT_KEY, appConfig) } diff --git a/apps/desktop/src/lib/context/appState.ts b/apps/desktop/src/lib/context/appState.ts index 12aa792..02acf83 100644 --- a/apps/desktop/src/lib/context/appState.ts +++ b/apps/desktop/src/lib/context/appState.ts @@ -1,4 +1,4 @@ -import type { AppState } from "@/types/appState" +import type { AppState } from "@kksh/types" import { getContext, setContext } from "svelte" import type { Writable } from "svelte/store" diff --git a/apps/desktop/src/lib/stores/apps.ts b/apps/desktop/src/lib/stores/apps.ts index 700b7c7..5f39267 100644 --- a/apps/desktop/src/lib/stores/apps.ts +++ b/apps/desktop/src/lib/stores/apps.ts @@ -7,7 +7,7 @@ import Fuse from "fuse.js" import { derived, get, writable } from "svelte/store" import { appState } from "./appState" -export const fuse = new Fuse([], { +const fuse = new Fuse([], { includeScore: true, threshold: 0.2, keys: ["name"] diff --git a/apps/desktop/src/lib/stores/quick-links.ts b/apps/desktop/src/lib/stores/quick-links.ts index 120ea98..bd263b9 100644 --- a/apps/desktop/src/lib/stores/quick-links.ts +++ b/apps/desktop/src/lib/stores/quick-links.ts @@ -6,7 +6,7 @@ import Fuse from "fuse.js" import { derived, get, writable, type Writable } from "svelte/store" import { appState } from "./appState" -export const fuse = new Fuse([], { +const fuse = new Fuse([], { includeScore: true, threshold: 0.2, keys: ["name"] diff --git a/apps/desktop/src/lib/supabase.ts b/apps/desktop/src/lib/supabase.ts index 19c62d4..539f443 100644 --- a/apps/desktop/src/lib/supabase.ts +++ b/apps/desktop/src/lib/supabase.ts @@ -1,19 +1,13 @@ -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/apps/desktop/src/lib/utils/updater.ts b/apps/desktop/src/lib/utils/updater.ts index 17705b0..d6b503d 100644 --- a/apps/desktop/src/lib/utils/updater.ts +++ b/apps/desktop/src/lib/utils/updater.ts @@ -1,8 +1,7 @@ import { extensions } from "@/stores" -import { supabaseAPI } from "@/supabase" import { isCompatible } from "@kksh/api" import type { ExtPackageJsonExtra } from "@kksh/api/models" -import { greaterThan } from "@std/semver" +import { getExtensionsLatestPublishByIdentifier } from "@kksh/sdk" import { relaunch } from "@tauri-apps/plugin-process" import { check } from "@tauri-apps/plugin-updater" import { gt } from "semver" @@ -32,11 +31,22 @@ export async function checkSingleExtensionUpdate( installedExt: ExtPackageJsonExtra, autoupgrade: boolean ) { - const { data: sbExt, error } = await supabaseAPI.getLatestExtPublish( - installedExt.kunkun.identifier - ) + const { + data: sbExt, + error, + response + } = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: "RAG" + } + }) + // const { data: sbExt, error } = await supabaseAPI.getLatestExtPublish( + // installedExt.kunkun.identifier + // ) if (error) { - return toast.error(`Failed to check update for ${installedExt.kunkun.identifier}: ${error}`) + return toast.error( + `Failed to check update for ${installedExt.kunkun.identifier}: ${error} (${response.status})` + ) } if (!sbExt) { @@ -49,10 +59,7 @@ export async function checkSingleExtensionUpdate( ) { if (autoupgrade) { await extensions - .upgradeStoreExtension( - sbExt.identifier, - supabaseAPI.translateExtensionFilePathToUrl(sbExt.tarball_path) - ) + .upgradeStoreExtension(sbExt.identifier, sbExt.tarball_path) .then(() => { toast.success(`${sbExt.name} upgraded`, { description: `From ${installedExt.version} to ${sbExt.version}` diff --git a/apps/desktop/src/routes/app/extension/store/+page.svelte b/apps/desktop/src/routes/app/extension/store/+page.svelte index 115d426..d684bb9 100644 --- a/apps/desktop/src/routes/app/extension/store/+page.svelte +++ b/apps/desktop/src/routes/app/extension/store/+page.svelte @@ -2,14 +2,13 @@ import { getExtensionsFolder } from "@/constants" import { appState, extensions } from "@/stores" import { keys } from "@/stores/keys" - import { supabaseAPI } from "@/supabase" - import { goBackOnEscapeClearSearchTerm, goHomeOnEscapeClearSearchTerm } from "@/utils/key" import { goBack, goHome } from "@/utils/route" - import { Action as ActionSchema } from "@kksh/api/models" + import { Action as ActionSchema, ExtensionStoreListItem, ExtPublish } from "@kksh/api/models" import { Action } from "@kksh/api/ui" - import { SBExt } from "@kksh/supabase/models" - import type { ExtPublishMetadata } from "@kksh/supabase/models" - import { type Tables } from "@kksh/supabase/types" + import { + getExtensionsLatestPublishByIdentifier, + postExtensionsIncrementDownloads + } from "@kksh/sdk" import { Button, Command } from "@kksh/svelte5" import { Constants } from "@kksh/ui" import { ExtListItem } from "@kksh/ui/extension" @@ -71,51 +70,57 @@ } }) - function onExtItemSelected(ext: SBExt) { + function onExtItemSelected(ext: ExtensionStoreListItem) { goto(`./store/${ext.identifier}`) } - async function onExtItemUpgrade(ext: SBExt) { - const res = await supabaseAPI.getLatestExtPublish(ext.identifier) - if (res.error) + async function onExtItemUpgrade(ext: ExtensionStoreListItem) { + const { data, error, response } = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: ext.identifier + } + }) + if (error) return toast.error("Fail to get latest extension", { - description: res.error.message + description: error.error }) - const tarballUrl = res.data.tarball_path.startsWith("http") - ? res.data.tarball_path - : supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path) - const installExtras = await getInstallExtras( - res.data as Tables<"ext_publish"> & { metadata: ExtPublishMetadata } - ) + const installExtras = await getInstallExtras(data?.metadata) return extensions - .upgradeStoreExtension(ext.identifier, tarballUrl, installExtras) + .upgradeStoreExtension(ext.identifier, data.tarball_path, installExtras) .then((newExt) => { toast.success(`${ext.name} Upgraded to ${newExt.version}`) }) } - async function onExtItemInstall(ext: SBExt) { - const res = await supabaseAPI.getLatestExtPublish(ext.identifier) - if (res.error) + async function onExtItemInstall(ext: ExtensionStoreListItem) { + const { data, error, response } = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: ext.identifier + } + }) + if (error) return toast.error("Fail to get latest extension", { - description: res.error.message + description: error.error }) - const tarballUrl = res.data.tarball_path.startsWith("http") - ? res.data.tarball_path - : supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path) - const installExtras = await getInstallExtras( - res.data as Tables<"ext_publish"> & { metadata: ExtPublishMetadata } - ) + const installExtras = await getInstallExtras(data?.metadata) const installDir = await getExtensionsFolder() return extensions - .installFromTarballUrl(tarballUrl, installDir, installExtras) + .installFromTarballUrl(data.tarball_path, installDir, installExtras) .then(() => toast.success(`Plugin ${ext.name} Installed`)) .then(() => - supabaseAPI.incrementDownloads({ - identifier: ext.identifier, - version: ext.version + postExtensionsIncrementDownloads({ + body: { + identifier: ext.identifier, + version: ext.version + } }) + .then(({ error }) => { + if (error) { + console.error(error) + } + }) + .catch(console.error) ) } @@ -159,7 +164,7 @@ }) - + {#snippet leftSlot()}