@candlerip/shared 0.0.86 → 0.0.87
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.
|
@@ -18,7 +18,6 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
18
18
|
resetCustomError();
|
|
19
19
|
});
|
|
20
20
|
_client.connect();
|
|
21
|
-
const _composeKey = (key) => `${environmentMode}:${key}`;
|
|
22
21
|
const _getClient = () => {
|
|
23
22
|
const resp = getCustomError();
|
|
24
23
|
if (resp) {
|
|
@@ -39,15 +38,14 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
39
38
|
};
|
|
40
39
|
};
|
|
41
40
|
const getCache = async (key) => {
|
|
42
|
-
const
|
|
43
|
-
const { composeCustomError } = CustomErrorWorker({ info: { redisKey } });
|
|
41
|
+
const { composeCustomError } = CustomErrorWorker({ info: { key } });
|
|
44
42
|
const { data: client, customError } = _getClient();
|
|
45
43
|
if (customError) {
|
|
46
44
|
return { customError };
|
|
47
45
|
}
|
|
48
46
|
let data;
|
|
49
47
|
try {
|
|
50
|
-
const cache = await client.get(
|
|
48
|
+
const cache = await client.get(key);
|
|
51
49
|
if (cache) {
|
|
52
50
|
data = JSON.parse(cache);
|
|
53
51
|
}
|
|
@@ -67,8 +65,7 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
67
65
|
};
|
|
68
66
|
};
|
|
69
67
|
const mGetCache = async (keys) => {
|
|
70
|
-
const
|
|
71
|
-
const { composeCustomError } = CustomErrorWorker({ info: { redisKeys } });
|
|
68
|
+
const { composeCustomError } = CustomErrorWorker({ info: { keys } });
|
|
72
69
|
const { data: client, customError } = _getClient();
|
|
73
70
|
if (customError) {
|
|
74
71
|
return { customError };
|
|
@@ -76,14 +73,14 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
76
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
74
|
const data = {};
|
|
78
75
|
try {
|
|
79
|
-
const cache = await client.mGet(
|
|
76
|
+
const cache = await client.mGet(keys);
|
|
80
77
|
if (!isArray(cache, isString)) {
|
|
81
78
|
return {
|
|
82
79
|
customError: composeCustomError('Error get data from redis', { cache }),
|
|
83
80
|
};
|
|
84
81
|
}
|
|
85
82
|
cache.forEach((it, i) => {
|
|
86
|
-
data[
|
|
83
|
+
data[keys[i]] = JSON.parse(it);
|
|
87
84
|
});
|
|
88
85
|
}
|
|
89
86
|
catch (err) {
|
|
@@ -91,7 +88,7 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
91
88
|
customError: composeCustomError('Error get data from redis', { err }),
|
|
92
89
|
};
|
|
93
90
|
}
|
|
94
|
-
if (Object.keys(data).length !==
|
|
91
|
+
if (Object.keys(data).length !== keys.length) {
|
|
95
92
|
return {
|
|
96
93
|
customError: composeCustomError('Missing data from redis', { data }),
|
|
97
94
|
};
|
|
@@ -101,14 +98,13 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
101
98
|
};
|
|
102
99
|
};
|
|
103
100
|
const setCache = async (key, data) => {
|
|
104
|
-
const
|
|
105
|
-
const { composeCustomError } = CustomErrorWorker({ info: { redisKey } });
|
|
101
|
+
const { composeCustomError } = CustomErrorWorker({ info: { key } });
|
|
106
102
|
const { data: client, customError } = _getClient();
|
|
107
103
|
if (customError) {
|
|
108
104
|
return { customError };
|
|
109
105
|
}
|
|
110
106
|
try {
|
|
111
|
-
await client.set(
|
|
107
|
+
await client.set(key, JSON.stringify(data));
|
|
112
108
|
}
|
|
113
109
|
catch (err) {
|
|
114
110
|
return {
|
|
@@ -9,7 +9,6 @@ export type TCacheWorker = (environmentMode: EnvironmentMode, url: string, passw
|
|
|
9
9
|
mGetCache: MGetCache;
|
|
10
10
|
setCache: SetCache;
|
|
11
11
|
};
|
|
12
|
-
export type ComposeKey = (key: CacheKey) => string;
|
|
13
12
|
export type GetCache = <T extends CacheKey = never, D extends Cache[T] = Cache[T]>(key: T) => Promise<TCustomError<D>>;
|
|
14
13
|
export type MGetCache = <T extends CacheKey = never, D extends Pick<Cache, T> = Pick<Cache, T>>(keys: T[]) => Promise<TCustomError<D>>;
|
|
15
14
|
export type SetCache = <T extends CacheKey = never>(key: T, data: Cache[T]) => Promise<TCustomError<null>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@candlerip/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.87",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "=22.19.0"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"./message-broker": "./message-broker/index.js"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"dev": "crs-tsc-watch"
|
|
19
|
+
"dev": "crs-tsc-watch",
|
|
20
|
+
"publish-package": "bash ./_devops/publish-package.sh"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@aws-sdk/client-ec2": "^3.938.0",
|