-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateRouterElementSystem.ts
More file actions
48 lines (43 loc) · 1.22 KB
/
createRouterElementSystem.ts
File metadata and controls
48 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { asyncPipe, E, unwrap } from "@duplojs/utils";
import { buildRouteFunction, type BuildRouteFunctionParams } from "@core/functionsBuilders";
import { controlBodyAsEmpty } from "@core/request";
import { createRoute } from "@core/route";
import { RouterBuildError } from "./buildError";
import { defaultEmptyReaderImplementation } from "@core/hub";
import { type HandlerStep } from "@core/steps";
import { type RouterElementSystem } from "./types";
interface CreateRouterElementSystemParams {
handlerStep: HandlerStep;
buildParams: BuildRouteFunctionParams;
}
export async function createRouterElementSystem(params: CreateRouterElementSystemParams): Promise<RouterElementSystem> {
const bodyController = controlBodyAsEmpty();
const bodyReader = bodyController.createReaderOrThrow(
defaultEmptyReaderImplementation,
);
const route = createRoute({
method: "GET",
paths: ["/"],
hooks: [],
preflightSteps: [],
steps: [params.handlerStep],
metadata: [],
bodyController,
});
const buildedRoute = await asyncPipe(
buildRouteFunction(
route,
params.buildParams,
),
E.whenIsLeft(
(element) => {
throw new RouterBuildError(route, element);
},
),
unwrap,
);
return {
bodyReader,
buildedRoute,
};
}