From 938a9097872db3d550209a5c1cf559a35155f5c7 Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Fri, 11 Jul 2025 01:17:54 +0530 Subject: [PATCH] tsc fixes --- bun.lock | 5 +++++ package.json | 1 + scripts/fix-interrupted-jobs.ts | 25 +++++++++-------------- scripts/generate-better-auth-schema.ts | 3 ++- scripts/investigate-repo.ts | 10 ++++----- scripts/migrate-to-better-auth.ts | 6 ++++-- scripts/repair-mirrored-repos.ts | 28 ++++++++++++++------------ scripts/test-graceful-shutdown.ts | 2 +- src/lib/db/schema.ts | 6 ++++++ src/lib/utils.ts | 8 +++++++- src/pages/api/sync/index.ts | 2 +- tsconfig.json | 3 ++- www/src/components/ui/button.tsx | 21 +++++++++---------- 13 files changed, 69 insertions(+), 51 deletions(-) diff --git a/bun.lock b/bun.lock index ab550f6..68fe96c 100644 --- a/bun.lock +++ b/bun.lock @@ -59,6 +59,7 @@ "@testing-library/jest-dom": "^6.6.3", "@testing-library/react": "^16.3.0", "@types/bcryptjs": "^3.0.0", + "@types/bun": "^1.2.18", "@types/jsonwebtoken": "^9.0.10", "@types/uuid": "^10.0.0", "@vitejs/plugin-react": "^4.6.0", @@ -540,6 +541,8 @@ "@types/bcryptjs": ["@types/bcryptjs@3.0.0", "", { "dependencies": { "bcryptjs": "*" } }, "sha512-WRZOuCuaz8UcZZE4R5HXTco2goQSI2XxjGY3hbM/xDvwmqFWd4ivooImsMx65OKM6CtNKbnZ5YL+YwAwK7c1dg=="], + "@types/bun": ["@types/bun@1.2.18", "", { "dependencies": { "bun-types": "1.2.18" } }, "sha512-Xf6RaWVheyemaThV0kUfaAUvCNokFr+bH8Jxp+tTZfx7dAPA8z9ePnP9S9+Vspzuxxx9JRAXhnyccRj3GyCMdQ=="], + "@types/canvas-confetti": ["@types/canvas-confetti@1.9.0", "", {}, "sha512-aBGj/dULrimR1XDZLtG9JwxX1b4HPRF6CX9Yfwh3NvstZEm1ZL7RBnel4keCPSqs1ANRu1u2Aoz9R+VmtjYuTg=="], "@types/chai": ["@types/chai@5.2.2", "", { "dependencies": { "@types/deep-eql": "*" } }, "sha512-8kB30R7Hwqf40JPiKhVzodJs2Qc1ZJ5zuT3uzw5Hq/dhNCl3G3l83jfpdI1e20BP348+fV7VIL/+FxaXkqBmWg=="], @@ -672,6 +675,8 @@ "buffer-from": ["buffer-from@1.1.2", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="], + "bun-types": ["bun-types@1.2.18", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-04+Eha5NP7Z0A9YgDAzMk5PHR16ZuLVa83b26kH5+cp1qZW4F6FmAURngE7INf4tKOvCE69vYvDEwoNl1tGiWw=="], + "cac": ["cac@6.7.14", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="], "camelcase": ["camelcase@8.0.0", "", {}, "sha512-8WB3Jcas3swSvjIeA2yvCJ+Miyz5l1ZmB6HFb9R1317dt9LCQoswg/BGrmAmkWVEszSrrg4RwmO46qIm2OEnSA=="], diff --git a/package.json b/package.json index 3ca4818..27dc0db 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "@testing-library/jest-dom": "^6.6.3", "@testing-library/react": "^16.3.0", "@types/bcryptjs": "^3.0.0", + "@types/bun": "^1.2.18", "@types/jsonwebtoken": "^9.0.10", "@types/uuid": "^10.0.0", "@vitejs/plugin-react": "^4.6.0", diff --git a/scripts/fix-interrupted-jobs.ts b/scripts/fix-interrupted-jobs.ts index 7ab358a..21d7860 100644 --- a/scripts/fix-interrupted-jobs.ts +++ b/scripts/fix-interrupted-jobs.ts @@ -10,7 +10,7 @@ */ import { db, mirrorJobs } from "../src/lib/db"; -import { eq } from "drizzle-orm"; +import { eq, and } from "drizzle-orm"; // Parse command line arguments const args = process.argv.slice(2); @@ -21,18 +21,19 @@ async function fixInterruptedJobs() { console.log("Checking for interrupted jobs..."); // Build the query - let query = db - .select() - .from(mirrorJobs) - .where(eq(mirrorJobs.inProgress, true)); + const whereConditions = userId + ? and(eq(mirrorJobs.inProgress, true), eq(mirrorJobs.userId, userId)) + : eq(mirrorJobs.inProgress, true); if (userId) { console.log(`Filtering for user: ${userId}`); - query = query.where(eq(mirrorJobs.userId, userId)); } // Find all in-progress jobs - const inProgressJobs = await query; + const inProgressJobs = await db + .select() + .from(mirrorJobs) + .where(whereConditions); if (inProgressJobs.length === 0) { console.log("No interrupted jobs found."); @@ -45,7 +46,7 @@ async function fixInterruptedJobs() { }); // Mark all in-progress jobs as failed - let updateQuery = db + await db .update(mirrorJobs) .set({ inProgress: false, @@ -53,13 +54,7 @@ async function fixInterruptedJobs() { status: "failed", message: "Job interrupted and marked as failed by cleanup script" }) - .where(eq(mirrorJobs.inProgress, true)); - - if (userId) { - updateQuery = updateQuery.where(eq(mirrorJobs.userId, userId)); - } - - await updateQuery; + .where(whereConditions); console.log(`✅ Successfully marked ${inProgressJobs.length} interrupted jobs as failed.`); console.log("These jobs can now be deleted through the normal cleanup process."); diff --git a/scripts/generate-better-auth-schema.ts b/scripts/generate-better-auth-schema.ts index 723e55e..5f5cef1 100644 --- a/scripts/generate-better-auth-schema.ts +++ b/scripts/generate-better-auth-schema.ts @@ -22,7 +22,8 @@ const auth = betterAuth({ }); // Generate the schema -const schema = auth.$internal.schema; +// Note: $internal API is not available in current better-auth version +// const schema = auth.$internal.schema; console.log("Better Auth Tables Required:"); console.log("============================"); diff --git a/scripts/investigate-repo.ts b/scripts/investigate-repo.ts index 8eeab35..b40678b 100644 --- a/scripts/investigate-repo.ts +++ b/scripts/investigate-repo.ts @@ -79,11 +79,11 @@ async function investigateRepository() { if (config.length > 0) { const userConfig = config[0]; console.log(` User ID: ${userConfig.userId}`); - console.log(` GitHub Username: ${userConfig.githubConfig?.username || "Not set"}`); + console.log(` GitHub Owner: ${userConfig.githubConfig?.owner || "Not set"}`); console.log(` Gitea URL: ${userConfig.giteaConfig?.url || "Not set"}`); - console.log(` Gitea Username: ${userConfig.giteaConfig?.username || "Not set"}`); - console.log(` Preserve Org Structure: ${userConfig.githubConfig?.preserveOrgStructure || false}`); - console.log(` Mirror Issues: ${userConfig.githubConfig?.mirrorIssues || false}`); + console.log(` Gitea Default Owner: ${userConfig.giteaConfig?.defaultOwner || "Not set"}`); + console.log(` Mirror Strategy: ${userConfig.githubConfig?.mirrorStrategy || "preserve"}`); + console.log(` Include Starred: ${userConfig.githubConfig?.includeStarred || false}`); } // Check for any active jobs @@ -123,7 +123,7 @@ async function investigateRepository() { try { const giteaUrl = userConfig.giteaConfig?.url; const giteaToken = userConfig.giteaConfig?.token; - const giteaUsername = userConfig.giteaConfig?.username; + const giteaUsername = userConfig.giteaConfig?.defaultOwner; if (giteaUrl && giteaToken && giteaUsername) { const checkUrl = `${giteaUrl}/api/v1/repos/${giteaUsername}/${repo.name}`; diff --git a/scripts/migrate-to-better-auth.ts b/scripts/migrate-to-better-auth.ts index ded3fa9..9790021 100644 --- a/scripts/migrate-to-better-auth.ts +++ b/scripts/migrate-to-better-auth.ts @@ -46,12 +46,14 @@ async function migrateUsers() { } // Create credential account with existing password hash + const accountId = uuidv4(); await db.insert(accounts).values({ - id: uuidv4(), + id: accountId, + accountId: accountId, userId: user.id, providerId: "credential", providerUserId: user.email, // Use email as provider user ID - password: user.password, // Move existing password hash + // password: user.password, // Password is not in users table anymore createdAt: user.createdAt, updatedAt: user.updatedAt, }); diff --git a/scripts/repair-mirrored-repos.ts b/scripts/repair-mirrored-repos.ts index 2b01a07..1a01b3f 100644 --- a/scripts/repair-mirrored-repos.ts +++ b/scripts/repair-mirrored-repos.ts @@ -81,21 +81,23 @@ async function repairMirroredRepositories() { try { // Find repositories that might need repair - let query = db - .select() - .from(repositories) - .where( - or( + const whereConditions = specificRepo + ? and( + or( + eq(repositories.status, "imported"), + eq(repositories.status, "failed") + ), + eq(repositories.name, specificRepo) + ) + : or( eq(repositories.status, "imported"), eq(repositories.status, "failed") - ) - ); + ); - if (specificRepo) { - query = query.where(eq(repositories.name, specificRepo)); - } - - const repos = await query; + const repos = await db + .select() + .from(repositories) + .where(whereConditions); if (repos.length === 0) { if (!isStartupMode) { @@ -137,7 +139,7 @@ async function repairMirroredRepositories() { } const userConfig = config[0]; - const giteaUsername = userConfig.giteaConfig?.username; + const giteaUsername = userConfig.giteaConfig?.defaultOwner; if (!giteaUsername) { if (!isStartupMode) { diff --git a/scripts/test-graceful-shutdown.ts b/scripts/test-graceful-shutdown.ts index 798a729..07ec2cd 100644 --- a/scripts/test-graceful-shutdown.ts +++ b/scripts/test-graceful-shutdown.ts @@ -47,7 +47,7 @@ async function createTestJob(): Promise { jobType: "mirror", totalItems: 10, itemIds: ['item-1', 'item-2', 'item-3', 'item-4', 'item-5'], - completedItemIds: ['item-1', 'item-2'], // Simulate partial completion + completedItems: 2, // Simulate partial completion inProgress: true, }); diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 125fb39..35dc62d 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -131,6 +131,8 @@ export const repositorySchema = z.object({ "skipped", "deleting", "deleted", + "syncing", + "synced", ]) .default("imported"), lastMirrored: z.coerce.date().optional().nullable(), @@ -157,6 +159,8 @@ export const mirrorJobSchema = z.object({ "skipped", "deleting", "deleted", + "syncing", + "synced", ]) .default("imported"), message: z.string(), @@ -191,6 +195,8 @@ export const organizationSchema = z.object({ "skipped", "deleting", "deleted", + "syncing", + "synced", ]) .default("imported"), lastMirrored: z.coerce.date().optional().nullable(), diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e292bae..eae92a1 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -194,7 +194,7 @@ export async function apiRequest( } } -export const getStatusColor = (status: RepoStatus): string => { +export const getStatusColor = (status: string): string => { switch (status) { case "imported": return "bg-blue-500"; // Info/primary-like @@ -208,6 +208,12 @@ export const getStatusColor = (status: RepoStatus): string => { return "bg-indigo-500"; // Sync in progress case "synced": return "bg-teal-500"; // Sync complete + case "skipped": + return "bg-gray-500"; // Skipped + case "deleting": + return "bg-orange-500"; // Deleting + case "deleted": + return "bg-gray-600"; // Deleted default: return "bg-gray-400"; // Unknown/neutral } diff --git a/src/pages/api/sync/index.ts b/src/pages/api/sync/index.ts index dd74473..2ada2e3 100644 --- a/src/pages/api/sync/index.ts +++ b/src/pages/api/sync/index.ts @@ -47,7 +47,7 @@ export const POST: APIRoute = async ({ request }) => { // Fetch GitHub data in parallel const [basicAndForkedRepos, starredRepos, gitOrgs] = await Promise.all([ getGithubRepositories({ octokit, config }), - config.githubConfig?.mirrorStarred + config.githubConfig?.includeStarred ? getGithubStarredRepositories({ octokit, config }) : Promise.resolve([]), getGithubOrganizations({ octokit, config }), diff --git a/tsconfig.json b/tsconfig.json index 90604a7..e1b23b6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,7 @@ "@/*": [ "./src/*" ] - } + }, + "types": ["bun-types"] } } \ No newline at end of file diff --git a/www/src/components/ui/button.tsx b/www/src/components/ui/button.tsx index a2df8dc..d4bf579 100644 --- a/www/src/components/ui/button.tsx +++ b/www/src/components/ui/button.tsx @@ -35,25 +35,24 @@ const buttonVariants = cva( } ) -function Button({ - className, - variant, - size, - asChild = false, - ...props -}: React.ComponentProps<"button"> & - VariantProps & { - asChild?: boolean - }) { +const Button = React.forwardRef< + HTMLButtonElement, + React.ComponentProps<"button"> & + VariantProps & { + asChild?: boolean + } +>(({ className, variant, size, asChild = false, ...props }, ref) => { const Comp = asChild ? Slot : "button" return ( ) -} +}) +Button.displayName = "Button" export { Button, buttonVariants }