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