@sdflc/backend-helpers 1.0.101 → 1.0.102
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/build/DataCache.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ declare class DataCache implements LoaderInterface {
|
|
|
9
9
|
init(batchFunction: any, keyPrefix?: string, context?: any): void;
|
|
10
10
|
load(key: any): any;
|
|
11
11
|
loadMany(keys: any[]): any;
|
|
12
|
-
|
|
12
|
+
prime(key: any, value: any): this;
|
|
13
|
+
clear(key: any | any[]): this;
|
|
14
|
+
clearAll(): this;
|
|
13
15
|
}
|
|
14
16
|
export { DataCache };
|
package/build/DataCache.js
CHANGED
|
@@ -16,13 +16,11 @@ class DataCache {
|
|
|
16
16
|
redisClient;
|
|
17
17
|
constructor(props) {
|
|
18
18
|
const { loaderFn, keyPrefix, context, buildKey, redisClient, table } = props || {};
|
|
19
|
-
|
|
20
|
-
props
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
this.config = props;
|
|
19
|
+
this.config = {
|
|
20
|
+
...props,
|
|
21
|
+
idField: props?.idField || _1.FIELDS.ID,
|
|
22
|
+
idFieldAs: props?.idFieldAs || _1.FIELDS.ID,
|
|
23
|
+
};
|
|
26
24
|
this.redisClient = redisClient;
|
|
27
25
|
this.buildKey = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
|
|
28
26
|
this.batchLoaderDefault = this.batchLoaderDefault.bind(this);
|
|
@@ -84,11 +82,19 @@ class DataCache {
|
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
load(key) {
|
|
87
|
-
|
|
85
|
+
const builtKey = this.buildKey(key);
|
|
86
|
+
if (builtKey == null) {
|
|
87
|
+
return Promise.resolve(null);
|
|
88
|
+
}
|
|
89
|
+
return this.loader.load(builtKey);
|
|
88
90
|
}
|
|
89
91
|
loadMany(keys) {
|
|
90
92
|
return this.loader.loadMany(keys.map((key) => this.buildKey(key)));
|
|
91
93
|
}
|
|
94
|
+
prime(key, value) {
|
|
95
|
+
this.loader?.prime(this.buildKey(key), value);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
92
98
|
clear(key) {
|
|
93
99
|
if (Array.isArray(key)) {
|
|
94
100
|
key.forEach((item) => this.loader?.clear(this.buildKey(item)));
|
|
@@ -96,6 +102,11 @@ class DataCache {
|
|
|
96
102
|
else {
|
|
97
103
|
this.loader?.clear(this.buildKey(key));
|
|
98
104
|
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
clearAll() {
|
|
108
|
+
this.loader?.clearAll();
|
|
109
|
+
return this;
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
exports.DataCache = DataCache;
|
package/build/esm/DataCache.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ declare class DataCache implements LoaderInterface {
|
|
|
9
9
|
init(batchFunction: any, keyPrefix?: string, context?: any): void;
|
|
10
10
|
load(key: any): any;
|
|
11
11
|
loadMany(keys: any[]): any;
|
|
12
|
-
|
|
12
|
+
prime(key: any, value: any): this;
|
|
13
|
+
clear(key: any | any[]): this;
|
|
14
|
+
clearAll(): this;
|
|
13
15
|
}
|
|
14
16
|
export { DataCache };
|
package/build/esm/DataCache.js
CHANGED
|
@@ -10,13 +10,11 @@ class DataCache {
|
|
|
10
10
|
redisClient;
|
|
11
11
|
constructor(props) {
|
|
12
12
|
const { loaderFn, keyPrefix, context, buildKey, redisClient, table } = props || {};
|
|
13
|
-
|
|
14
|
-
props
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
this.config = props;
|
|
13
|
+
this.config = {
|
|
14
|
+
...props,
|
|
15
|
+
idField: props?.idField || FIELDS.ID,
|
|
16
|
+
idFieldAs: props?.idFieldAs || FIELDS.ID,
|
|
17
|
+
};
|
|
20
18
|
this.redisClient = redisClient;
|
|
21
19
|
this.buildKey = typeof buildKey === 'function' ? buildKey : defaultBuildKey;
|
|
22
20
|
this.batchLoaderDefault = this.batchLoaderDefault.bind(this);
|
|
@@ -78,11 +76,19 @@ class DataCache {
|
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
78
|
load(key) {
|
|
81
|
-
|
|
79
|
+
const builtKey = this.buildKey(key);
|
|
80
|
+
if (builtKey == null) {
|
|
81
|
+
return Promise.resolve(null);
|
|
82
|
+
}
|
|
83
|
+
return this.loader.load(builtKey);
|
|
82
84
|
}
|
|
83
85
|
loadMany(keys) {
|
|
84
86
|
return this.loader.loadMany(keys.map((key) => this.buildKey(key)));
|
|
85
87
|
}
|
|
88
|
+
prime(key, value) {
|
|
89
|
+
this.loader?.prime(this.buildKey(key), value);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
86
92
|
clear(key) {
|
|
87
93
|
if (Array.isArray(key)) {
|
|
88
94
|
key.forEach((item) => this.loader?.clear(this.buildKey(item)));
|
|
@@ -90,6 +96,11 @@ class DataCache {
|
|
|
90
96
|
else {
|
|
91
97
|
this.loader?.clear(this.buildKey(key));
|
|
92
98
|
}
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
clearAll() {
|
|
102
|
+
this.loader?.clearAll();
|
|
103
|
+
return this;
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
export { DataCache };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export interface LoaderInterface {
|
|
2
|
-
load(id: any): any
|
|
3
|
-
loadMany(id: any): any
|
|
4
|
-
clear(key: any | any[]):
|
|
2
|
+
load(id: any): Promise<any>;
|
|
3
|
+
loadMany(id: any): Promise<any[]>;
|
|
4
|
+
clear(key: any | any[]): this;
|
|
5
|
+
clearAll(): this;
|
|
6
|
+
prime(key: any, value: any): this;
|
|
5
7
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export interface LoaderInterface {
|
|
2
|
-
load(id: any): any
|
|
3
|
-
loadMany(id: any): any
|
|
4
|
-
clear(key: any | any[]):
|
|
2
|
+
load(id: any): Promise<any>;
|
|
3
|
+
loadMany(id: any): Promise<any[]>;
|
|
4
|
+
clear(key: any | any[]): this;
|
|
5
|
+
clearAll(): this;
|
|
6
|
+
prime(key: any, value: any): this;
|
|
5
7
|
}
|