import * as tm from "type-mapping"; import {PathUtil} from "../../path"; import {RouteData, Route} from "../route"; import { NonStringMappableKeys } from "../predicate"; export type SetParam = ( Route<{ readonly method : DataT["method"]; readonly path : DataT["path"]; readonly param : F; readonly query : DataT["query"]; readonly body : DataT["body"]; readonly header : DataT["header"]; readonly response : DataT["response"]; }> ); export type AssertCanSetParam = ( keyof PathUtil.RawParamOf extends keyof tm.MappableInputOf ? ( keyof tm.MappableInputOf extends keyof PathUtil.RawParamOf ? ( NonStringMappableKeys extends never ? F : [ "You must have string as MappableInput<> for these parameter names", NonStringMappableKeys ] ) : [ "The following parameter names do not exist", Exclude< keyof tm.MappableInputOf, PathUtil.ParamNameOf > ] ) : [ "The following parameter names are not mapped", Exclude< PathUtil.ParamNameOf, keyof tm.MappableInputOf > ] ); export function setParam ( data : DataT, f : AssertCanSetParam, ) : SetParam { return new Route<{ readonly method : DataT["method"]; readonly path : DataT["path"]; readonly param : F; readonly query : DataT["query"]; readonly body : DataT["body"]; readonly header : DataT["header"]; readonly response : DataT["response"]; }>({ ...data, param : f as F, }); }