@elliemae/pui-app-sdk 5.27.1 → 5.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -218,19 +218,39 @@ function RetryAsync(retries = 3, interval = 2e3, reThrowException = true) {
218
218
  function MemoizeSingleArgPrimitive(_target, _propertyKey, descriptor) {
219
219
  const originalMethod = descriptor.value;
220
220
  const cache = {};
221
- descriptor.value = function(arg) {
221
+ function isPrimitiveArg(arg) {
222
222
  const type = typeof arg;
223
- const isPrimitive = arg === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "undefined";
224
- if (!isPrimitive) {
225
- return originalMethod.call(this, arg);
226
- }
227
- const key = String(arg);
228
- if (Object.prototype.hasOwnProperty.call(cache, key)) {
229
- return cache[key];
223
+ return arg === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "undefined";
224
+ }
225
+ function getCachedResult(params) {
226
+ const { context, cacheObj, key, original, arg } = params;
227
+ if (Object.prototype.hasOwnProperty.call(cacheObj, key)) {
228
+ return cacheObj[key];
230
229
  }
231
- const result = originalMethod.call(this, arg);
232
- cache[key] = result;
230
+ const result = arg !== void 0 ? original.call(context, arg) : original.call(context);
231
+ cacheObj[key] = result;
233
232
  return result;
233
+ }
234
+ descriptor.value = function MemoizeSingleArgPrimitiveWrapper(...args) {
235
+ if (args.length === 0) {
236
+ return getCachedResult({
237
+ context: this,
238
+ cacheObj: cache,
239
+ key: "__NO_ARGS__",
240
+ original: originalMethod
241
+ });
242
+ }
243
+ if (args.length === 1 && isPrimitiveArg(args[0])) {
244
+ const key = String(args[0]);
245
+ return getCachedResult({
246
+ context: this,
247
+ cacheObj: cache,
248
+ key,
249
+ original: originalMethod,
250
+ arg: args[0]
251
+ });
252
+ }
253
+ return originalMethod.apply(this, args);
234
254
  };
235
255
  return descriptor;
236
256
  }
@@ -186,19 +186,39 @@ function RetryAsync(retries = 3, interval = 2e3, reThrowException = true) {
186
186
  function MemoizeSingleArgPrimitive(_target, _propertyKey, descriptor) {
187
187
  const originalMethod = descriptor.value;
188
188
  const cache = {};
189
- descriptor.value = function(arg) {
189
+ function isPrimitiveArg(arg) {
190
190
  const type = typeof arg;
191
- const isPrimitive = arg === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "undefined";
192
- if (!isPrimitive) {
193
- return originalMethod.call(this, arg);
194
- }
195
- const key = String(arg);
196
- if (Object.prototype.hasOwnProperty.call(cache, key)) {
197
- return cache[key];
191
+ return arg === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "undefined";
192
+ }
193
+ function getCachedResult(params) {
194
+ const { context, cacheObj, key, original, arg } = params;
195
+ if (Object.prototype.hasOwnProperty.call(cacheObj, key)) {
196
+ return cacheObj[key];
198
197
  }
199
- const result = originalMethod.call(this, arg);
200
- cache[key] = result;
198
+ const result = arg !== void 0 ? original.call(context, arg) : original.call(context);
199
+ cacheObj[key] = result;
201
200
  return result;
201
+ }
202
+ descriptor.value = function MemoizeSingleArgPrimitiveWrapper(...args) {
203
+ if (args.length === 0) {
204
+ return getCachedResult({
205
+ context: this,
206
+ cacheObj: cache,
207
+ key: "__NO_ARGS__",
208
+ original: originalMethod
209
+ });
210
+ }
211
+ if (args.length === 1 && isPrimitiveArg(args[0])) {
212
+ const key = String(args[0]);
213
+ return getCachedResult({
214
+ context: this,
215
+ cacheObj: cache,
216
+ key,
217
+ original: originalMethod,
218
+ arg: args[0]
219
+ });
220
+ }
221
+ return originalMethod.apply(this, args);
202
222
  };
203
223
  return descriptor;
204
224
  }
@@ -160,18 +160,44 @@ export declare function AsyncSingleExecution(_target: any, _propertyKey: string,
160
160
  */
161
161
  export declare function RetryAsync(retries?: number, interval?: number, reThrowException?: boolean): MethodDecorator;
162
162
  /**
163
- * Memoizes the result of a function with a single primitive argument.
164
- * Only works for functions that take exactly one primitive argument (string, number, boolean, symbol, null, or undefined).
165
- * Uses a simple object as the cache.
163
+ * Memoizes the result of a function with a single primitive argument or no arguments.
164
+ * Only caches results for functions that take exactly one primitive argument (string, number, boolean, symbol, null, or undefined)
165
+ * or no arguments at all. Uses a simple object as the cache.
166
166
  * @param _target
167
167
  * @param _propertyKey
168
168
  * @param descriptor
169
169
  * @example
170
+ * // Single primitive argument
170
171
  * class Example {
171
172
  * @MemoizeSingleArgPrimitive
172
173
  * double(x: number) {
173
174
  * return x * 2;
174
175
  * }
175
176
  * }
177
+ * const ex = new Example();
178
+ * ex.double(2); // Calls original, returns 4
179
+ * ex.double(2); // Returns cached result, 4
180
+ * @example
181
+ * // No arguments
182
+ * class ExampleNoArg {
183
+ * @MemoizeSingleArgPrimitive
184
+ * getRandom() {
185
+ * return Math.random();
186
+ * }
187
+ * }
188
+ * const ex2 = new ExampleNoArg();
189
+ * ex2.getRandom(); // Calls original, returns a value
190
+ * ex2.getRandom(); // Returns cached value
191
+ * @example
192
+ * // Not cached for non-primitive or multiple arguments
193
+ * class ExampleObj {
194
+ * @MemoizeSingleArgPrimitive
195
+ * sum(obj: { x: number }) {
196
+ * return obj.x + 1;
197
+ * }
198
+ * }
199
+ * const ex3 = new ExampleObj();
200
+ * ex3.sum({ x: 1 }); // Calls original
201
+ * ex3.sum({ x: 1 }); // Calls original again (not cached)
176
202
  */
177
- export declare function MemoizeSingleArgPrimitive<T extends string | number | boolean | symbol | null | undefined, R>(_target: any, _propertyKey: string, descriptor: TypedPropertyDescriptor<(arg: T) => R>): TypedPropertyDescriptor<(arg: T) => R>;
203
+ export declare function MemoizeSingleArgPrimitive<T extends string | number | boolean | symbol | null | undefined, R>(_target: any, _propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => R>): TypedPropertyDescriptor<(...args: any[]) => R>;