feat: Add sdk openapi generators

This commit is contained in:
Wanjohi
2025-11-05 13:23:59 +03:00
parent bcb4763532
commit dc3642153d
34 changed files with 2827 additions and 133 deletions

View File

@@ -1,4 +1,4 @@
import { teamTable } from "../team/team.sql.js";
import { userTable } from "../user/user.sql.js";
import { pgTable, varchar } from "drizzle-orm/pg-core";
import { id, timestamps, ulid } from "../drizzle/types.js";
@@ -8,8 +8,8 @@ export const apiAppTable = pgTable("api_app", {
name: varchar("name", { length: 255 }).notNull(),
secret: varchar("secret", { length: 255 }).notNull(),
redirectURI: varchar("redirect", { length: 255 }).notNull(),
teamID: ulid("team_id")
.references(() => teamTable.id, {
ownerID: ulid("owner_id")
.references(() => userTable.id, {
onDelete: "cascade",
})
.notNull(),
@@ -19,8 +19,8 @@ export const apiPersonalTokenTable = pgTable("api_personal_token", {
...id,
...timestamps,
token: varchar("token", { length: 255 }).notNull(),
teamID: ulid("team_id")
.references(() => teamTable.id, {
ownerID: ulid("owner_id")
.references(() => userTable.id, {
onDelete: "cascade",
})
.notNull(),

View File

@@ -36,7 +36,7 @@ export namespace Personal {
return tx
.select({
id: apiPersonalTokenTable.id,
teamID: apiPersonalTokenTable.teamID,
ownerID: apiPersonalTokenTable.ownerID,
})
.from(apiPersonalTokenTable)
.where(eq(apiPersonalTokenTable.token, token))

View File

@@ -6,11 +6,13 @@ import { PostgresJsQueryResultHKT, drizzle } from "drizzle-orm/postgres-js";
export namespace Database {
const { DATABASE_URL } = process.env;
if (!DATABASE_URL) {
throw new Error("DATABASE_URL is not set");
}
// if (!DATABASE_URL) {
// throw new Error("DATABASE_URL is not set");
// }
const dbUrl =
DATABASE_URL || "postgres://user:password@localhost:5432/nestri";
const sql = postgres(DATABASE_URL, {
const sql = postgres(dbUrl, {
max: 20,
idle_timeout: 60,
});

View File

@@ -0,0 +1,11 @@
export function lazy<T>(fn: () => T) {
let value: T | undefined;
let loaded = false;
return (): T => {
if (loaded) return value as T;
loaded = true;
value = fn();
return value as T;
};
}