@@ -72,9 +72,10 @@ const isOptionsWithDataIndexArgument = (
72
72
*
73
73
* ```
74
74
*/
75
- const makeIdempotent = < Func extends AnyFunction > (
75
+ /* const makeIdempotent = <Func extends AnyFunction>(
76
76
fn: Func,
77
- options : ItempotentFunctionOptions < Parameters < Func > >
77
+ options: ItempotentFunctionOptions<Parameters<Func>>,
78
+ thisArg: Handler
78
79
): ((...args: Parameters<Func>) => ReturnType<Func>) => {
79
80
const { persistenceStore, config } = options;
80
81
const idempotencyConfig = config ? config : new IdempotencyConfig({});
@@ -101,8 +102,44 @@ const makeIdempotent = <Func extends AnyFunction>(
101
102
persistenceStore: persistenceStore,
102
103
functionArguments: args,
103
104
functionPayloadToBeHashed,
105
+ thisArg,
104
106
}).handle() as ReturnType<Func>;
105
107
};
106
- } ;
108
+ }; */
109
+ // eslint-disable-next-line func-style
110
+ function makeIdempotent < Func extends AnyFunction > (
111
+ fn : Func ,
112
+ options : ItempotentFunctionOptions < Parameters < Func > >
113
+ ) : ( ...args : Parameters < Func > ) => ReturnType < Func > {
114
+ const { persistenceStore, config } = options ;
115
+ const idempotencyConfig = config ? config : new IdempotencyConfig ( { } ) ;
116
+
117
+ if ( ! idempotencyConfig . isEnabled ( ) ) return fn ;
118
+
119
+ return function ( ...args : Parameters < Func > ) : ReturnType < Func > {
120
+ let functionPayloadToBeHashed ;
121
+
122
+ if ( isFnHandler ( fn , args ) ) {
123
+ idempotencyConfig . registerLambdaContext ( args [ 1 ] ) ;
124
+ functionPayloadToBeHashed = args [ 0 ] ;
125
+ } else {
126
+ if ( isOptionsWithDataIndexArgument ( options ) ) {
127
+ functionPayloadToBeHashed = args [ options . dataIndexArgument ] ;
128
+ } else {
129
+ functionPayloadToBeHashed = args [ 0 ] ;
130
+ }
131
+ }
132
+
133
+ return new IdempotencyHandler ( {
134
+ functionToMakeIdempotent : fn ,
135
+ idempotencyConfig : idempotencyConfig ,
136
+ persistenceStore : persistenceStore ,
137
+ functionArguments : args ,
138
+ functionPayloadToBeHashed,
139
+ // @ts -expect-error abc
140
+ thisArg : this ,
141
+ } ) . handle ( ) as ReturnType < Func > ;
142
+ } ;
143
+ }
107
144
108
145
export { makeIdempotent } ;
0 commit comments