Template
1
0

feat: split client to separate class

This commit is contained in:
2025-04-20 11:56:40 +00:00
parent 2e8d6b76d7
commit 221452893e
11 changed files with 220 additions and 195 deletions

View File

@@ -1,11 +1,11 @@
import z from "zod";
import { BadRequestError, InternalServerError, NotFoundError, RelayError } from "./errors.ts";
import { Route, RouteMethod } from "./route.ts";
import type { Route, RouteMethod } from "./route.ts";
const SUPPORTED_MEHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
export class Api<TRoutes extends Route[]> {
export class RelayAPI<TRoutes extends Route[]> {
/**
* Route maps funneling registered routes to the specific methods supported by
* the relay instance.
@@ -35,7 +35,7 @@ export class Api<TRoutes extends Route[]> {
*
* @param routes - Routes to register with the instance.
*/
constructor(routes: TRoutes) {
constructor({ routes }: Config<TRoutes>) {
const methods: (keyof typeof this.routes)[] = [];
for (const route of routes) {
this.#validateRoutePath(route);
@@ -264,6 +264,10 @@ function toResponse(result: object | RelayError | Response | void): Response {
|--------------------------------------------------------------------------------
*/
type Config<TRoutes extends Route[]> = {
routes: TRoutes;
};
type Routes = {
POST: Route[];
GET: Route[];