Skip to content

Commit bca4231

Browse files
committed
feat: separate db package
1 parent 0002236 commit bca4231

248 files changed

Lines changed: 710 additions & 621 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/api/package.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@
3333
"dev": "TZ=UTC wrangler dev --test-scheduled",
3434
"dev:remote": "wrangler dev --remote",
3535
"deploy": "wrangler deploy --minify",
36-
"dev:turso": "TZ=UTC turso dev --db-file ./src/db/local-db",
3736
"dev:stripe": "stripe listen --load-from-webhooks-api --forward-to localhost:8787/stripe/webhooks",
38-
"migrate": "drizzle-kit migrate",
39-
"migrate:push": "drizzle-kit push",
40-
"migrate:generate": "drizzle-kit generate",
41-
"studio": "drizzle-kit studio",
4237
"lint": "eslint . --max-warnings 0",
4338
"lint:fix": "eslint . --max-warnings 0 --fix",
4439
"format": "prettier --write .",
@@ -48,11 +43,9 @@
4843
"@anthropic-ai/sdk": "0.55.1",
4944
"@asyncstatus/dayjs": "workspace:*",
5045
"@asyncstatus/email": "workspace:*",
46+
"@asyncstatus/db": "workspace:*",
5147
"@asyncstatus/typed-handlers": "workspace:*",
52-
"@gitbeaker/rest": "43.4.0",
5348
"@hono-rate-limiter/cloudflare": "0.2.2",
54-
"@langchain/textsplitters": "0.1.0",
55-
"@libsql/client": "0.15.10",
5649
"@linear/sdk": "^28.0.0",
5750
"@noble/ed25519": "2.3.0",
5851
"@octokit/auth-oauth-user": "6.0.0",
@@ -62,14 +55,12 @@
6255
"@slack/web-api": "7.9.3",
6356
"ai": "4.3.18",
6457
"better-auth": "catalog:",
65-
"drizzle-orm": "0.44.3",
66-
"drizzle-zod": "0.8.2",
58+
"drizzle-orm": "catalog:",
6759
"hono": "catalog:",
6860
"hono-rate-limiter": "0.4.2",
6961
"jose": "6.0.12",
7062
"nanoid": "catalog:",
7163
"octokit": "5.0.3",
72-
"random-words": "2.0.1",
7364
"resend": "4.7.0",
7465
"stripe": "^17.3.1",
7566
"voyageai": "0.0.4",
@@ -80,7 +71,6 @@
8071
"@cloudflare/workers-types": "catalog:",
8172
"@octokit/openapi-webhooks-types": "12.0.3",
8273
"@types/bun": "catalog:",
83-
"drizzle-kit": "0.31.4",
8474
"wrangler": "catalog:"
8575
}
8676
}

apps/api/src/durable-objects/discord-gateway.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DurableObject } from "cloudflare:workers";
2+
import * as schema from "@asyncstatus/db";
3+
import { createDb } from "@asyncstatus/db/create-db";
24
import { eq } from "drizzle-orm";
3-
import * as schema from "../db";
4-
import { createDb } from "../db/db";
55
import type { Bindings } from "../lib/env";
66

77
// Discord Gateway API constants

apps/api/src/errors/index.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.

apps/api/src/index.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import type { SlackEvent } from "@slack/web-api";
99
import { Hono } from "hono";
1010
import { cors } from "hono/cors";
1111
import type { ContentfulStatusCode } from "hono/utils/http-status";
12-
import {
13-
AsyncStatusApiError,
14-
type AsyncStatusApiJsonError,
15-
AsyncStatusUnexpectedApiError,
16-
} from "./errors";
1712
import { createContext, type HonoEnv } from "./lib/env";
1813
import { verifySlackRequest } from "./lib/slack";
1914
import { handleStripeWebhook } from "./lib/stripe-webhook";
@@ -405,17 +400,7 @@ const app = new Hono<HonoEnv>()
405400
] as ContentfulStatusCode,
406401
);
407402
}
408-
if (err instanceof AsyncStatusUnexpectedApiError) {
409-
return c.json({ type: err.name, message: err.message }, err.status);
410-
}
411-
if (err instanceof AsyncStatusApiError) {
412-
return c.json({ type: err.name, message: err.message }, err.status);
413-
}
414-
const error = {
415-
type: "ASAPIUnexpectedError",
416-
message: "An unexpected error occurred. Please try again later.",
417-
} satisfies AsyncStatusApiJsonError;
418-
return c.json(error, 500);
403+
return c.json({ message: "Unknown error", code: "INTERNAL_SERVER_ERROR", cause: err }, 500);
419404
});
420405

421406
const typedHandlersApp = typedHandlersHonoServer(

apps/api/src/lib/auth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import * as schema from "@asyncstatus/db";
2+
import type { Db } from "@asyncstatus/db/create-db";
13
import ResetPassword from "@asyncstatus/email/auth/reset-password-email";
24
import VerificationEmail from "@asyncstatus/email/auth/verification-email";
35
import { betterAuth } from "better-auth";
46
import { drizzleAdapter } from "better-auth/adapters/drizzle";
57
import { customSession, jwt } from "better-auth/plugins";
68
import { desc, eq } from "drizzle-orm";
79
import type { Resend } from "resend";
8-
import * as schema from "../db";
9-
import type { Db } from "../db/db";
1010
import { authCookiesPlugin } from "./auth-cookies-plugin";
1111
import type { Bindings } from "./env";
1212

apps/api/src/lib/calculate-next-schedule-execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { dayjs } from "@asyncstatus/dayjs";
2-
import type { Schedule } from "../db";
2+
import type { Schedule } from "@asyncstatus/db";
33

44
export function calculateNextScheduleExecution(schedule: Schedule): Date | null {
55
const now = dayjs().tz(schedule.config.timezone);

apps/api/src/lib/env.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Anthropic from "@anthropic-ai/sdk";
2+
import type * as schema from "@asyncstatus/db";
3+
import type { Db } from "@asyncstatus/db/create-db";
4+
import { createDb } from "@asyncstatus/db/create-db";
25
import { Webhooks as GithubWebhooks } from "@octokit/webhooks";
36
import { createOpenRouter, type OpenRouterProvider } from "@openrouter/ai-sdk-provider";
47
import type { SlackEvent } from "@slack/web-api";
58
import type { InferSelectModel } from "drizzle-orm";
69
import type { Context, Next } from "hono";
710
import { Resend } from "resend";
811
import { VoyageAIClient } from "voyageai";
9-
import type * as schema from "../db";
10-
import type { Db } from "../db/db";
11-
import { createDb } from "../db/db";
1212
import type { DiscordGatewayDurableObject } from "../durable-objects/discord-gateway";
1313
import type { DeleteGithubIntegrationWorkflowParams } from "../workflows/github/delete-github-integration";
1414
import type { SyncGithubWorkflowParams } from "../workflows/github/sync-github";

apps/api/src/lib/get-organization-plan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as schema from "@asyncstatus/db";
2+
import type { Db } from "@asyncstatus/db/create-db";
13
import { eq } from "drizzle-orm";
24
import type Stripe from "stripe";
3-
import * as schema from "../db";
4-
import type { Db } from "../db/db";
55
import { syncStripeDataToKV } from "./stripe";
66

77
export type UserPlan = "basic" | "startup" | "enterprise";

apps/api/src/lib/middleware.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

apps/api/src/lib/stripe-organization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as schema from "@asyncstatus/db";
2+
import type { Db } from "@asyncstatus/db/create-db";
13
import { eq } from "drizzle-orm";
24
import type Stripe from "stripe";
3-
import * as schema from "../db";
4-
import type { Db } from "../db/db";
55

66
type GetOrCreateOrganizationStripeCustomerIdOptions = {
77
db: Db;

0 commit comments

Comments
 (0)