server/types/api.ts
Jesse Wierzbinski e52e230ce3
refactor(database): 🚚 Move database ORM code to classes/database
The old directory, packages/database-interface, was confusingly named so it was better to move it here
2024-10-24 16:28:38 +02:00

86 lines
1.9 KiB
TypeScript

import type { RouterRoute } from "@hono/hono/types";
import type { OpenAPIHono } from "@hono/zod-openapi";
import type {
Delete,
Follow,
FollowAccept,
FollowReject,
InstanceMetadata,
LikeExtension,
Note,
Unfollow,
User,
} from "@versia/federation/types";
import type { SocketAddress } from "bun";
import { z } from "zod";
import type { Application } from "~/classes/database/application";
import type { User as DatabaseUser } from "~/classes/database/user";
import type { RolePermissions } from "~/drizzle/schema";
import type { Config } from "~/packages/config-manager";
export type HttpVerb = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS";
export interface ApiRouteMetadata {
ratelimits: {
max: number;
duration: number;
};
route: string;
auth: {
required: boolean;
methodOverrides?: {
[Key in HttpVerb]?: boolean;
};
oauthPermissions?: string[];
};
challenge?: {
required: boolean;
methodOverrides?: {
[Key in HttpVerb]?: boolean;
};
};
permissions?: {
required: RolePermissions[];
methodOverrides?: {
[Key in HttpVerb]?: RolePermissions[];
};
};
}
export const ErrorSchema = z.object({
error: z.string(),
});
export type HonoEnv = {
Variables: {
config: Config;
auth: {
user: DatabaseUser | null;
token: string | null;
application: Application | null;
};
};
Bindings: {
ip?: SocketAddress | null;
};
};
export interface ApiRouteExports {
meta: ApiRouteMetadata;
schemas?: {
query?: z.AnyZodObject;
body?: z.AnyZodObject;
};
default: (app: OpenAPIHono<HonoEnv>) => RouterRoute;
}
export type KnownEntity =
| Note
| InstanceMetadata
| User
| Follow
| FollowAccept
| FollowReject
| Unfollow
| Delete
| LikeExtension;