@candlerip/shared 0.0.131 → 0.0.133
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 +18 -14
- package/cache/redis/workers/type.d.ts +3 -7
- package/common/translation/translation-code/page/utils/index.d.ts +1 -0
- package/common/translation/translation-code/page/utils/index.js +1 -0
- package/database/mutation/page-translation/utils/index.d.ts +0 -1
- package/database/mutation/page-translation/utils/index.js +0 -1
- package/package.json +1 -1
- package/database/mutation/page-translation/utils/compose-page-dictionary-db/index.d.ts +0 -2
- package/database/mutation/page-translation/utils/compose-page-dictionary-db/index.js +0 -12
- package/database/mutation/page-translation/utils/compose-page-dictionary-db/type.d.ts +0 -8
- package/database/mutation/page-translation/utils/compose-page-dictionary-db/type.js +0 -1
|
@@ -92,7 +92,6 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
92
92
|
try {
|
|
93
93
|
const promises = getRedisData.map((it) => client.json.get(it.cacheKey, { path: it.pathKeys }));
|
|
94
94
|
data = await Promise.all(promises);
|
|
95
|
-
console.error('***', data);
|
|
96
95
|
if (!data || data.some((it) => it.length === 0)) {
|
|
97
96
|
return {
|
|
98
97
|
customError: composeCustomError('No data in Redis'),
|
|
@@ -104,23 +103,19 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
104
103
|
customError: composeCustomError('Error get data by object keys from Redis', { err }),
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
const normalizedData = {};
|
|
109
|
-
getRedisData.forEach((it, index) => {
|
|
106
|
+
const normalizedData = getRedisData.map((it, index) => {
|
|
110
107
|
const { objKeys } = it;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (objKeys) {
|
|
114
|
-
objKeys.forEach((objKey) => {
|
|
115
|
-
normalizedCacheKeyData[objKey] = objKeys?.length === 1 ? data[index][0] : data[index][`$.${objKey}`][0];
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
normalizedCacheKeyData = data[index];
|
|
108
|
+
if (!objKeys) {
|
|
109
|
+
return data[index];
|
|
120
110
|
}
|
|
121
|
-
|
|
111
|
+
const normalizedCacheKeyData = {};
|
|
112
|
+
objKeys.forEach((objKey) => {
|
|
113
|
+
normalizedCacheKeyData[objKey] = objKeys?.length === 1 ? data[index][0] : data[index][`$.${objKey}`][0];
|
|
114
|
+
});
|
|
115
|
+
return normalizedCacheKeyData;
|
|
122
116
|
});
|
|
123
117
|
return {
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
119
|
data: normalizedData,
|
|
125
120
|
};
|
|
126
121
|
};
|
|
@@ -148,3 +143,12 @@ export const CacheWorker = (environmentMode, url, password, options) => {
|
|
|
148
143
|
set,
|
|
149
144
|
};
|
|
150
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,5 +1,5 @@
|
|
|
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;
|
|
@@ -11,16 +11,12 @@ export type TCacheWorker = (environmentMode: EnvironmentMode, url: string, passw
|
|
|
11
11
|
export type GetClient = () => TCustomError<ReturnType<typeof createClient>>;
|
|
12
12
|
export type Set = <T extends keyof Cache>(key: T, data: Cache[T]) => Promise<TCustomError<null>>;
|
|
13
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> =
|
|
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 Gets = <T extends
|
|
22
|
-
[key in CacheKey]?: CacheData;
|
|
23
|
-
} = never, C extends CacheKey = CacheKey>(props: GetProps<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
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { composeExcludedPageTranslationCodes, PAGE_TRANSLATION_CODES_MAP } from '../../../../../common/index.js';
|
|
2
|
-
import { getPageTranslationsAsDictionaryDb } from '../get-page-translations-as-dictionary-db/index.js';
|
|
3
|
-
export const composePageDictionaryDb = async (page, language, options) => {
|
|
4
|
-
let codes = [...PAGE_TRANSLATION_CODES_MAP[page]];
|
|
5
|
-
const excludedCodes = composeExcludedPageTranslationCodes({
|
|
6
|
-
...options?.excludedPageTranslationCodeOptions,
|
|
7
|
-
page,
|
|
8
|
-
});
|
|
9
|
-
codes = codes.filter((it) => !excludedCodes.includes(it));
|
|
10
|
-
const resp = await getPageTranslationsAsDictionaryDb(language, codes);
|
|
11
|
-
return resp;
|
|
12
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CustomError, ExcludedPageTranslationCodeOptions, Language, Page, PageDictionary } from '../../../../../common/index.js';
|
|
2
|
-
export type ComposePageDictionaryDb = (page: Page, language: Language, options?: {
|
|
3
|
-
excludedPageTranslationCodeOptions?: ExcludedPageTranslationCodeOptions;
|
|
4
|
-
}) => Promise<{
|
|
5
|
-
data: PageDictionary;
|
|
6
|
-
} | {
|
|
7
|
-
customError: CustomError;
|
|
8
|
-
}>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|