@travetto/cache 7.0.0-rc.0 → 7.0.0-rc.1
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.
- package/package.json +1 -1
- package/src/decorator.ts +8 -8
package/package.json
CHANGED
package/src/decorator.ts
CHANGED
|
@@ -21,15 +21,15 @@ export function Cache<F extends string, U extends Record<F, CacheService>>(
|
|
|
21
21
|
config = cfg;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
const dec = function <R extends Promise<unknown>>(target: U & CacheAware, propertyKey: string,
|
|
24
|
+
const dec = function <R extends Promise<unknown>>(target: U & CacheAware, propertyKey: string, descriptor: MethodDescriptor<R>): void {
|
|
25
25
|
config.keySpace ??= `${target.constructor.name}.${propertyKey}`;
|
|
26
26
|
(target[CacheConfigSymbol] ??= {})[propertyKey] = config;
|
|
27
|
-
const handler =
|
|
27
|
+
const handler = descriptor.value!;
|
|
28
28
|
// Allows for DI to run, as the service will not be bound until after the decorator is run
|
|
29
|
-
|
|
29
|
+
descriptor.value = castTo(function (this: typeof target) {
|
|
30
30
|
return this[field].cache(this, propertyKey, handler, [...arguments]);
|
|
31
31
|
});
|
|
32
|
-
Object.defineProperty(
|
|
32
|
+
Object.defineProperty(descriptor.value, 'name', { value: propertyKey, writable: false });
|
|
33
33
|
};
|
|
34
34
|
return castTo(dec);
|
|
35
35
|
}
|
|
@@ -42,14 +42,14 @@ export function Cache<F extends string, U extends Record<F, CacheService>>(
|
|
|
42
42
|
* @kind decorator
|
|
43
43
|
*/
|
|
44
44
|
export function EvictCache<F extends string, U extends Record<F, CacheService>>(field: F, config: CoreCacheConfig = {}) {
|
|
45
|
-
return function <R extends Promise<unknown>>(target: U & CacheAware, propertyKey: string,
|
|
45
|
+
return function <R extends Promise<unknown>>(target: U & CacheAware, propertyKey: string, descriptor: MethodDescriptor<R>): void {
|
|
46
46
|
config.keySpace ??= `${target.constructor.name}.${propertyKey}`;
|
|
47
47
|
(target[EvictConfigSymbol] ??= {})[propertyKey] = config;
|
|
48
|
-
const handler =
|
|
48
|
+
const handler = descriptor.value!;
|
|
49
49
|
// Allows for DI to run, as the service will not be bound until after the decorator is run
|
|
50
|
-
|
|
50
|
+
descriptor.value = castTo(function (this: typeof target) {
|
|
51
51
|
return this[field].evict(this, propertyKey, handler, [...arguments]);
|
|
52
52
|
});
|
|
53
|
-
Object.defineProperty(
|
|
53
|
+
Object.defineProperty(descriptor.value, 'name', { value: propertyKey, writable: false });
|
|
54
54
|
};
|
|
55
55
|
}
|