@@ -4,6 +4,7 @@ import type { InferDataFromQueryTagOption, QueryTagObject, QueryTagOption, Query
44import { TODO } from '../type-utils' ;
55import { QueryBuilderFrozen } from './QueryBuilderFrozen' ;
66import { type MiddlewareFn , createMiddlewareFunction } from './createMiddlewareFunction' ;
7+ import { PostprocessorFn } from './createMiddlewareFunction' ;
78import { type PreprocessorFn , createPreprocessorFunction , identityPreprocessor } from './createPreprocessorFunction' ;
89import { createTagMiddleware } from './createTagMiddleware' ;
910import { createUpdateMiddleware } from './createUpdateMiddleware' ;
@@ -65,8 +66,8 @@ export class QueryBuilder<
6566 withPreprocessor ( preprocessor : PreprocessorFn < TVars , TVars > ) : this;
6667
6768 /**
68- * Adds a preprocessor function to the query with a different type of input variables.
69- * The preprocessor function is called before the query function is called.
69+ * Adds a pre-processor function to the query with a different type of input variables.
70+ * The pre-processor function is called before the query function is called.
7071 */
7172 withPreprocessor < TVars$ = TVars > ( preprocessor : PreprocessorFn < TVars$ , TVars > ) : QueryBuilder < TVars$ , TData , TError , TKey , TTags , TFlags > ;
7273
@@ -78,24 +79,35 @@ export class QueryBuilder<
7879 } ) ;
7980 }
8081
82+ /**
83+ * Adds a post-processor function to the query.
84+ * The post-processor function is called after the query function is successfully called.
85+ * It can be used to modify the output data.
86+ */
87+ withPostprocessor < TData$ = TData > (
88+ postprocessor : PostprocessorFn < TData , TData$ > ,
89+ ) : QueryBuilder < TVars , TData$ , TError , TKey , TTags , TFlags > {
90+ return this . withMiddleware ( async ( ctx , next ) => postprocessor ( await next ( ctx ) ) ) ;
91+ }
92+
8193 /**
8294 * Adds a middleware function to the query.
8395 * The middleware function wraps the query function and
8496 * can be used to modify the input variables, the output data, or the error.
8597 */
86- withMiddleware ( middleware : MiddlewareFn < TVars , TData , TError , TKey > ) : this;
98+ withMiddleware ( middleware : MiddlewareFn < TVars , TData , TError , TKey , TData > ) : this;
8799
88100 /**
89101 * Adds a middleware function to the query with overloaded types.
90102 * The middleware function wraps the query function and
91103 * can be used to modify the input variables, the output data, or the error.
92104 */
93105 withMiddleware < TVars$ = TVars , TData$ = TData , TError$ = TError > (
94- middleware : MiddlewareFn < TVars$ , TData$ , TError$ , TKey > ,
106+ middleware : MiddlewareFn < TVars$ , TData$ , TError$ , TKey , TData > ,
95107 ) : QueryBuilder < TVars$ , TData$ , TError$ , TKey , TTags , TFlags > ;
96108
97109 withMiddleware < TVars$ = TVars , TData$ = TData , TError$ = TError > (
98- middleware : MiddlewareFn < TVars$ , TData$ , TError$ , TKey > ,
110+ middleware : MiddlewareFn < TVars$ , TData$ , TError$ , TKey , TData > ,
99111 config ?: Partial < BuilderConfig < TVars$ , TData$ , TError$ , TKey > > ,
100112 ) : QueryBuilder < TVars$ , TData$ , TError$ , TKey , TTags , TFlags > {
101113 const newBuilder = this as unknown as QueryBuilder < TVars$ , TData$ , TError$ , TKey , TTags , TFlags > ;
0 commit comments