mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: ♻️ Always use explicit types in every function
This commit is contained in:
parent
54cea29ce9
commit
c1dcdc78ae
62 changed files with 359 additions and 226 deletions
|
|
@ -63,7 +63,7 @@ const schemas = {
|
|||
}),
|
||||
};
|
||||
|
||||
export default (plugin: PluginType) =>
|
||||
export default (plugin: PluginType): void =>
|
||||
plugin.registerRoute("/oauth/authorize", (app) =>
|
||||
app.openapi(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { createRoute, z } from "@hono/zod-openapi";
|
|||
import { exportJWK } from "jose";
|
||||
import type { PluginType } from "../index.ts";
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/.well-known/jwks", (app) =>
|
||||
app.openapi(
|
||||
createRoute({
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { randomString } from "@/math.ts";
|
|||
import { setCookie } from "@hono/hono/cookie";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { User, db } from "@versia/kit/db";
|
||||
import { and, eq, isNull } from "@versia/kit/drizzle";
|
||||
import { type SQL, and, eq, isNull } from "@versia/kit/drizzle";
|
||||
import {
|
||||
OpenIdAccounts,
|
||||
RolePermissions,
|
||||
|
|
@ -29,7 +29,7 @@ export const schemas = {
|
|||
}),
|
||||
};
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/oauth/sso/{issuer}/callback", (app) => {
|
||||
app.openapi(
|
||||
createRoute({
|
||||
|
|
@ -150,7 +150,7 @@ export default (plugin: PluginType) => {
|
|||
|
||||
// Check if account is already linked
|
||||
const account = await db.query.OpenIdAccounts.findFirst({
|
||||
where: (account, { eq, and }) =>
|
||||
where: (account, { eq, and }): SQL | undefined =>
|
||||
and(
|
||||
eq(account.serverId, sub),
|
||||
eq(account.issuerId, issuer.id),
|
||||
|
|
@ -188,7 +188,7 @@ export default (plugin: PluginType) => {
|
|||
|
||||
let userId = (
|
||||
await db.query.OpenIdAccounts.findFirst({
|
||||
where: (account, { eq, and }) =>
|
||||
where: (account, { eq, and }): SQL | undefined =>
|
||||
and(
|
||||
eq(account.serverId, sub),
|
||||
eq(account.issuerId, issuer.id),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { jsonOrForm } from "@/api";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { db } from "@versia/kit/db";
|
||||
import { eq } from "@versia/kit/drizzle";
|
||||
import { type SQL, eq } from "@versia/kit/drizzle";
|
||||
import { Tokens } from "@versia/kit/tables";
|
||||
import type { PluginType } from "../../index.ts";
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ export const schemas = {
|
|||
}),
|
||||
};
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/oauth/revoke", (app) => {
|
||||
app.openapi(
|
||||
createRoute({
|
||||
|
|
@ -63,7 +63,7 @@ export default (plugin: PluginType) => {
|
|||
context.req.valid("json");
|
||||
|
||||
const foundToken = await db.query.Tokens.findFirst({
|
||||
where: (tokenTable, { eq, and }) =>
|
||||
where: (tokenTable, { eq, and }): SQL | undefined =>
|
||||
and(
|
||||
eq(tokenTable.accessToken, token ?? ""),
|
||||
eq(tokenTable.clientId, client_id),
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const schemas = {
|
|||
}),
|
||||
};
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/oauth/sso", (app) => {
|
||||
app.openapi(
|
||||
createRoute({
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { jsonOrForm } from "@/api";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { Application, db } from "@versia/kit/db";
|
||||
import { eq } from "@versia/kit/drizzle";
|
||||
import { type SQL, eq } from "@versia/kit/drizzle";
|
||||
import { Tokens } from "@versia/kit/tables";
|
||||
import type { PluginType } from "../../index.ts";
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ export const schemas = {
|
|||
}),
|
||||
};
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/oauth/token", (app) => {
|
||||
app.openapi(
|
||||
createRoute({
|
||||
|
|
@ -155,7 +155,7 @@ export default (plugin: PluginType) => {
|
|||
}
|
||||
|
||||
const token = await db.query.Tokens.findFirst({
|
||||
where: (token, { eq, and }) =>
|
||||
where: (token, { eq, and }): SQL | undefined =>
|
||||
and(
|
||||
eq(token.code, code),
|
||||
eq(
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import { auth } from "@/api";
|
|||
import { proxyUrl } from "@/response";
|
||||
import { createRoute, z } from "@hono/zod-openapi";
|
||||
import { db } from "@versia/kit/db";
|
||||
import { eq } from "@versia/kit/drizzle";
|
||||
import { type SQL, eq } from "@versia/kit/drizzle";
|
||||
import { OpenIdAccounts, RolePermissions } from "@versia/kit/tables";
|
||||
import type { PluginType } from "~/plugins/openid";
|
||||
import { ErrorSchema } from "~/types/api";
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/api/v1/sso", (app) => {
|
||||
app.openapi(
|
||||
createRoute({
|
||||
|
|
@ -88,7 +88,7 @@ export default (plugin: PluginType) => {
|
|||
}
|
||||
|
||||
const account = await db.query.OpenIdAccounts.findFirst({
|
||||
where: (account, { eq, and }) =>
|
||||
where: (account, { eq, and }): SQL | undefined =>
|
||||
and(
|
||||
eq(account.userId, user.id),
|
||||
eq(account.issuerId, issuerId),
|
||||
|
|
@ -181,7 +181,7 @@ export default (plugin: PluginType) => {
|
|||
}
|
||||
|
||||
const account = await db.query.OpenIdAccounts.findFirst({
|
||||
where: (account, { eq, and }) =>
|
||||
where: (account, { eq, and }): SQL | undefined =>
|
||||
and(
|
||||
eq(account.userId, user.id),
|
||||
eq(account.issuerId, issuerId),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { ErrorSchema } from "~/types/api";
|
|||
import type { PluginType } from "../../index.ts";
|
||||
import { oauthDiscoveryRequest, oauthRedirectUri } from "../../utils.ts";
|
||||
|
||||
export default (plugin: PluginType) => {
|
||||
export default (plugin: PluginType): void => {
|
||||
plugin.registerRoute("/api/v1/sso", (app) => {
|
||||
app.openapi(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue