| 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 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | type InstrumentationResultMeta = {
|
| 20 | url: LoaderFunctionArgs["url"];
|
| 21 | pattern: string;
|
| 22 | params: LoaderFunctionArgs["params"];
|
| 23 | };
|
| 24 | |
| 25 | |
| 26 | |
| 27 |
|
| 28 | type InstrumentationHandlerResult = {
|
| 29 | status: "success";
|
| 30 | error: undefined;
|
| 31 | } | {
|
| 32 | status: "error";
|
| 33 | error: Error;
|
| 34 | };
|
| 35 | |
| 36 | |
| 37 | |
| 38 |
|
| 39 | type InstrumentationClientRouterResult = InstrumentationHandlerResult & {
|
| 40 | meta: InstrumentationResultMeta | undefined;
|
| 41 | };
|
| 42 | |
| 43 | |
| 44 |
|
| 45 | type InstrumentationServerHandlerResult = InstrumentationHandlerResult & {
|
| 46 | statusCode: number;
|
| 47 | meta: InstrumentationResultMeta | undefined;
|
| 48 | };
|
| 49 | type InstrumentFunction<T, TInnerResult = InstrumentationHandlerResult> = (handler: () => Promise<TInnerResult>, info: T) => Promise<void>;
|
| 50 | type ReadonlyRequest = {
|
| 51 | method: string;
|
| 52 | url: string;
|
| 53 | headers: Pick<Headers, "get">;
|
| 54 | };
|
| 55 | type ReadonlyContext = Pick<RouterContextProvider, "get">;
|
| 56 | type InstrumentableRoute = {
|
| 57 | id: string;
|
| 58 | index: boolean | undefined;
|
| 59 | path: string | undefined;
|
| 60 | instrument(instrumentations: RouteInstrumentations): void;
|
| 61 | };
|
| 62 | type RouteInstrumentations = {
|
| 63 | lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
| 64 | "lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
| 65 | "lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
| 66 | "lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
| 67 | middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
| 68 | loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
| 69 | action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
| 70 | };
|
| 71 | type RouteLazyInstrumentationInfo = undefined;
|
| 72 | type RouteHandlerInstrumentationInfo = Readonly<Omit<LoaderFunctionArgs, "request" | "context"> & {
|
| 73 | request: ReadonlyRequest;
|
| 74 | context: ReadonlyContext;
|
| 75 | }>;
|
| 76 | type InstrumentableRouter = {
|
| 77 | instrument(instrumentations: RouterInstrumentations): void;
|
| 78 | };
|
| 79 | type RouterInstrumentations = {
|
| 80 | navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo, InstrumentationClientRouterResult>;
|
| 81 | fetch?: InstrumentFunction<RouterFetchInstrumentationInfo, InstrumentationClientRouterResult>;
|
| 82 | };
|
| 83 | type RouterNavigationInstrumentationInfo = Readonly<{
|
| 84 | to: string | number;
|
| 85 | currentUrl: string;
|
| 86 | formMethod?: HTMLFormMethod;
|
| 87 | formEncType?: FormEncType;
|
| 88 | formData?: FormData;
|
| 89 | body?: any;
|
| 90 | }>;
|
| 91 | type RouterFetchInstrumentationInfo = Readonly<{
|
| 92 | href: string;
|
| 93 | currentUrl: string;
|
| 94 | fetcherKey: string;
|
| 95 | formMethod?: HTMLFormMethod;
|
| 96 | formEncType?: FormEncType;
|
| 97 | formData?: FormData;
|
| 98 | body?: any;
|
| 99 | }>;
|
| 100 | type InstrumentableRequestHandler = {
|
| 101 | instrument(instrumentations: RequestHandlerInstrumentations): void;
|
| 102 | };
|
| 103 | type RequestHandlerInstrumentations = {
|
| 104 | request?: InstrumentFunction<RequestHandlerInstrumentationInfo, InstrumentationServerHandlerResult>;
|
| 105 | };
|
| 106 | type RequestHandlerInstrumentationInfo = Readonly<{
|
| 107 | request: ReadonlyRequest;
|
| 108 | context: ReadonlyContext | undefined;
|
| 109 | }>;
|
| 110 |
|
| 111 | export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationClientRouterResult, InstrumentationHandlerResult, InstrumentationServerHandlerResult, ServerInstrumentation }; |
| \ | No newline at end of file |