@@ -76,10 +76,15 @@ import { omit, pick } from "../index.js";
7676 * has access to resources created during input processing via closure.
7777 */
7878export type Customization <
79+ // The ctx object from the original function.
7980 Ctx extends Record < string , any > ,
81+ // The validators for the args the customization function consumes.
8082 CustomArgsValidator extends PropertyValidators ,
83+ // The ctx object produced: a patch applied to the original ctx.
8184 CustomCtx extends Record < string , any > ,
85+ // The args produced by the customization function.
8286 CustomMadeArgs extends Record < string , any > ,
87+ // Extra args that are passed to the input function.
8388 ExtraArgs extends Record < string , any > = Record < string , any > ,
8489> = {
8590 args : CustomArgsValidator ;
@@ -155,31 +160,30 @@ export function customCtxAndArgs<
155160 CustomMadeArgs ,
156161 ExtraArgs
157162> {
163+ // This is already the right type. This function just helps you define it.
158164 return objectWithArgsAndInput ;
159165}
160166
161167/**
162168 * A helper for defining a Customization when your mod doesn't need to add or remove
163169 * 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.
165171 * @returns A ctx delta to be applied to the original ctx.
166172 */
167173export function customCtx <
168174 InCtx extends Record < string , any > ,
169175 OutCtx extends Record < string , any > ,
170176 ExtraArgs extends Record < string , any > = Record < string , any > ,
171177> (
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 > {
180181 return {
181182 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+ } ) ,
183187 } ;
184188}
185189
0 commit comments