/**
* Copyright (c) 2018-present, heineiuo.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
///
import jsonSchema from 'json-schema';
import { ParseOptions, TokensToRegexpOptions, MatchFunction, MatchResult } from 'path-to-regexp';
import { MutableRefObject, ReactNode } from 'react';
export type PathOptions = TokensToRegexpOptions & ParseOptions & {
path?: HttpRequestPath;
};
export type HttpRequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
export type HttpRequestPath = string;
type Unregister = () => void;
export type OnRequestFunc = (event: FetchEvent, route: RegisteredValue & {
matched: MatchResult;
json?: Json;
}) => void | Promise;
export type RouteProps = PathOptions & {
children?: ReactNode;
method?: HttpRequestMethod;
onRequest?: OnRequestFunc;
cors?: boolean | CorsOptions;
maxAge?: number;
jsonSchema?: jsonSchema.JSONSchema7;
};
export type RegisterParams = RouteProps & {
method: HttpRequestMethod;
onRequest: OnRequestFunc;
};
export type RegisteredValue = RegisterParams & {
match: MatchFunction;
};
export type Register = (params: RegisterParams) => Unregister;
export type RegisteredKey = `/${HttpRequestMethod}${HttpRequestPath}`;
export type RegisteredMap = Map;
export type HangOnMap = Map void;
timer: any;
}>;
export type RouterContextState = {
register: Register;
registeredMap: MutableRefObject;
};
export type RouteContextState = Omit & {
register: Register;
};
export type RouteComponentProps = {
addListener: (event: 'fetch' | 'scheduled', callback: (event: FetchEvent) => void) => () => void;
};
export type RouteComponent = ((props: RouteComponentProps) => JSX.Element) | ((props: RouteComponentProps) => void);
export type StaticOrigin = boolean | string | RegExp | (boolean | string | RegExp)[];
export type CustomOrigin = (requestOrigin: string | undefined, callback: (err: Error | null, origin?: StaticOrigin) => void) => void;
export interface CorsOptions {
/**
* @default '*''
*/
origin?: StaticOrigin | CustomOrigin | undefined;
/**
* @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
*/
methods?: string | string[] | undefined;
allowedHeaders?: string | string[] | undefined;
exposedHeaders?: string | string[] | undefined;
credentials?: boolean | undefined;
maxAge?: number | undefined;
/**
* @default false
*/
preflightContinue?: boolean | undefined;
/**
* @default 204
*/
optionsSuccessStatus?: number | undefined;
}
export {};