UNPKG

3.06 kBTypeScriptView Raw
1
2import { FormEncType, HTMLFormMethod, LoaderFunctionArgs, RouterContextProvider } from "./utils.js";
3//#region lib/router/instrumentation.d.ts
4type ServerInstrumentation = {
5 handler?: InstrumentRequestHandlerFunction;
6 route?: InstrumentRouteFunction;
7};
8type ClientInstrumentation = {
9 router?: InstrumentRouterFunction;
10 route?: InstrumentRouteFunction;
11};
12type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
13type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
14type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
15type InstrumentationHandlerResult = {
16 status: "success";
17 error: undefined;
18} | {
19 status: "error";
20 error: Error;
21};
22type InstrumentFunction<T> = (handler: () => Promise<InstrumentationHandlerResult>, info: T) => Promise<void>;
23type ReadonlyRequest = {
24 method: string;
25 url: string;
26 headers: Pick<Headers, "get">;
27};
28type ReadonlyContext = Pick<RouterContextProvider, "get">;
29type InstrumentableRoute = {
30 id: string;
31 index: boolean | undefined;
32 path: string | undefined;
33 instrument(instrumentations: RouteInstrumentations): void;
34};
35type RouteInstrumentations = {
36 lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
37 "lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
38 "lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
39 "lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
40 middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
41 loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
42 action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
43};
44type RouteLazyInstrumentationInfo = undefined;
45type RouteHandlerInstrumentationInfo = Readonly<{
46 request: ReadonlyRequest;
47 params: LoaderFunctionArgs["params"];
48 pattern: string;
49 context: ReadonlyContext;
50}>;
51type InstrumentableRouter = {
52 instrument(instrumentations: RouterInstrumentations): void;
53};
54type RouterInstrumentations = {
55 navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
56 fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
57};
58type RouterNavigationInstrumentationInfo = Readonly<{
59 to: string | number;
60 currentUrl: string;
61 formMethod?: HTMLFormMethod;
62 formEncType?: FormEncType;
63 formData?: FormData;
64 body?: any;
65}>;
66type RouterFetchInstrumentationInfo = Readonly<{
67 href: string;
68 currentUrl: string;
69 fetcherKey: string;
70 formMethod?: HTMLFormMethod;
71 formEncType?: FormEncType;
72 formData?: FormData;
73 body?: any;
74}>;
75type InstrumentableRequestHandler = {
76 instrument(instrumentations: RequestHandlerInstrumentations): void;
77};
78type RequestHandlerInstrumentations = {
79 request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
80};
81type RequestHandlerInstrumentationInfo = Readonly<{
82 request: ReadonlyRequest;
83 context: ReadonlyContext | undefined;
84}>;
85//#endregion
86export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationHandlerResult, ServerInstrumentation };
\No newline at end of file