diff options
| author | Frank <[email protected]> | 2025-09-18 10:59:01 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-09-18 10:59:01 -0400 |
| commit | 4ceabdffa07b1af8d99eb73622a4d549d99ec6d2 (patch) | |
| tree | 72e2ae62084a9e24cc76caffbd1f30dafc69ea56 /packages/console/core/src/workspace.ts | |
| parent | c87480cf931a6f8f8b55552558ef521f1918b578 (diff) | |
| download | opencode-4ceabdffa07b1af8d99eb73622a4d549d99ec6d2.tar.gz opencode-4ceabdffa07b1af8d99eb73622a4d549d99ec6d2.zip | |
wip: zen
Diffstat (limited to 'packages/console/core/src/workspace.ts')
| -rw-r--r-- | packages/console/core/src/workspace.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/packages/console/core/src/workspace.ts b/packages/console/core/src/workspace.ts new file mode 100644 index 000000000..a9fb923d6 --- /dev/null +++ b/packages/console/core/src/workspace.ts @@ -0,0 +1,58 @@ +import { z } from "zod" +import { fn } from "./util/fn" +import { centsToMicroCents } from "./util/price" +import { Actor } from "./actor" +import { Database, eq } from "./drizzle" +import { Identifier } from "./identifier" +import { UserTable } from "./schema/user.sql" +import { BillingTable } from "./schema/billing.sql" +import { WorkspaceTable } from "./schema/workspace.sql" +import { Key } from "./key" + +export namespace Workspace { + export const create = fn(z.void(), async () => { + const account = Actor.assert("account") + const workspaceID = Identifier.create("workspace") + await Database.transaction(async (tx) => { + await tx.insert(WorkspaceTable).values({ + id: workspaceID, + }) + await tx.insert(UserTable).values({ + workspaceID, + id: Identifier.create("user"), + email: account.properties.email, + name: "", + }) + await tx.insert(BillingTable).values({ + workspaceID, + id: Identifier.create("billing"), + balance: 0, + }) + }) + await Actor.provide( + "system", + { + workspaceID, + }, + async () => { + await Key.create({ name: "Default API Key" }) + }, + ) + return workspaceID + }) + + export async function list() { + const account = Actor.assert("account") + return Database.use(async (tx) => { + return tx + .select({ + id: WorkspaceTable.id, + slug: WorkspaceTable.slug, + name: WorkspaceTable.name, + }) + .from(UserTable) + .innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id)) + .where(eq(UserTable.email, account.properties.email)) + }) + } +} |
