import type { Handler } from '../types';
import { ConcatPath } from '../utils/concatPath';
import { lowercaseMethods } from '../utils/methods';
import { t } from 'wint-js';
type Merge = B extends object ? (A extends object ? (keyof A extends never ? B : A & B) : (keyof B extends never ? A : B)) : B;
type MergeRoutes = Routes>;
export type Route = [method: string, path: string, handlers: Handler[]];
export type PluginResult> = ReturnType;
export interface RouteHandler {
(path: Path, ...handlers: Handler, State>[]): Routes;
}
export interface Routes extends Record> {
}
export interface GenericRoutes extends Routes> {
}
export interface GenericPlugin extends Plugin {
}
/**
* A routes plugin
*/
export interface Plugin {
plugin(routes: T): R;
}
export declare class Routes implements Plugin {
base: Root;
/**
* Properties for correct type inference. Set to null by default
*/
stateInfer: State;
/**
* Fallback when guard functions reject
*/
fallback: Handler;
/**
* Routes record
*/
readonly record: Route[];
/**
* Route guards - before handling
*/
readonly guards: Handler[];
/**
* Route wrappers - after handling
*/
readonly wraps: Handler[];
/**
* Create a route group
*/
constructor(base?: Root);
/**
* Add prefix
*/
prefix(base: B): Routes, State>;
/**
* Add guards
*/
guard(...fns: Handler[]): this;
/**
* Add layers (Guards with no validation)
*/
layer(...fns: Handler[]): this;
/**
* Non-typesafe plugins
*/
plug[]>(...plugins: T): this;
/**
* Register a plugin
*/
use>(f: T): MergeRoutes>;
/**
* Add wraps
*/
wrap(...fns: Handler[]): this;
/**
* Add a state as a guard
*/
state>(fn: F, reject?: Handler): Routes>>>;
/**
* Add multiple fields to the state
*/
state>>(rec: O, reject?: Handler): Routes>>;
} & State>;
private hasMultipleState;
private registerMultipleState;
private registerSingleState;
/**
* Prepend guard. This function is considered internal API.
*/
prependGuards(...fns: Handler[]): this;
/**
* Register a reject handler for current handlers
*/
reject(fn: Handler): this;
/**
* Extend other routes
*/
extend(...routes: Routes[]): this;
/**
* Routes can be used as a plugin
*/
plugin(routes: T): T;
/**
* Infer all routes to the router
*/
infer(router: T): T;
}
/**
* Route groups
*/
export declare const routes: (base?: Root) => Routes;
/**
* Create reusable states
*/
export declare const state: | Record>>(s: T) => T;
/**
* Create a plugin from a function
*/
export declare const plugin: >(plugin: (routes: GenericRoutes) => R) => Plugin;
export {};