@@ -76,10 +76,15 @@ import { omit, pick } from "../index.js";
76
76
* has access to resources created during input processing via closure.
77
77
*/
78
78
export type Customization <
79
+ // The ctx object from the original function.
79
80
Ctx extends Record < string , any > ,
81
+ // The validators for the args the customization function consumes.
80
82
CustomArgsValidator extends PropertyValidators ,
83
+ // The ctx object produced: a patch applied to the original ctx.
81
84
CustomCtx extends Record < string , any > ,
85
+ // The args produced by the customization function.
82
86
CustomMadeArgs extends Record < string , any > ,
87
+ // Extra args that are passed to the input function.
83
88
ExtraArgs extends Record < string , any > = Record < string , any > ,
84
89
> = {
85
90
args : CustomArgsValidator ;
@@ -155,31 +160,30 @@ export function customCtxAndArgs<
155
160
CustomMadeArgs ,
156
161
ExtraArgs
157
162
> {
163
+ // This is already the right type. This function just helps you define it.
158
164
return objectWithArgsAndInput ;
159
165
}
160
166
161
167
/**
162
168
* A helper for defining a Customization when your mod doesn't need to add or remove
163
169
* anything from args.
164
- * @param mod A function that defines how to modify the ctx.
170
+ * @param modifyCtx A function that defines how to modify the ctx.
165
171
* @returns A ctx delta to be applied to the original ctx.
166
172
*/
167
173
export function customCtx <
168
174
InCtx extends Record < string , any > ,
169
175
OutCtx extends Record < string , any > ,
170
176
ExtraArgs extends Record < string , any > = Record < string , any > ,
171
177
> (
172
- mod : ( original : InCtx , extra : ExtraArgs ) => Promise < OutCtx > | OutCtx ,
173
- ) : Customization <
174
- InCtx ,
175
- Record < string , never > ,
176
- OutCtx ,
177
- Record < string , never > ,
178
- ExtraArgs
179
- > {
178
+ modifyCtx : ( original : InCtx , extra : ExtraArgs ) => Promise < OutCtx > | OutCtx ,
179
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
180
+ ) : Customization < InCtx , { } , OutCtx , object , ExtraArgs > {
180
181
return {
181
182
args : { } ,
182
- input : async ( ctx , _ , extra ) => ( { ctx : await mod ( ctx , extra ) , args : { } } ) ,
183
+ input : async ( ctx , _ , extra ) => ( {
184
+ ctx : await modifyCtx ( ctx , extra ) ,
185
+ args : { } ,
186
+ } ) ,
183
187
} ;
184
188
}
185
189
0 commit comments