import type { IRouteParams } from "@ethicdevs/react-monolith";
import type { FastifySchema } from "fastify";
import { ResourceVisibility } from "@prisma/client";
import type { AppThemeScheme } from "./types";
import { PullRequestFormState } from "./islands/RepositoryPullRequestCreateForm";
export enum AppRoute {
HOME = "home",
THEME_SET_SCHEME_ACTION = "theme.set_scheme.action",
AUTH_REGISTER = "auth.register",
AUTH_REGISTER_ACTION = "auth.register.action",
AUTH_LOGIN = "auth.login",
AUTH_LOGIN_ACTION = "auth.login.action",
AUTH_LOGOUT_ACTION = "auth.logout.action",
ORGANIZATION_DETAILS = "organization.details",
REPOSITORY_BROWSER = "repository.browser",
REPOSITORY_BROWSER_WITH_PATH = "repository.browser.with_path",
REPOSITORY_COMMITS_LOG = "repository.commits_log",
REPOSITORY_COMPARE = "repository.compare",
REPOSITORY_CREATE = "repository.create",
REPOSITORY_CREATE_ACTION = "repository.create.action",
REPOSITORY_DETAILS = "repository.details",
REPOSITORY_DETAILS_WITH_TRAILING_SLASH = "repository.details.with_trailing_slash",
REPOSITORY_EXPLORE = "repository.explore",
REPOSITORY_FORK = "repository.fork",
REPOSITORY_FORK_ACTION = "repository.fork.action",
REPOSITORY_PULL_REQUEST_CLOSE_ACTION = "repository.pull_request.close.action",
REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION = "repository.pull_request.comment.create.action",
REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION = "repository.pull_request.comment.delete.action",
REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION = "repository.pull_request.comment.update.action",
REPOSITORY_PULL_REQUEST_CREATE = "repository.pull_request.create",
REPOSITORY_PULL_REQUEST_CREATE_ACTION = "repository.pull_request.create.action",
REPOSITORY_PULL_REQUEST_DELETE_ACTION = "repository.pull_request.delete.action",
REPOSITORY_PULL_REQUEST_DETAILS = "repository.pull_request.details",
REPOSITORY_PULL_REQUEST_MERGE_ACTION = "repository.pull_request.merge.action",
REPOSITORY_PULL_REQUEST_UPDATE_ACTION = "repository.pull_request.update.action",
REPOSITORY_PULL_REQUESTS = "repository.pull_requests",
REPOSITORY_SHOW_OBJECT = "repository.show_object",
SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION = "syntax_highlight.highlight_code.action",
USER_DASHBOARD = "user.dashboard",
USER_DETAILS = "user.details",
}
export const AppRoutePaths: Record<AppRoute, string> = {
[AppRoute.HOME]: "/",
[AppRoute.THEME_SET_SCHEME_ACTION]: "/theme/:themeScheme",
[AppRoute.AUTH_REGISTER]: "/auth/register",
[AppRoute.AUTH_REGISTER_ACTION]: "/auth/register",
[AppRoute.AUTH_LOGIN]: "/auth/login",
[AppRoute.AUTH_LOGIN_ACTION]: "/auth/login",
[AppRoute.AUTH_LOGOUT_ACTION]: "/auth/logout",
[AppRoute.ORGANIZATION_DETAILS]: "/:orgSlug",
[AppRoute.REPOSITORY_BROWSER]: "/:orgSlug/:repoSlug/:currentRef/tree",
[AppRoute.REPOSITORY_BROWSER_WITH_PATH]:
"/:orgSlug/:repoSlug/:currentRef/tree/*",
[AppRoute.REPOSITORY_COMMITS_LOG]: "/:orgSlug/:repoSlug/:currentRef/commits",
[AppRoute.REPOSITORY_COMPARE]: "/:orgSlug/:repoSlug/compare/:refA..:refB",
[AppRoute.REPOSITORY_CREATE]: "/repo/new",
[AppRoute.REPOSITORY_CREATE_ACTION]: "/repo/new",
[AppRoute.REPOSITORY_DETAILS]: "/:orgSlug/:repoSlug",
[AppRoute.REPOSITORY_DETAILS_WITH_TRAILING_SLASH]: "/:orgSlug/:repoSlug/",
[AppRoute.REPOSITORY_EXPLORE]: "/repo/explore",
[AppRoute.REPOSITORY_FORK]: "/:orgSlug/:repoSlug/fork",
[AppRoute.REPOSITORY_FORK_ACTION]: "/:orgSlug/:repoSlug/fork",
[AppRoute.REPOSITORY_PULL_REQUEST_CLOSE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/close",
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/comment",
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/comment/delete",
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/comment/edit",
[AppRoute.REPOSITORY_PULL_REQUEST_CREATE]: "/:orgSlug/:repoSlug/pulls/new",
[AppRoute.REPOSITORY_PULL_REQUEST_CREATE_ACTION]:
"/:orgSlug/:repoSlug/pulls/new",
[AppRoute.REPOSITORY_PULL_REQUEST_DELETE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/delete",
[AppRoute.REPOSITORY_PULL_REQUEST_DETAILS]:
"/:orgSlug/:repoSlug/pulls/:pullUid",
[AppRoute.REPOSITORY_PULL_REQUEST_MERGE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/merge",
[AppRoute.REPOSITORY_PULL_REQUEST_UPDATE_ACTION]:
"/:orgSlug/:repoSlug/pulls/:pullUid/edit",
[AppRoute.REPOSITORY_PULL_REQUESTS]: "/:orgSlug/:repoSlug/pulls",
[AppRoute.REPOSITORY_SHOW_OBJECT]: "/:orgSlug/:repoSlug/show/:objectId",
[AppRoute.SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION]:
"/api/syntax/highlight/:outputFormat",
[AppRoute.USER_DASHBOARD]: "/dashboard",
[AppRoute.USER_DETAILS]: "/@:username",
};
export interface AppRoutesParams extends IRouteParams {
[AppRoute.HOME]: undefined;
[AppRoute.THEME_SET_SCHEME_ACTION]: {
params: {
themeScheme: AppThemeScheme;
};
};
[AppRoute.AUTH_REGISTER]: undefined;
[AppRoute.AUTH_REGISTER_ACTION]: {
body: {
email_address: string;
username: string;
password: string;
};
};
[AppRoute.AUTH_LOGIN]: undefined;
[AppRoute.AUTH_LOGIN_ACTION]: {
body: {
email_address: string;
password: string;
};
};
[AppRoute.AUTH_LOGOUT_ACTION]: undefined;
[AppRoute.ORGANIZATION_DETAILS]: {
params: {
orgSlug: string;
};
};
[AppRoute.REPOSITORY_BROWSER]: {
params: {
orgSlug: string;
repoSlug: string;
currentRef: string;
"*": string;
};
};
[AppRoute.REPOSITORY_BROWSER_WITH_PATH]: {
params: {
orgSlug: string;
repoSlug: string;
currentRef: string;
"*": string;
};
};
[AppRoute.REPOSITORY_COMMITS_LOG]: {
params: {
orgSlug: string;
repoSlug: string;
currentRef: string;
};
};
[AppRoute.REPOSITORY_COMPARE]: {
params: {
orgSlug: string;
repoSlug: string;
refA: string;
refB: string;
};
};
[AppRoute.REPOSITORY_CREATE]: undefined;
[AppRoute.REPOSITORY_CREATE_ACTION]: {
body: {
parent_org_slug: string;
repo_display_name: string;
repo_init_license_file: "on" | "off";
repo_init_license_kind: string;
repo_init_readme_file: "on" | "off";
repo_keywords: string;
repo_keywords_add: string;
repo_short_description: string;
repo_slug: string;
repo_visibility: ResourceVisibility;
repo_website_url: string;
};
};
[AppRoute.REPOSITORY_DETAILS]: {
params: {
orgSlug: string;
repoSlug: string;
};
};
[AppRoute.REPOSITORY_DETAILS_WITH_TRAILING_SLASH]: {
params: {
orgSlug: string;
repoSlug: string;
};
};
[AppRoute.REPOSITORY_EXPLORE]: undefined;
[AppRoute.REPOSITORY_FORK]: {
params: {
orgSlug: string;
repoSlug: string;
};
};
[AppRoute.REPOSITORY_FORK_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
};
body: {
target_org_slug: string;
target_repo_display_name: string;
target_repo_slug: string;
target_repo_visibility: ResourceVisibility;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_CLOSE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
};
body: {
reason_message: string;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
};
body: {};
};
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
commentId: string;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
commentId: string;
};
body: {};
};
[AppRoute.REPOSITORY_PULL_REQUEST_CREATE]: {
params: {
orgSlug: string;
repoSlug: string;
};
querystring: {
from_branch?: string;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_CREATE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
};
body: {
state_from: PullRequestFormState;
state_dest: PullRequestFormState;
summary: string;
description: string;
source_parent_org_slug: string;
source_repository_slug: string;
source_repository_from_branch: string;
target_parent_org_slug: string;
target_repository_slug: string;
target_repository_dest_branch: string;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_DELETE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_DETAILS]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_MERGE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
};
body: {
merge_summary: string;
merge_message: string;
};
};
[AppRoute.REPOSITORY_PULL_REQUEST_UPDATE_ACTION]: {
params: {
orgSlug: string;
repoSlug: string;
pullUid: number;
};
body: {};
};
[AppRoute.REPOSITORY_PULL_REQUESTS]: {
params: {
orgSlug: string;
repoSlug: string;
};
};
[AppRoute.REPOSITORY_SHOW_OBJECT]: {
params: {
orgSlug: string;
repoSlug: string;
objectId: string;
};
};
[AppRoute.SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION]: {
params: {
outputFormat?: "html" | "json";
};
body: {
code: string;
language: string;
theme_scheme: AppThemeScheme;
};
};
[AppRoute.USER_DASHBOARD]: undefined;
[AppRoute.USER_DETAILS]: {
params: {
username: string;
};
};
}
export const AppRoutesSchemas: Record<AppRoute, undefined | FastifySchema> = {
[AppRoute.HOME]: undefined,
[AppRoute.THEME_SET_SCHEME_ACTION]: {
params: {
type: "object",
required: ["themeScheme"],
additionalProperties: false,
properties: {
themeScheme: {
type: "string",
enum: ["light", "dark"],
},
},
},
},
[AppRoute.AUTH_REGISTER]: undefined,
[AppRoute.AUTH_REGISTER_ACTION]: {
body: {
type: "object",
required: ["email_address", "username", "password"],
additionalProperties: false,
properties: {
email_address: { type: "string" },
username: { type: "string" },
password: { type: "string" },
},
},
},
[AppRoute.AUTH_LOGIN]: undefined,
[AppRoute.AUTH_LOGIN_ACTION]: {
body: {
type: "object",
required: ["email_address", "password"],
additionalProperties: false,
properties: {
email_address: { type: "string" },
password: { type: "string" },
},
},
},
[AppRoute.AUTH_LOGOUT_ACTION]: undefined,
[AppRoute.ORGANIZATION_DETAILS]: {
params: {
type: "object",
required: ["orgSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_BROWSER]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "currentRef", "*"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
currentRef: {
type: "string",
},
"*": {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_BROWSER_WITH_PATH]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "currentRef", "*"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
currentRef: {
type: "string",
},
"*": {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_COMMITS_LOG]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "currentRef"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
currentRef: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_COMPARE]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "refA", "refB"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
refA: {
type: "string",
},
refB: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_CREATE]: undefined,
[AppRoute.REPOSITORY_CREATE_ACTION]: {
body: {
type: "object",
required: [
"parent_org_slug",
"repo_display_name",
"repo_init_license_file",
"repo_init_license_kind",
"repo_init_readme_file",
"repo_keywords",
"repo_keywords_add",
"repo_short_description",
"repo_slug",
"repo_visibility",
"repo_website_url",
],
additionalProperties: false,
properties: {
parent_org_slug: {
type: "string",
},
repo_display_name: {
type: "string",
minLength: 3,
maxLength: 64,
},
repo_init_license_file: {
type: "string",
enum: ["on", "off"],
},
repo_init_license_kind: {
type: "string",
},
repo_init_readme_file: {
type: "string",
enum: ["on", "off"],
},
repo_keywords: {
type: "string",
},
repo_keywords_add: {
type: "string",
},
repo_short_description: {
type: "string",
minLength: 10,
maxLength: 140,
},
repo_slug: {
type: "string",
minLength: 3,
maxLength: 64,
},
repo_visibility: {
type: "string",
enum: Object.values(ResourceVisibility),
},
repo_website_url: {
type: "string",
format: "uri",
},
},
},
},
[AppRoute.REPOSITORY_DETAILS]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_DETAILS_WITH_TRAILING_SLASH]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_EXPLORE]: undefined,
[AppRoute.REPOSITORY_FORK]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
body: {
type: "object",
required: [
"target_org_slug",
"target_repo_display_name",
"target_repo_slug",
"target_repo_visibility",
],
additionalProperties: false,
properties: {
target_org_slug: {
type: "string",
},
target_repo_display_name: {
type: "string",
},
target_repo_slug: {
type: "string",
},
target_repo_visibility: {
type: "string",
enum: Object.values(ResourceVisibility),
},
},
},
},
[AppRoute.REPOSITORY_FORK_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_CLOSE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_CREATE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_DELETE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_COMMENT_UPDATE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_CREATE]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
querystring: {
type: "object",
required: [],
additionalProperties: false,
properties: {
from_branch: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_CREATE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
body: {
type: "object",
required: [
"state_from",
"state_dest",
"summary",
"source_parent_org_slug",
"source_repository_slug",
"source_repository_from_branch",
"target_parent_org_slug",
"target_repository_slug",
"target_repository_dest_branch",
],
additionalProperties: false,
properties: {
state_from: {
type: "string",
},
state_dest: {
type: "string",
},
summary: {
type: "string",
},
description: {
type: "string",
},
source_parent_org_slug: {
type: "string",
},
source_repository_slug: {
type: "string",
},
source_repository_from_branch: {
type: "string",
},
target_parent_org_slug: {
type: "string",
},
target_repository_slug: {
type: "string",
},
target_repository_dest_branch: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_DELETE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_DETAILS]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_MERGE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
body: {
type: "object",
required: ["merge_summary"],
additionalProperties: false,
properties: {
merge_summary: {
type: "string",
},
merge_message: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUEST_UPDATE_ACTION]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "pullUid"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
pullUid: {
type: "number",
},
},
},
},
[AppRoute.REPOSITORY_PULL_REQUESTS]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
},
},
},
[AppRoute.REPOSITORY_SHOW_OBJECT]: {
params: {
type: "object",
required: ["orgSlug", "repoSlug", "objectId"],
additionalProperties: false,
properties: {
orgSlug: {
type: "string",
},
repoSlug: {
type: "string",
},
objectId: {
type: "string",
},
},
},
},
[AppRoute.SYNTAX_HIGHLIGHT_HIGHLIGHT_CODE_ACTION]: {
params: {
type: "object",
required: [],
additionalProperties: false,
properties: {
outputFormat: {
type: "string",
enum: ["html", "json"],
},
},
},
body: {
type: "object",
required: ["code", "language", "theme_scheme"],
additionalProperties: false,
properties: {
code: {
type: "string",
},
language: {
type: "string",
},
theme_scheme: {
type: "string",
enum: ["light", "dark"],
},
},
},
},
[AppRoute.USER_DASHBOARD]: undefined,
[AppRoute.USER_DETAILS]: {
params: {
type: "object",
required: ["username"],
additionalProperties: false,
properties: {
username: {
type: "string",
},
},
},
},
};