vona-module-a-caching 5.0.7 → 5.0.8

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/index.js CHANGED
@@ -1,3 +1,159 @@
1
- export * from "./.metadata/index.js";
2
- export * from "./lib/index.js";
3
- export * from "./types/index.js";
1
+ import { BeanInfo, BeanAopMethodBase, beanFullNameFromOnionName, cast, BeanScopeBase } from 'vona';
2
+ import { AopMethod, Aspect } from 'vona-module-a-aspect';
3
+ import { evaluateExpressions, isNil } from '@cabloy/utils';
4
+ import { getKeyHash } from 'vona-module-a-cache';
5
+ import { Scope } from 'vona-module-a-bean';
6
+
7
+ var _dec$4, _dec2$4, _class$4;
8
+ let AopMethodCachingClear = (_dec$4 = AopMethod(), _dec2$4 = BeanInfo({
9
+ module: "a-caching"
10
+ }), _dec$4(_class$4 = _dec2$4(_class$4 = class AopMethodCachingClear extends BeanAopMethodBase {
11
+ async execute(options, _args, next, _receiver, _prop) {
12
+ // next
13
+ const value = await next();
14
+ // cache
15
+ const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
16
+ await cache.clear(options);
17
+ // ok
18
+ return value;
19
+ }
20
+ }) || _class$4) || _class$4);
21
+
22
+ function combineCachingKey(options, args, receiver, prop) {
23
+ // cacheKeyFn
24
+ if (options.cacheKeyFn) {
25
+ if (typeof options.cacheKeyFn === 'string') {
26
+ if (!receiver[options.cacheKeyFn]) {
27
+ throw new Error(`cacheKeyFn not found: ${cast(receiver).$beanFullName}#${options.cacheKeyFn}`);
28
+ }
29
+ return receiver[options.cacheKeyFn](args, prop, options, receiver);
30
+ }
31
+ return options.cacheKeyFn.call(receiver, args, prop, options, receiver);
32
+ }
33
+ // cacheKey
34
+ if (options.cacheKey) {
35
+ return evaluateExpressions(options.cacheKey, {
36
+ args,
37
+ prop,
38
+ options,
39
+ self: receiver,
40
+ app: cast(receiver).app,
41
+ ctx: cast(receiver).ctx
42
+ });
43
+ }
44
+ // default
45
+ return `${cast(receiver).$beanFullName}_${options.cacheProp ?? prop}_${getKeyHash(args)}`;
46
+ }
47
+ function combineCachingValue(options, args, receiver, prop, value) {
48
+ // cacheValueFn
49
+ if (!isNil(options.cacheValueFn)) {
50
+ if (typeof options.cacheValueFn === 'string') {
51
+ if (!receiver[options.cacheValueFn]) {
52
+ throw new Error(`cacheValueFn not found: ${cast(receiver).$beanFullName}#${options.cacheValueFn}`);
53
+ }
54
+ return receiver[options.cacheValueFn](value, args, prop, options, receiver);
55
+ }
56
+ return options.cacheValueFn.call(receiver, value, args, prop, options, receiver);
57
+ }
58
+ // cacheValue
59
+ if (!isNil(options.cacheValue)) {
60
+ return evaluateExpressions(options.cacheValue, {
61
+ value,
62
+ args,
63
+ prop,
64
+ options,
65
+ self: receiver,
66
+ app: cast(receiver).app,
67
+ ctx: cast(receiver).ctx
68
+ });
69
+ }
70
+ // default
71
+ return value;
72
+ }
73
+ function isCachingKeyValid(key) {
74
+ return !isNil(key) && key !== false && key !== '';
75
+ }
76
+
77
+ var _dec$3, _dec2$3, _class$3;
78
+ let AopMethodCachingDel = (_dec$3 = AopMethod(), _dec2$3 = BeanInfo({
79
+ module: "a-caching"
80
+ }), _dec$3(_class$3 = _dec2$3(_class$3 = class AopMethodCachingDel extends BeanAopMethodBase {
81
+ async execute(options, args, next, receiver, prop) {
82
+ // next
83
+ const value = await next();
84
+ // key
85
+ const key = combineCachingKey(options, args, receiver, prop);
86
+ if (!isCachingKeyValid(key)) return value;
87
+ // cache
88
+ const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
89
+ await cache.del(key, options);
90
+ // ok
91
+ return value;
92
+ }
93
+ }) || _class$3) || _class$3);
94
+
95
+ var _dec$2, _dec2$2, _class$2;
96
+ let AopMethodCachingGet = (_dec$2 = AopMethod(), _dec2$2 = BeanInfo({
97
+ module: "a-caching"
98
+ }), _dec$2(_class$2 = _dec2$2(_class$2 = class AopMethodCachingGet extends BeanAopMethodBase {
99
+ async execute(options, args, next, receiver, prop) {
100
+ // key
101
+ const key = combineCachingKey(options, args, receiver, prop);
102
+ if (!isCachingKeyValid(key)) return next();
103
+ // cache
104
+ const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
105
+ return await cache.get(key, Object.assign({}, options, {
106
+ get: () => {
107
+ return next();
108
+ }
109
+ }));
110
+ }
111
+ }) || _class$2) || _class$2);
112
+
113
+ var _dec$1, _dec2$1, _class$1;
114
+ let AopMethodCachingSet = (_dec$1 = AopMethod(), _dec2$1 = BeanInfo({
115
+ module: "a-caching"
116
+ }), _dec$1(_class$1 = _dec2$1(_class$1 = class AopMethodCachingSet extends BeanAopMethodBase {
117
+ async execute(options, args, next, receiver, prop) {
118
+ // next
119
+ const value = await next();
120
+ // key
121
+ const key = combineCachingKey(options, args, receiver, prop);
122
+ if (!isCachingKeyValid(key)) return value;
123
+ // value
124
+ const cacheValue = combineCachingValue(options, args, receiver, prop, value);
125
+ // cache
126
+ const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
127
+ await cache.set(cacheValue, key, options);
128
+ // ok
129
+ return value;
130
+ }
131
+ }) || _class$1) || _class$1);
132
+
133
+ var _dec, _dec2, _class;
134
+ let ScopeModuleACaching = (_dec = Scope(), _dec2 = BeanInfo({
135
+ module: "a-caching"
136
+ }), _dec(_class = _dec2(_class = class ScopeModuleACaching extends BeanScopeBase {}) || _class) || _class);
137
+
138
+ /** scope: end */
139
+
140
+ function Get(options) {
141
+ return Aspect.aopMethod('a-caching:cachingGet', options);
142
+ }
143
+ function Set(options) {
144
+ return Aspect.aopMethod('a-caching:cachingSet', options);
145
+ }
146
+ function Del(options) {
147
+ return Aspect.aopMethod('a-caching:cachingDel', options);
148
+ }
149
+ function Clear(options) {
150
+ return Aspect.aopMethod('a-caching:cachingClear', options);
151
+ }
152
+ const Caching = {
153
+ get: Get,
154
+ set: Set,
155
+ del: Del,
156
+ clear: Clear
157
+ };
158
+
159
+ export { AopMethodCachingClear, AopMethodCachingDel, AopMethodCachingGet, AopMethodCachingSet, Caching, ScopeModuleACaching, combineCachingKey, combineCachingValue, isCachingKeyValid };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-caching",
3
3
  "type": "module",
4
- "version": "5.0.7",
4
+ "version": "5.0.8",
5
5
  "title": "a-caching",
6
6
  "vonaModule": {
7
7
  "dependencies": {}
@@ -27,6 +27,6 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "clean": "rimraf dist tsconfig.build.tsbuildinfo",
30
- "tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
30
+ "tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
31
31
  }
32
32
  }
@@ -1,25 +0,0 @@
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
- /* eslint-disable */
8
- /** aopMethod: begin */
9
- export * from "../bean/aopMethod.cachingClear.js";
10
- export * from "../bean/aopMethod.cachingDel.js";
11
- export * from "../bean/aopMethod.cachingGet.js";
12
- export * from "../bean/aopMethod.cachingSet.js";
13
- import 'vona';
14
- /** aopMethod: end */
15
- /** scope: begin */
16
- import { BeanScopeBase } from 'vona';
17
- import { Scope } from 'vona-module-a-bean';
18
- let ScopeModuleACaching = class ScopeModuleACaching extends BeanScopeBase {
19
- };
20
- ScopeModuleACaching = __decorate([
21
- Scope()
22
- ], ScopeModuleACaching);
23
- export { ScopeModuleACaching };
24
- import 'vona';
25
- /** scope: end */
@@ -1,2 +0,0 @@
1
- export const __ThisModule__ = 'a-caching';
2
- export { ScopeModuleACaching as ScopeModule } from "./index.js";
@@ -1,23 +0,0 @@
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 };
@@ -1,28 +0,0 @@
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
- import { combineCachingKey, isCachingKeyValid } from "../lib/utils.js";
10
- let AopMethodCachingDel = class AopMethodCachingDel extends BeanAopMethodBase {
11
- async execute(options, args, next, receiver, prop) {
12
- // next
13
- const value = await next();
14
- // key
15
- const key = combineCachingKey(options, args, receiver, prop);
16
- if (!isCachingKeyValid(key))
17
- return value;
18
- // cache
19
- const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
20
- await cache.del(key, options);
21
- // ok
22
- return value;
23
- }
24
- };
25
- AopMethodCachingDel = __decorate([
26
- AopMethod()
27
- ], AopMethodCachingDel);
28
- export { AopMethodCachingDel };
@@ -1,26 +0,0 @@
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
- import { combineCachingKey, isCachingKeyValid } from "../lib/utils.js";
10
- let AopMethodCachingGet = class AopMethodCachingGet extends BeanAopMethodBase {
11
- async execute(options, args, next, receiver, prop) {
12
- // key
13
- const key = combineCachingKey(options, args, receiver, prop);
14
- if (!isCachingKeyValid(key))
15
- return next();
16
- // cache
17
- const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
18
- return await cache.get(key, Object.assign({}, options, { get: () => {
19
- return next();
20
- } }));
21
- }
22
- };
23
- AopMethodCachingGet = __decorate([
24
- AopMethod()
25
- ], AopMethodCachingGet);
26
- export { AopMethodCachingGet };
@@ -1,30 +0,0 @@
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
- import { combineCachingKey, combineCachingValue, isCachingKeyValid } from "../lib/utils.js";
10
- let AopMethodCachingSet = class AopMethodCachingSet extends BeanAopMethodBase {
11
- async execute(options, args, next, receiver, prop) {
12
- // next
13
- const value = await next();
14
- // key
15
- const key = combineCachingKey(options, args, receiver, prop);
16
- if (!isCachingKeyValid(key))
17
- return value;
18
- // value
19
- const cacheValue = combineCachingValue(options, args, receiver, prop, value);
20
- // cache
21
- const cache = this.bean.summer.cache(beanFullNameFromOnionName(options.cacheName, 'summerCache'));
22
- await cache.set(cacheValue, key, options);
23
- // ok
24
- return value;
25
- }
26
- };
27
- AopMethodCachingSet = __decorate([
28
- AopMethod()
29
- ], AopMethodCachingSet);
30
- export { AopMethodCachingSet };
@@ -1,19 +0,0 @@
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
- };
package/dist/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./caching.js";
2
- export * from "./utils.js";
package/dist/lib/utils.js DELETED
@@ -1,57 +0,0 @@
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
- app: cast(receiver).app,
23
- ctx: cast(receiver).ctx,
24
- });
25
- }
26
- // default
27
- return `${cast(receiver).$beanFullName}_${options.cacheProp ?? prop}_${getKeyHash(args)}`;
28
- }
29
- export function combineCachingValue(options, args, receiver, prop, value) {
30
- // cacheValueFn
31
- if (!isNil(options.cacheValueFn)) {
32
- if (typeof options.cacheValueFn === 'string') {
33
- if (!receiver[options.cacheValueFn]) {
34
- throw new Error(`cacheValueFn not found: ${cast(receiver).$beanFullName}#${options.cacheValueFn}`);
35
- }
36
- return receiver[options.cacheValueFn](value, args, prop, options, receiver);
37
- }
38
- return options.cacheValueFn.call(receiver, value, args, prop, options, receiver);
39
- }
40
- // cacheValue
41
- if (!isNil(options.cacheValue)) {
42
- return evaluateExpressions(options.cacheValue, {
43
- value,
44
- args,
45
- prop,
46
- options,
47
- self: receiver,
48
- app: cast(receiver).app,
49
- ctx: cast(receiver).ctx,
50
- });
51
- }
52
- // default
53
- return value;
54
- }
55
- export function isCachingKeyValid(key) {
56
- return !isNil(key) && key !== false && key !== '';
57
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from "./caching.js";