type CleanKey = S extends `"${string}"` ? S extends `"${infer K}"` ? K : S : S; type KeyName = K extends `*${string}` | `${string}}` ? CleanKey : CleanKey; type KeyVal = K extends `*${string}` ? string[] : string | number; /** Parameters for a given path */ export type PathArgs = unknown extends S ? any : PathKeys extends never ? unknown : KeysToArgs>; /** Computes the union of keys for a path string */ export type PathKeys = string extends S ? string : S extends `${string}\\${string}` ? S extends `${infer A}\\${':' | '*' | '}'}${infer B}` ? PathKeys | PathKeys : ColonSplits | StarSplits : ColonSplits | StarSplits; /** Characters that end a :param or *wildcard token */ type PathDelimiter = '/' | '\\' | '%' | '&' | '*' | ':' | '{' | ';' | ',' | '!' | '@'; /** Token after every ':' in S */ type ColonSplits = S extends `${string}:${infer K}` ? PathToken | ColonSplits : never; /** `*`-prefixed token after every '*' in S */ type StarSplits = S extends `${string}*${infer K}` ? `*${PathToken}` | StarSplits : never; /** Prefix of K up to (excluding) its first PathDelimiter. * * Fast path: no delimiter at all, or the first '/' ends a delimiter-free token. * The delimiter-union templates without `infer` are matched without instantiation. */ type PathToken = K extends `${string}${PathDelimiter}${string}` ? K extends `${infer H}/${string}` ? H extends `${string}${PathDelimiter}${string}` ? PathTokenSlow : H : PathTokenSlow : K; /** Cuts at the first occurrence of each delimiter (union); recursing on each * candidate converges on the shortest, delimiter-free prefix. */ type PathTokenSlow = K extends `${infer H}${PathDelimiter}${string}` ? PathToken : K; type KeysToArgs = OptionalArgs & (RequiredPathKeys extends never ? unknown : RequiredArgs); /** Wide keys (`string`, template patterns) keep the original key-remapping * form so index signatures (and their `keyof`) stay exactly the same. */ type HasWideKey = true extends (Key extends string ? {} extends { [P in Key]: 1; } ? true : never : never) ? true : false; type OptionalArgs = HasWideKey extends true ? { [K in Key as K extends `${string}}` ? KeyName : never]?: KeyVal; } : { [N in KeyName>]?: (N extends KeyName, `*${string}`>> ? string[] : never) | (N extends KeyName, `*${string}`>> ? string | number : never); }; type RequiredArgs = HasWideKey extends true ? { [K in Key as K extends `${string}}` ? never : KeyName]: KeyVal; } : { [N in KeyName>]: (N extends KeyName, `*${string}`>> ? string[] : never) | (N extends KeyName, `*${string}`>> ? string | number : never); }; type OptionalPathKeys = Extract; type RequiredPathKeys = Exclude; export {}; //# sourceMappingURL=pathTypes.d.ts.map