import {ErrorWithContext} from "@extollo/util"; import {ResolvedRouteHandler, Route} from "./Route"; export class ActivatedRoute { public readonly params: {[key: string]: string} public readonly handler: ResolvedRouteHandler public readonly preflight: ResolvedRouteHandler[] public readonly postflight: ResolvedRouteHandler[] constructor( public readonly route: Route, public readonly path: string ) { const params = route.extract(path) if ( !params ) { const error = new ErrorWithContext('Cannot get params for route. Path does not match.') error.context = { matchedRoute: String(route), requestPath: path, } throw error } this.params = params this.preflight = route.resolvePreflight() this.handler = route.resolveHandler() this.postflight = route.resolvePostflight() } }