24 lines
690 B
TypeScript
24 lines
690 B
TypeScript
import { Result } from "@shared/utils/result.ts";
|
|
import { Schema } from "@shared/utils/validator.ts";
|
|
|
|
class ApiRoute<
|
|
Path extends string,
|
|
ReqSchema extends Schema<any>,
|
|
ResSchema extends Schema<any>,
|
|
> {
|
|
constructor(
|
|
public readonly path: Path,
|
|
public readonly reqSchema: ReqSchema,
|
|
public readonly resSchema: ResSchema,
|
|
) {
|
|
}
|
|
}
|
|
|
|
export type ExtractRouteParams<T extends string> = T extends string
|
|
? T extends `${infer _Start}:${infer Param}/${infer Rest}`
|
|
? Param | ExtractRouteParams<Rest>
|
|
: T extends `${infer _Start}:${infer Param}` ? Param
|
|
: T extends `${infer _Start}*` ? "restOfThePath"
|
|
: never
|
|
: never;
|