mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-25 03:34:22 +01:00
big format
This commit is contained in:
@@ -24,37 +24,40 @@ export namespace AWS {
|
||||
body: z.string(),
|
||||
}),
|
||||
async (input) => {
|
||||
const res = await createClient().fetch("https://email.us-east-1.amazonaws.com/v2/email/outbound-emails", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Amz-Target": "SES.SendEmail",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
FromEmailAddress: `OpenCode Zen <contact@anoma.ly>`,
|
||||
Destination: {
|
||||
ToAddresses: [input.to],
|
||||
const res = await createClient().fetch(
|
||||
"https://email.us-east-1.amazonaws.com/v2/email/outbound-emails",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Amz-Target": "SES.SendEmail",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
Content: {
|
||||
Simple: {
|
||||
Subject: {
|
||||
Charset: "UTF-8",
|
||||
Data: input.subject,
|
||||
},
|
||||
Body: {
|
||||
Text: {
|
||||
body: JSON.stringify({
|
||||
FromEmailAddress: `OpenCode Zen <contact@anoma.ly>`,
|
||||
Destination: {
|
||||
ToAddresses: [input.to],
|
||||
},
|
||||
Content: {
|
||||
Simple: {
|
||||
Subject: {
|
||||
Charset: "UTF-8",
|
||||
Data: input.body,
|
||||
Data: input.subject,
|
||||
},
|
||||
Html: {
|
||||
Charset: "UTF-8",
|
||||
Data: input.body,
|
||||
Body: {
|
||||
Text: {
|
||||
Charset: "UTF-8",
|
||||
Data: input.body,
|
||||
},
|
||||
Html: {
|
||||
Charset: "UTF-8",
|
||||
Data: input.body,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
}),
|
||||
},
|
||||
)
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to send email: ${res.statusText}`)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import { Client } from "@planetscale/database"
|
||||
|
||||
import { MySqlTransaction, type MySqlTransactionConfig } from "drizzle-orm/mysql-core"
|
||||
import type { ExtractTablesWithRelations } from "drizzle-orm"
|
||||
import type { PlanetScalePreparedQueryHKT, PlanetscaleQueryResultHKT } from "drizzle-orm/planetscale-serverless"
|
||||
import type {
|
||||
PlanetScalePreparedQueryHKT,
|
||||
PlanetscaleQueryResultHKT,
|
||||
} from "drizzle-orm/planetscale-serverless"
|
||||
import { Context } from "../context"
|
||||
import { memo } from "../util/memo"
|
||||
|
||||
@@ -67,7 +70,10 @@ export namespace Database {
|
||||
}
|
||||
}
|
||||
|
||||
export async function transaction<T>(callback: (tx: TxOrDb) => Promise<T>, config?: MySqlTransactionConfig) {
|
||||
export async function transaction<T>(
|
||||
callback: (tx: TxOrDb) => Promise<T>,
|
||||
config?: MySqlTransactionConfig,
|
||||
) {
|
||||
try {
|
||||
const { tx } = TransactionContext.use()
|
||||
return callback(tx)
|
||||
|
||||
@@ -20,8 +20,14 @@ export namespace Key {
|
||||
email: AuthTable.subject,
|
||||
})
|
||||
.from(KeyTable)
|
||||
.innerJoin(UserTable, and(eq(KeyTable.userID, UserTable.id), eq(KeyTable.workspaceID, UserTable.workspaceID)))
|
||||
.innerJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))
|
||||
.innerJoin(
|
||||
UserTable,
|
||||
and(eq(KeyTable.userID, UserTable.id), eq(KeyTable.workspaceID, UserTable.workspaceID)),
|
||||
)
|
||||
.innerJoin(
|
||||
AuthTable,
|
||||
and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")),
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
...[
|
||||
|
||||
@@ -11,7 +11,9 @@ export namespace Provider {
|
||||
tx
|
||||
.select()
|
||||
.from(ProviderTable)
|
||||
.where(and(eq(ProviderTable.workspaceID, Actor.workspace()), isNull(ProviderTable.timeDeleted))),
|
||||
.where(
|
||||
and(eq(ProviderTable.workspaceID, Actor.workspace()), isNull(ProviderTable.timeDeleted)),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -50,7 +52,12 @@ export namespace Provider {
|
||||
return Database.transaction((tx) =>
|
||||
tx
|
||||
.delete(ProviderTable)
|
||||
.where(and(eq(ProviderTable.provider, provider), eq(ProviderTable.workspaceID, Actor.workspace()))),
|
||||
.where(
|
||||
and(
|
||||
eq(ProviderTable.provider, provider),
|
||||
eq(ProviderTable.workspaceID, Actor.workspace()),
|
||||
),
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { index, mysqlEnum, mysqlTable, primaryKey, uniqueIndex, varchar } from "drizzle-orm/mysql-core"
|
||||
import {
|
||||
index,
|
||||
mysqlEnum,
|
||||
mysqlTable,
|
||||
primaryKey,
|
||||
uniqueIndex,
|
||||
varchar,
|
||||
} from "drizzle-orm/mysql-core"
|
||||
import { id, timestamps, ulid } from "../drizzle/types"
|
||||
|
||||
export const AuthProvider = ["email", "github", "google"] as const
|
||||
|
||||
@@ -9,5 +9,8 @@ export const ModelTable = mysqlTable(
|
||||
...timestamps,
|
||||
model: varchar("model", { length: 64 }).notNull(),
|
||||
},
|
||||
(table) => [...workspaceIndexes(table), uniqueIndex("model_workspace_model").on(table.workspaceID, table.model)],
|
||||
(table) => [
|
||||
...workspaceIndexes(table),
|
||||
uniqueIndex("model_workspace_model").on(table.workspaceID, table.model),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,5 +10,8 @@ export const ProviderTable = mysqlTable(
|
||||
provider: varchar("provider", { length: 64 }).notNull(),
|
||||
credentials: text("credentials").notNull(),
|
||||
},
|
||||
(table) => [...workspaceIndexes(table), uniqueIndex("workspace_provider").on(table.workspaceID, table.provider)],
|
||||
(table) => [
|
||||
...workspaceIndexes(table),
|
||||
uniqueIndex("workspace_provider").on(table.workspaceID, table.provider),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { mysqlTable, uniqueIndex, varchar, int, mysqlEnum, index, bigint } from "drizzle-orm/mysql-core"
|
||||
import {
|
||||
mysqlTable,
|
||||
uniqueIndex,
|
||||
varchar,
|
||||
int,
|
||||
mysqlEnum,
|
||||
index,
|
||||
bigint,
|
||||
} from "drizzle-orm/mysql-core"
|
||||
import { timestamps, ulid, utc, workspaceColumns } from "../drizzle/types"
|
||||
import { workspaceIndexes } from "./workspace.sql"
|
||||
|
||||
|
||||
@@ -26,7 +26,10 @@ export namespace User {
|
||||
authEmail: AuthTable.subject,
|
||||
})
|
||||
.from(UserTable)
|
||||
.leftJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))
|
||||
.leftJoin(
|
||||
AuthTable,
|
||||
and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")),
|
||||
)
|
||||
.where(and(eq(UserTable.workspaceID, Actor.workspace()), isNull(UserTable.timeDeleted))),
|
||||
),
|
||||
)
|
||||
@@ -36,7 +39,13 @@ export namespace User {
|
||||
tx
|
||||
.select()
|
||||
.from(UserTable)
|
||||
.where(and(eq(UserTable.workspaceID, Actor.workspace()), eq(UserTable.id, id), isNull(UserTable.timeDeleted)))
|
||||
.where(
|
||||
and(
|
||||
eq(UserTable.workspaceID, Actor.workspace()),
|
||||
eq(UserTable.id, id),
|
||||
isNull(UserTable.timeDeleted),
|
||||
),
|
||||
)
|
||||
.then((rows) => rows[0]),
|
||||
),
|
||||
)
|
||||
@@ -48,7 +57,10 @@ export namespace User {
|
||||
email: AuthTable.subject,
|
||||
})
|
||||
.from(UserTable)
|
||||
.leftJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))
|
||||
.leftJoin(
|
||||
AuthTable,
|
||||
and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")),
|
||||
)
|
||||
.where(and(eq(UserTable.workspaceID, Actor.workspace()), eq(UserTable.id, id)))
|
||||
.then((rows) => rows[0]?.email),
|
||||
),
|
||||
@@ -130,10 +142,16 @@ export namespace User {
|
||||
workspaceName: WorkspaceTable.name,
|
||||
})
|
||||
.from(UserTable)
|
||||
.innerJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")))
|
||||
.innerJoin(
|
||||
AuthTable,
|
||||
and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email")),
|
||||
)
|
||||
.innerJoin(WorkspaceTable, eq(WorkspaceTable.id, workspaceID))
|
||||
.where(
|
||||
and(eq(UserTable.workspaceID, workspaceID), eq(UserTable.id, Actor.assert("user").properties.userID)),
|
||||
and(
|
||||
eq(UserTable.workspaceID, workspaceID),
|
||||
eq(UserTable.id, Actor.assert("user").properties.userID),
|
||||
),
|
||||
)
|
||||
.then((rows) => rows[0]),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user