1+ import { EngineMap } from "./engines/engine_map.ts" ;
2+
3+ /**
4+ * Allow arbitrary parameters in addition to parameters in T.
5+ */
6+ export type AllowArbitraryParams < T > = T & Record < string , unknown > ;
7+
18export type BaseParameters = {
29 /**
310 * Parameter defines the device to use to get the results. It can be set to
@@ -39,7 +46,19 @@ export type BaseParameters = {
3946 */
4047 timeout ?: number ;
4148} ;
42- export type BaseResponse < P = Record < string | number | symbol , never > > = {
49+
50+ // https://github.com/microsoft/TypeScript/issues/29729
51+ // deno-lint-ignore ban-types
52+ type AnyEngineName = string & { } ;
53+ export type EngineName = ( keyof EngineMap ) | AnyEngineName ;
54+ export type EngineParameters <
55+ E extends EngineName = EngineName ,
56+ > = {
57+ [ K in E ] : K extends keyof EngineMap ? EngineMap [ K ] [ "parameters" ]
58+ : BaseParameters & Record < string , unknown > ;
59+ } [ E ] ;
60+
61+ export type BaseResponse < E extends EngineName = EngineName > = {
4362 search_metadata : {
4463 id : string ;
4564 status : "Queued" | "Processing" | "Success" ;
@@ -49,14 +68,15 @@ export type BaseResponse<P = Record<string | number | symbol, never>> = {
4968 raw_html_file : string ;
5069 total_time_taken : number ;
5170 } ;
52- search_parameters :
53- & { engine : string }
54- & Omit < BaseParameters & P , "api_key" | "no_cache" | "async" | "timeout" > ;
71+ search_parameters : Omit <
72+ EngineParameters < E > ,
73+ "api_key" | "no_cache" | "async" | "timeout"
74+ > ;
5575 serpapi_pagination ?: { next : string } ;
5676 pagination ?: { next : string } ;
5777 next ?: (
58- callback ?: ( json : BaseResponse < P > ) => void ,
59- ) => Promise < BaseResponse < P > > ;
78+ callback ?: ( json : BaseResponse < E > ) => void ,
79+ ) => Promise < BaseResponse < E > > ;
6080 // deno-lint-ignore no-explicit-any
6181 [ key : string ] : any ; // TODO(seb): use recursive type
6282} ;
0 commit comments