@candlerip/shared 0.0.130 → 0.0.132
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/cache/redis/workers/index.js +27 -22
- package/cache/redis/workers/type.d.ts +8 -12
- package/package.json +1 -1
- /package/cache/redis/workers/{compose-redis-get-data → compose-get-redis-data}/index.d.ts +0 -0
- /package/cache/redis/workers/{compose-redis-get-data → compose-get-redis-data}/index.js +0 -0
- /package/cache/redis/workers/{compose-redis-get-data → compose-get-redis-data}/type.d.ts +0 -0
- /package/cache/redis/workers/{compose-redis-get-data → compose-get-redis-data}/type.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomErrorWorker } from '../../../common/index.js';
|
|
2
2
|
import { createClient } from 'redis';
|
|
3
|
-
import { composeGetRedisData } from './compose-redis-
|
|
3
|
+
import { composeGetRedisData } from './compose-get-redis-data/index.js';
|
|
4
4
|
export const CacheWorker = (environmentMode, url, password, options) => {
|
|
5
5
|
const _isEnabled = Boolean(options?.isEnabled);
|
|
6
6
|
const customErrorWorker = CustomErrorWorker();
|
|
@@ -38,9 +38,10 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
38
38
|
data: _client,
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
-
const
|
|
41
|
+
const get = async (props) => {
|
|
42
|
+
const { cacheKey } = props;
|
|
42
43
|
const { composeCustomError } = CustomErrorWorker({ info: props });
|
|
43
|
-
const {
|
|
44
|
+
const { objKeys, pathKeys } = composeGetRedisData(props);
|
|
44
45
|
const { data: client, customError } = _getClient();
|
|
45
46
|
if (customError) {
|
|
46
47
|
return { customError };
|
|
@@ -79,7 +80,7 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
79
80
|
data: normalizedData,
|
|
80
81
|
};
|
|
81
82
|
};
|
|
82
|
-
const
|
|
83
|
+
const gets = async (props) => {
|
|
83
84
|
const { composeCustomError } = CustomErrorWorker({ info: { props } });
|
|
84
85
|
const getRedisData = props.map((it) => composeGetRedisData(it));
|
|
85
86
|
const { data: client, customError } = _getClient();
|
|
@@ -91,7 +92,6 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
91
92
|
try {
|
|
92
93
|
const promises = getRedisData.map((it) => client.json.get(it.cacheKey, { path: it.pathKeys }));
|
|
93
94
|
data = await Promise.all(promises);
|
|
94
|
-
console.error('***', data);
|
|
95
95
|
if (!data || data.some((it) => it.length === 0)) {
|
|
96
96
|
return {
|
|
97
97
|
customError: composeCustomError('No data in Redis'),
|
|
@@ -103,27 +103,23 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
103
103
|
customError: composeCustomError('Error get data by object keys from Redis', { err }),
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
const normalizedData = {};
|
|
108
|
-
getRedisData.forEach((it, index) => {
|
|
106
|
+
const normalizedData = getRedisData.map((it, index) => {
|
|
109
107
|
const { objKeys } = it;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (objKeys) {
|
|
113
|
-
objKeys.forEach((objKey) => {
|
|
114
|
-
normalizedCacheKeyData[objKey] = objKeys?.length === 1 ? data[index][0] : data[index][`$.${objKey}`][0];
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
normalizedCacheKeyData = data[index];
|
|
108
|
+
if (!objKeys) {
|
|
109
|
+
return data[index];
|
|
119
110
|
}
|
|
120
|
-
|
|
111
|
+
const normalizedCacheKeyData = {};
|
|
112
|
+
objKeys.forEach((objKey) => {
|
|
113
|
+
normalizedCacheKeyData[objKey] = objKeys?.length === 1 ? data[index][0] : data[index][`$.${objKey}`][0];
|
|
114
|
+
});
|
|
115
|
+
return normalizedCacheKeyData;
|
|
121
116
|
});
|
|
122
117
|
return {
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
119
|
data: normalizedData,
|
|
124
120
|
};
|
|
125
121
|
};
|
|
126
|
-
const
|
|
122
|
+
const set = async (key, data) => {
|
|
127
123
|
const { composeCustomError } = CustomErrorWorker({ info: { key } });
|
|
128
124
|
const { data: client, customError } = _getClient();
|
|
129
125
|
if (customError) {
|
|
@@ -142,8 +138,17 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
142
138
|
};
|
|
143
139
|
};
|
|
144
140
|
return {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
get,
|
|
142
|
+
gets,
|
|
143
|
+
set,
|
|
148
144
|
};
|
|
149
145
|
};
|
|
146
|
+
const { gets } = CacheWorker('', '', '', { isEnabled: true });
|
|
147
|
+
let language = 'hu';
|
|
148
|
+
const cacheKey = [`common-page-header-langmenu-items-dictionary-${language}`];
|
|
149
|
+
const resp = await gets([
|
|
150
|
+
{
|
|
151
|
+
cacheKey: cacheKey[0],
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
resp.data;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import { EnvironmentMode, TCustomError } from '../../../common/index.js';
|
|
2
|
-
import { CacheKey,
|
|
2
|
+
import { CacheKey, Cache, CacheData } from '../../common/index.js';
|
|
3
3
|
import { createClient } from 'redis';
|
|
4
4
|
export type TCacheWorker = (environmentMode: EnvironmentMode, url: string, password: string, options?: {
|
|
5
5
|
isEnabled?: boolean;
|
|
6
6
|
}) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
get: Get;
|
|
8
|
+
gets: Gets;
|
|
9
|
+
set: Set;
|
|
10
10
|
};
|
|
11
11
|
export type GetClient = () => TCustomError<ReturnType<typeof createClient>>;
|
|
12
|
-
export type
|
|
13
|
-
export type
|
|
14
|
-
export type
|
|
12
|
+
export type Set = <T extends keyof Cache>(key: T, data: Cache[T]) => Promise<TCustomError<null>>;
|
|
13
|
+
export type Get = <T extends CacheData = never, C extends CacheKey = CacheKey>(props: GetProps<C>) => Promise<TCustomError<T>>;
|
|
14
|
+
export type GetProps<C extends CacheKey> = {
|
|
15
15
|
cacheKey: C;
|
|
16
16
|
objKey?: ObjKey;
|
|
17
|
-
} : {
|
|
18
|
-
cacheKey: C;
|
|
19
17
|
objKeys?: string[];
|
|
20
18
|
};
|
|
21
|
-
export type
|
|
22
|
-
[key in CacheKey]?: CacheData;
|
|
23
|
-
} = never, C extends CacheKey = CacheKey>(props: GetCacheProps<C>[]) => Promise<TCustomError<T>>;
|
|
19
|
+
export type Gets = <T extends CacheData[] = CacheData[], C extends CacheKey = CacheKey>(props: GetProps<C>[]) => Promise<TCustomError<T>>;
|
|
24
20
|
export type ObjKeys = string[];
|
|
25
21
|
export type ObjKey = {
|
|
26
22
|
code: number;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|