45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { Schema as S } from "@effect/schema";
|
|
|
|
// --- INTERFACES --------------------------------------------------------------
|
|
|
|
export interface RouteLiteral<Literal extends string> {
|
|
readonly _tag: "Literal";
|
|
readonly literal: Literal;
|
|
}
|
|
|
|
export interface RouteParam<Name extends string, Schema extends S.Schema<any, string>> {
|
|
readonly _tag: "Param";
|
|
readonly name: Name;
|
|
readonly schema: Schema;
|
|
}
|
|
|
|
export namespace RouteLiteral {
|
|
export type Any = RouteLiteral<string>;
|
|
}
|
|
|
|
export namespace RouteParam {
|
|
export type Any = RouteParam<string, S.Schema<any, string>>;
|
|
}
|
|
|
|
export namespace Route {
|
|
export type Any = readonly (
|
|
| RouteLiteral.Any
|
|
| RouteParam.Any
|
|
)[];
|
|
}
|
|
|
|
// --- CONSTRUCTORS ------------------------------------------------------------
|
|
|
|
export const RouteLiteral = <const Literal extends string>(literal: Literal): RouteLiteral<Literal> => Object.freeze<RouteLiteral<Literal>>({
|
|
_tag: "Literal",
|
|
literal,
|
|
});
|
|
|
|
export const RouteParam = <const Name extends string, const Schema extends S.Schema<any, string>>(name: Name, schema: Schema): RouteParam<Name, Schema> => Object.freeze<RouteParam<Name, Schema>>({
|
|
_tag: "Param",
|
|
name,
|
|
schema,
|
|
});
|
|
|
|
export const Route = <const Route extends Route.Any>(...route: Route): Route => Object.freeze<Route>(route);
|