vona-module-a-caching 5.0.3 → 5.0.4
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/dist/.metadata/index.d.ts +15 -0
- package/dist/.metadata/index.js +3 -0
- package/dist/bean/aopMethod.cachingClear.d.ts +9 -0
- package/dist/bean/aopMethod.cachingClear.js +23 -0
- package/dist/bean/aopMethod.cachingDel.d.ts +9 -0
- package/dist/bean/aopMethod.cachingDel.js +29 -0
- package/dist/bean/aopMethod.cachingGet.d.ts +4 -3
- package/dist/bean/aopMethod.cachingGet.js +13 -4
- package/dist/bean/aopMethod.cachingSet.d.ts +11 -0
- package/dist/bean/aopMethod.cachingSet.js +31 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/caching.d.ts +15 -0
- package/dist/lib/caching.js +19 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.js +50 -0
- package/dist/types/caching.d.ts +11 -0
- package/dist/types/caching.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
/** aopMethod: begin */
|
|
2
|
+
export * from '../bean/aopMethod.cachingClear.ts';
|
|
3
|
+
export * from '../bean/aopMethod.cachingDel.ts';
|
|
2
4
|
export * from '../bean/aopMethod.cachingGet.ts';
|
|
5
|
+
export * from '../bean/aopMethod.cachingSet.ts';
|
|
6
|
+
import type { IAopMethodOptionsCachingClear } from '../bean/aopMethod.cachingClear.ts';
|
|
7
|
+
import type { IAopMethodOptionsCachingDel } from '../bean/aopMethod.cachingDel.ts';
|
|
3
8
|
import type { IAopMethodOptionsCachingGet } from '../bean/aopMethod.cachingGet.ts';
|
|
9
|
+
import type { IAopMethodOptionsCachingSet } from '../bean/aopMethod.cachingSet.ts';
|
|
4
10
|
import 'vona';
|
|
5
11
|
declare module 'vona-module-a-aspect' {
|
|
6
12
|
interface IAopMethodRecord {
|
|
13
|
+
'a-caching:cachingClear': IAopMethodOptionsCachingClear;
|
|
14
|
+
'a-caching:cachingDel': IAopMethodOptionsCachingDel;
|
|
7
15
|
'a-caching:cachingGet': IAopMethodOptionsCachingGet;
|
|
16
|
+
'a-caching:cachingSet': IAopMethodOptionsCachingSet;
|
|
8
17
|
}
|
|
9
18
|
}
|
|
10
19
|
declare module 'vona-module-a-caching' {
|
|
20
|
+
interface AopMethodCachingClear {
|
|
21
|
+
}
|
|
22
|
+
interface AopMethodCachingDel {
|
|
23
|
+
}
|
|
11
24
|
interface AopMethodCachingGet {
|
|
12
25
|
}
|
|
26
|
+
interface AopMethodCachingSet {
|
|
27
|
+
}
|
|
13
28
|
}
|
|
14
29
|
/** aopMethod: end */
|
|
15
30
|
/** scope: begin */
|
package/dist/.metadata/index.js
CHANGED
|
@@ -6,7 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
/* eslint-disable */
|
|
8
8
|
/** aopMethod: begin */
|
|
9
|
+
export * from "../bean/aopMethod.cachingClear.js";
|
|
10
|
+
export * from "../bean/aopMethod.cachingDel.js";
|
|
9
11
|
export * from "../bean/aopMethod.cachingGet.js";
|
|
12
|
+
export * from "../bean/aopMethod.cachingSet.js";
|
|
10
13
|
import 'vona';
|
|
11
14
|
/** aopMethod: end */
|
|
12
15
|
/** scope: begin */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
|
+
import type { IAopMethodExecute, IDecoratorAopMethodOptions } from 'vona-module-a-aspect';
|
|
3
|
+
import type { TypeCachingActionClearOptions } from '../types/caching.ts';
|
|
4
|
+
import { BeanAopMethodBase } from 'vona';
|
|
5
|
+
export interface IAopMethodOptionsCachingClear extends IDecoratorAopMethodOptions, TypeCachingActionClearOptions {
|
|
6
|
+
}
|
|
7
|
+
export declare class AopMethodCachingClear extends BeanAopMethodBase implements IAopMethodExecute {
|
|
8
|
+
execute(options: IAopMethodOptionsCachingClear, _args: [], next: Next, _receiver: any, _prop: string): Promise<any>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
8
|
+
import { AopMethod } from 'vona-module-a-aspect';
|
|
9
|
+
let AopMethodCachingClear = class AopMethodCachingClear extends BeanAopMethodBase {
|
|
10
|
+
async execute(options, _args, next, _receiver, _prop) {
|
|
11
|
+
// next
|
|
12
|
+
const value = await next();
|
|
13
|
+
// cache
|
|
14
|
+
const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
|
|
15
|
+
await cache.clear(options);
|
|
16
|
+
// ok
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
AopMethodCachingClear = __decorate([
|
|
21
|
+
AopMethod()
|
|
22
|
+
], AopMethodCachingClear);
|
|
23
|
+
export { AopMethodCachingClear };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
|
+
import type { IAopMethodExecute, IDecoratorAopMethodOptions } from 'vona-module-a-aspect';
|
|
3
|
+
import type { TypeCachingActionOptions } from '../types/caching.ts';
|
|
4
|
+
import { BeanAopMethodBase } from 'vona';
|
|
5
|
+
export interface IAopMethodOptionsCachingDel extends IDecoratorAopMethodOptions, TypeCachingActionOptions {
|
|
6
|
+
}
|
|
7
|
+
export declare class AopMethodCachingDel extends BeanAopMethodBase implements IAopMethodExecute {
|
|
8
|
+
execute(options: IAopMethodOptionsCachingDel, args: [], next: Next, receiver: any, prop: string): Promise<any>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { isNil } from '@cabloy/utils';
|
|
8
|
+
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
9
|
+
import { AopMethod } from 'vona-module-a-aspect';
|
|
10
|
+
import { combineCachingKey } from "../lib/utils.js";
|
|
11
|
+
let AopMethodCachingDel = class AopMethodCachingDel extends BeanAopMethodBase {
|
|
12
|
+
async execute(options, args, next, receiver, prop) {
|
|
13
|
+
// next
|
|
14
|
+
const value = await next();
|
|
15
|
+
// key
|
|
16
|
+
const key = combineCachingKey(options, args, receiver, prop);
|
|
17
|
+
if (isNil(key) || key === false || key === '')
|
|
18
|
+
return value;
|
|
19
|
+
// cache
|
|
20
|
+
const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
|
|
21
|
+
await cache.del(key, options);
|
|
22
|
+
// ok
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
AopMethodCachingDel = __decorate([
|
|
27
|
+
AopMethod()
|
|
28
|
+
], AopMethodCachingDel);
|
|
29
|
+
export { AopMethodCachingDel };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Next
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
2
|
import type { IAopMethodExecute, IDecoratorAopMethodOptions } from 'vona-module-a-aspect';
|
|
3
|
+
import type { TypeCachingActionOptions } from '../types/caching.ts';
|
|
3
4
|
import { BeanAopMethodBase } from 'vona';
|
|
4
|
-
export interface IAopMethodOptionsCachingGet extends IDecoratorAopMethodOptions {
|
|
5
|
+
export interface IAopMethodOptionsCachingGet extends IDecoratorAopMethodOptions, TypeCachingActionOptions {
|
|
5
6
|
}
|
|
6
7
|
export declare class AopMethodCachingGet extends BeanAopMethodBase implements IAopMethodExecute {
|
|
7
|
-
execute(
|
|
8
|
+
execute(options: IAopMethodOptionsCachingGet, args: [], next: Next, receiver: any, prop: string): Promise<any>;
|
|
8
9
|
}
|
|
@@ -4,12 +4,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
7
|
+
import { isNil } from '@cabloy/utils';
|
|
8
|
+
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
8
9
|
import { AopMethod } from 'vona-module-a-aspect';
|
|
10
|
+
import { combineCachingKey } from "../lib/utils.js";
|
|
9
11
|
let AopMethodCachingGet = class AopMethodCachingGet extends BeanAopMethodBase {
|
|
10
|
-
execute(
|
|
11
|
-
//
|
|
12
|
-
|
|
12
|
+
async execute(options, args, next, receiver, prop) {
|
|
13
|
+
// key
|
|
14
|
+
const key = combineCachingKey(options, args, receiver, prop);
|
|
15
|
+
if (isNil(key) || key === false || key === '')
|
|
16
|
+
return next();
|
|
17
|
+
// cache
|
|
18
|
+
const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
|
|
19
|
+
return await cache.get(key, Object.assign({}, options, { get: () => {
|
|
20
|
+
return next();
|
|
21
|
+
} }));
|
|
13
22
|
}
|
|
14
23
|
};
|
|
15
24
|
AopMethodCachingGet = __decorate([
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Next } from 'vona';
|
|
2
|
+
import type { IAopMethodExecute, IDecoratorAopMethodOptions } from 'vona-module-a-aspect';
|
|
3
|
+
import type { TypeCacheValueFn, TypeCachingActionOptions } from '../types/caching.ts';
|
|
4
|
+
import { BeanAopMethodBase } from 'vona';
|
|
5
|
+
export interface IAopMethodOptionsCachingSet extends IDecoratorAopMethodOptions, TypeCachingActionOptions {
|
|
6
|
+
cacheValue?: any;
|
|
7
|
+
cacheValueFn?: TypeCacheValueFn | string;
|
|
8
|
+
}
|
|
9
|
+
export declare class AopMethodCachingSet extends BeanAopMethodBase implements IAopMethodExecute {
|
|
10
|
+
execute(options: IAopMethodOptionsCachingSet, args: [], next: Next, receiver: any, prop: string): Promise<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { isNil } from '@cabloy/utils';
|
|
8
|
+
import { BeanAopMethodBase, beanFullNameFromOnionName } from 'vona';
|
|
9
|
+
import { AopMethod } from 'vona-module-a-aspect';
|
|
10
|
+
import { combineCachingKey, combineCachingValue } from "../lib/utils.js";
|
|
11
|
+
let AopMethodCachingSet = class AopMethodCachingSet extends BeanAopMethodBase {
|
|
12
|
+
async execute(options, args, next, receiver, prop) {
|
|
13
|
+
// next
|
|
14
|
+
const value = await next();
|
|
15
|
+
// key
|
|
16
|
+
const key = combineCachingKey(options, args, receiver, prop);
|
|
17
|
+
if (isNil(key) || key === false || key === '')
|
|
18
|
+
return value;
|
|
19
|
+
// value
|
|
20
|
+
const cacheValue = combineCachingValue(options, args, receiver, prop, value);
|
|
21
|
+
// cache
|
|
22
|
+
const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
|
|
23
|
+
await cache.set(cacheValue, key, options);
|
|
24
|
+
// ok
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
AopMethodCachingSet = __decorate([
|
|
29
|
+
AopMethod()
|
|
30
|
+
], AopMethodCachingSet);
|
|
31
|
+
export { AopMethodCachingSet };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IAopMethodOptionsCachingClear } from '../bean/aopMethod.cachingClear.ts';
|
|
2
|
+
import type { IAopMethodOptionsCachingDel } from '../bean/aopMethod.cachingDel.ts';
|
|
3
|
+
import type { IAopMethodOptionsCachingGet } from '../bean/aopMethod.cachingGet.ts';
|
|
4
|
+
import type { IAopMethodOptionsCachingSet } from '../bean/aopMethod.cachingSet.ts';
|
|
5
|
+
declare function Get(options?: Partial<IAopMethodOptionsCachingGet>): MethodDecorator;
|
|
6
|
+
declare function Set(options?: Partial<IAopMethodOptionsCachingSet>): MethodDecorator;
|
|
7
|
+
declare function Del(options?: Partial<IAopMethodOptionsCachingDel>): MethodDecorator;
|
|
8
|
+
declare function Clear(options?: Partial<IAopMethodOptionsCachingClear>): MethodDecorator;
|
|
9
|
+
export declare const Caching: {
|
|
10
|
+
get: typeof Get;
|
|
11
|
+
set: typeof Set;
|
|
12
|
+
del: typeof Del;
|
|
13
|
+
clear: typeof Clear;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Aspect } from 'vona-module-a-aspect';
|
|
2
|
+
function Get(options) {
|
|
3
|
+
return Aspect.aopMethod('a-caching:cachingGet', options);
|
|
4
|
+
}
|
|
5
|
+
function Set(options) {
|
|
6
|
+
return Aspect.aopMethod('a-caching:cachingSet', options);
|
|
7
|
+
}
|
|
8
|
+
function Del(options) {
|
|
9
|
+
return Aspect.aopMethod('a-caching:cachingDel', options);
|
|
10
|
+
}
|
|
11
|
+
function Clear(options) {
|
|
12
|
+
return Aspect.aopMethod('a-caching:cachingClear', options);
|
|
13
|
+
}
|
|
14
|
+
export const Caching = {
|
|
15
|
+
get: Get,
|
|
16
|
+
set: Set,
|
|
17
|
+
del: Del,
|
|
18
|
+
clear: Clear,
|
|
19
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BeanBase } from 'vona';
|
|
2
|
+
import type { IAopMethodOptionsCachingSet } from '../bean/aopMethod.cachingSet.ts';
|
|
3
|
+
import type { TypeCachingActionOptions } from '../types/caching.ts';
|
|
4
|
+
export declare function combineCachingKey(options: TypeCachingActionOptions, args: [], receiver: BeanBase, prop: string): any;
|
|
5
|
+
export declare function combineCachingValue(options: IAopMethodOptionsCachingSet, args: [], receiver: BeanBase, prop: string, value: any): any;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { evaluateExpressions, isNil } from '@cabloy/utils';
|
|
2
|
+
import { cast } from 'vona';
|
|
3
|
+
import { getKeyHash } from 'vona-module-a-cache';
|
|
4
|
+
export function combineCachingKey(options, args, receiver, prop) {
|
|
5
|
+
// cacheKeyFn
|
|
6
|
+
if (options.cacheKeyFn) {
|
|
7
|
+
if (typeof options.cacheKeyFn === 'string') {
|
|
8
|
+
if (!receiver[options.cacheKeyFn]) {
|
|
9
|
+
throw new Error(`cacheKeyFn not found: ${cast(receiver).$beanFullName}#${options.cacheKeyFn}`);
|
|
10
|
+
}
|
|
11
|
+
return receiver[options.cacheKeyFn](args, prop, options, receiver);
|
|
12
|
+
}
|
|
13
|
+
return options.cacheKeyFn.call(receiver, args, prop, options, receiver);
|
|
14
|
+
}
|
|
15
|
+
// cacheKey
|
|
16
|
+
if (options.cacheKey) {
|
|
17
|
+
return evaluateExpressions(options.cacheKey, {
|
|
18
|
+
args,
|
|
19
|
+
prop,
|
|
20
|
+
options,
|
|
21
|
+
self: receiver,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// default
|
|
25
|
+
return `${cast(receiver).$beanFullName}_${options.cacheProp ?? prop}_${getKeyHash(args)}`;
|
|
26
|
+
}
|
|
27
|
+
export function combineCachingValue(options, args, receiver, prop, value) {
|
|
28
|
+
// cacheValueFn
|
|
29
|
+
if (!isNil(options.cacheValueFn)) {
|
|
30
|
+
if (typeof options.cacheValueFn === 'string') {
|
|
31
|
+
if (!receiver[options.cacheValueFn]) {
|
|
32
|
+
throw new Error(`cacheValueFn not found: ${cast(receiver).$beanFullName}#${options.cacheValueFn}`);
|
|
33
|
+
}
|
|
34
|
+
return receiver[options.cacheValueFn](value, args, prop, options, receiver);
|
|
35
|
+
}
|
|
36
|
+
return options.cacheValueFn.call(receiver, value, args, prop, options, receiver);
|
|
37
|
+
}
|
|
38
|
+
// cacheValue
|
|
39
|
+
if (!isNil(options.cacheValue)) {
|
|
40
|
+
return evaluateExpressions(options.cacheValue, {
|
|
41
|
+
value,
|
|
42
|
+
args,
|
|
43
|
+
prop,
|
|
44
|
+
options,
|
|
45
|
+
self: receiver,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// default
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BeanBase } from 'vona';
|
|
2
|
+
import type { ISummerCacheRecord, TSummerCacheActionOptions } from 'vona-module-a-summer';
|
|
3
|
+
export type TypeCacheKeyFn = (args: [], prop: string, options: TypeCachingActionOptions, receiver: BeanBase) => any;
|
|
4
|
+
export type TypeCacheValueFn = (value: any, args: [], prop: string, options: TypeCachingActionOptions, receiver: BeanBase) => any;
|
|
5
|
+
export type TypeCachingActionOptions = Pick<TSummerCacheActionOptions<unknown, unknown>, 'mode' | 'ignoreNull' | 'ttl' | 'updateAgeOnGet' | 'broadcastOnSet'> & {
|
|
6
|
+
cacheName: keyof ISummerCacheRecord;
|
|
7
|
+
cacheKey?: any;
|
|
8
|
+
cacheKeyFn?: TypeCacheKeyFn | string;
|
|
9
|
+
cacheProp?: string;
|
|
10
|
+
};
|
|
11
|
+
export type TypeCachingActionClearOptions = Omit<TypeCachingActionOptions, 'cacheKey' | 'cacheKeyFn' | 'cacheProp'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './caching.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./caching.js";
|