@candlerip/shared3 0.0.101 → 0.0.102
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +16 -1
- package/src/_devops/get-project-config/domains/args/index.d.ts +5 -0
- package/src/_devops/get-project-config/domains/args/index.js +1 -0
- package/src/_devops/get-project-config/domains/index.d.ts +1 -0
- package/src/_devops/get-project-config/domains/index.js +1 -0
- package/src/_devops/get-project-config/index.d.ts +2 -0
- package/src/_devops/get-project-config/index.js +18 -0
- package/src/aws/account-id/config.d.ts +1 -0
- package/src/aws/account-id/config.js +1 -0
- package/src/aws/account-id/index.d.ts +1 -0
- package/src/aws/account-id/index.js +1 -0
- package/src/aws/app-config/get-app-config/index.d.ts +1 -0
- package/src/aws/app-config/get-app-config/index.js +1 -0
- package/src/aws/app-config/get-app-config/util.d.ts +10 -0
- package/src/aws/app-config/get-app-config/util.js +79 -0
- package/src/aws/app-config/index.d.ts +1 -0
- package/src/aws/app-config/index.js +1 -0
- package/src/aws/cdk/attach-policy/index.d.ts +1 -0
- package/src/aws/cdk/attach-policy/index.js +1 -0
- package/src/aws/cdk/attach-policy/type.d.ts +24 -0
- package/src/aws/cdk/attach-policy/type.js +1 -0
- package/src/aws/cdk/attach-policy/util.d.ts +2 -0
- package/src/aws/cdk/attach-policy/util.js +33 -0
- package/src/aws/cdk/compose-cdk-stack/index.d.ts +1 -0
- package/src/aws/cdk/compose-cdk-stack/index.js +1 -0
- package/src/aws/cdk/compose-cdk-stack/type.d.ts +2 -0
- package/src/aws/cdk/compose-cdk-stack/type.js +1 -0
- package/src/aws/cdk/compose-cdk-stack/util.d.ts +2 -0
- package/src/aws/cdk/compose-cdk-stack/util.js +2 -0
- package/src/aws/cdk/index.d.ts +2 -0
- package/src/aws/cdk/index.js +2 -0
- package/src/aws/index.d.ts +7 -0
- package/src/aws/index.js +7 -0
- package/src/aws/lambda/index.d.ts +2 -0
- package/src/aws/lambda/index.js +2 -0
- package/src/aws/lambda/lambda-arn/compose-lambda-arn/index.d.ts +1 -0
- package/src/aws/lambda/lambda-arn/compose-lambda-arn/index.js +1 -0
- package/src/aws/lambda/lambda-arn/compose-lambda-arn/type.d.ts +2 -0
- package/src/aws/lambda/lambda-arn/compose-lambda-arn/type.js +1 -0
- package/src/aws/lambda/lambda-arn/compose-lambda-arn/util.d.ts +2 -0
- package/src/aws/lambda/lambda-arn/compose-lambda-arn/util.js +2 -0
- package/src/aws/lambda/lambda-arn/config.d.ts +1 -0
- package/src/aws/lambda/lambda-arn/config.js +3 -0
- package/src/aws/lambda/lambda-arn/index.d.ts +2 -0
- package/src/aws/lambda/lambda-arn/index.js +2 -0
- package/src/aws/lambda/lambda-name/config.d.ts +1 -0
- package/src/aws/lambda/lambda-name/config.js +1 -0
- package/src/aws/lambda/lambda-name/index.d.ts +2 -0
- package/src/aws/lambda/lambda-name/index.js +2 -0
- package/src/aws/lambda/lambda-name/type.d.ts +2 -0
- package/src/aws/lambda/lambda-name/type.js +1 -0
- package/src/aws/region/config.d.ts +1 -0
- package/src/aws/region/config.js +1 -0
- package/src/aws/region/default.d.ts +2 -0
- package/src/aws/region/default.js +1 -0
- package/src/aws/region/index.d.ts +3 -0
- package/src/aws/region/index.js +3 -0
- package/src/aws/region/type.d.ts +2 -0
- package/src/aws/region/type.js +1 -0
- package/src/aws/s3/index.d.ts +1 -0
- package/src/aws/s3/index.js +1 -0
- package/src/aws/s3/s3-arn/compose-s3-arn/index.d.ts +1 -0
- package/src/aws/s3/s3-arn/compose-s3-arn/index.js +1 -0
- package/src/aws/s3/s3-arn/compose-s3-arn/type.d.ts +1 -0
- package/src/aws/s3/s3-arn/compose-s3-arn/type.js +1 -0
- package/src/aws/s3/s3-arn/compose-s3-arn/util.d.ts +2 -0
- package/src/aws/s3/s3-arn/compose-s3-arn/util.js +2 -0
- package/src/aws/s3/s3-arn/config.d.ts +1 -0
- package/src/aws/s3/s3-arn/config.js +1 -0
- package/src/aws/s3/s3-arn/index.d.ts +2 -0
- package/src/aws/s3/s3-arn/index.js +2 -0
- package/src/aws/sqs/index.d.ts +2 -0
- package/src/aws/sqs/index.js +2 -0
- package/src/aws/sqs/queue-arn/compose-queue-arn/index.d.ts +1 -0
- package/src/aws/sqs/queue-arn/compose-queue-arn/index.js +1 -0
- package/src/aws/sqs/queue-arn/compose-queue-arn/type.d.ts +2 -0
- package/src/aws/sqs/queue-arn/compose-queue-arn/type.js +1 -0
- package/src/aws/sqs/queue-arn/compose-queue-arn/util.d.ts +2 -0
- package/src/aws/sqs/queue-arn/compose-queue-arn/util.js +2 -0
- package/src/aws/sqs/queue-arn/config.d.ts +1 -0
- package/src/aws/sqs/queue-arn/config.js +3 -0
- package/src/aws/sqs/queue-arn/index.d.ts +2 -0
- package/src/aws/sqs/queue-arn/index.js +2 -0
- package/src/aws/sqs/queue-name/cache/config.d.ts +1 -0
- package/src/aws/sqs/queue-name/cache/config.js +1 -0
- package/src/aws/sqs/queue-name/cache/index.d.ts +2 -0
- package/src/aws/sqs/queue-name/cache/index.js +2 -0
- package/src/aws/sqs/queue-name/cache/type.d.ts +2 -0
- package/src/aws/sqs/queue-name/cache/type.js +1 -0
- package/src/aws/sqs/queue-name/index.d.ts +3 -0
- package/src/aws/sqs/queue-name/index.js +3 -0
- package/src/aws/sqs/queue-name/logger/config.d.ts +1 -0
- package/src/aws/sqs/queue-name/logger/config.js +1 -0
- package/src/aws/sqs/queue-name/logger/index.d.ts +2 -0
- package/src/aws/sqs/queue-name/logger/index.js +2 -0
- package/src/aws/sqs/queue-name/logger/type.d.ts +2 -0
- package/src/aws/sqs/queue-name/logger/type.js +1 -0
- package/src/aws/sqs/queue-name/queue-name/config.d.ts +1 -0
- package/src/aws/sqs/queue-name/queue-name/config.js +3 -0
- package/src/aws/sqs/queue-name/queue-name/index.d.ts +2 -0
- package/src/aws/sqs/queue-name/queue-name/index.js +2 -0
- package/src/aws/sqs/queue-name/queue-name/type.d.ts +2 -0
- package/src/aws/sqs/queue-name/queue-name/type.js +1 -0
- package/src/backend/cache/cache/index.d.ts +2 -0
- package/src/backend/cache/cache/index.js +2 -0
- package/src/backend/cache/cache/singleton.d.ts +23 -0
- package/src/backend/cache/cache/singleton.js +104 -0
- package/src/backend/cache/cache/type.d.ts +5 -0
- package/src/backend/cache/cache/type.js +1 -0
- package/src/backend/cache/cache-key/config.d.ts +1 -0
- package/src/backend/cache/cache-key/config.js +18 -0
- package/src/backend/cache/cache-key/index.d.ts +3 -0
- package/src/backend/cache/cache-key/index.js +3 -0
- package/src/backend/cache/cache-key/type-guard.d.ts +2 -0
- package/src/backend/cache/cache-key/type-guard.js +4 -0
- package/src/backend/cache/cache-key/type.d.ts +2 -0
- package/src/backend/cache/cache-key/type.js +1 -0
- package/src/backend/cache/index.d.ts +2 -0
- package/src/backend/cache/index.js +2 -0
- package/src/backend/database/connect-database/index.d.ts +1 -0
- package/src/backend/database/connect-database/index.js +1 -0
- package/src/backend/database/connect-database/type.d.ts +1 -0
- package/src/backend/database/connect-database/type.js +1 -0
- package/src/backend/database/connect-database/util.d.ts +2 -0
- package/src/backend/database/connect-database/util.js +12 -0
- package/src/backend/database/model/translation/index.d.ts +2 -0
- package/src/backend/database/model/translation/index.js +2 -0
- package/src/backend/database/model/translation/type.d.ts +7 -0
- package/src/backend/database/model/translation/type.js +1 -0
- package/src/backend/database/model/translation/util.d.ts +7 -0
- package/src/backend/database/model/translation/util.js +7 -0
- package/src/backend/database/mutation/translation/get-translations/index.d.ts +1 -0
- package/src/backend/database/mutation/translation/get-translations/index.js +1 -0
- package/src/backend/database/mutation/translation/get-translations/type.d.ts +8 -0
- package/src/backend/database/mutation/translation/get-translations/type.js +1 -0
- package/src/backend/database/mutation/translation/get-translations/util.d.ts +2 -0
- package/src/backend/database/mutation/translation/get-translations/util.js +30 -0
- package/src/backend/database/mutation/translation/get-translations-as-dictionary/index.d.ts +1 -0
- package/src/backend/database/mutation/translation/get-translations-as-dictionary/index.js +1 -0
- package/src/backend/database/mutation/translation/get-translations-as-dictionary/util.d.ts +7 -0
- package/src/backend/database/mutation/translation/get-translations-as-dictionary/util.js +51 -0
- package/src/backend/database/mutation/translation/index.d.ts +2 -0
- package/src/backend/database/mutation/translation/index.js +2 -0
- package/src/backend/dictionary/compose-dictionary/index.d.ts +1 -0
- package/src/backend/dictionary/compose-dictionary/index.js +1 -0
- package/src/backend/dictionary/compose-dictionary/type.d.ts +10 -0
- package/src/backend/dictionary/compose-dictionary/type.js +1 -0
- package/src/backend/dictionary/compose-dictionary/util.d.ts +2 -0
- package/src/backend/dictionary/compose-dictionary/util.js +10 -0
- package/src/backend/dictionary/get-excluded-translation-ids/index.d.ts +1 -0
- package/src/backend/dictionary/get-excluded-translation-ids/index.js +1 -0
- package/src/backend/dictionary/get-excluded-translation-ids/type.d.ts +5 -0
- package/src/backend/dictionary/get-excluded-translation-ids/type.js +1 -0
- package/src/backend/dictionary/get-excluded-translation-ids/util.d.ts +2 -0
- package/src/backend/dictionary/get-excluded-translation-ids/util.js +10 -0
- package/src/backend/dictionary/index.d.ts +2 -0
- package/src/backend/dictionary/index.js +2 -0
- package/src/backend/express/index.d.ts +1 -0
- package/src/backend/express/index.js +1 -0
- package/src/backend/express/start-express-app/index.d.ts +1 -0
- package/src/backend/express/start-express-app/index.js +1 -0
- package/src/backend/express/start-express-app/type.d.ts +2 -0
- package/src/backend/express/start-express-app/type.js +1 -0
- package/src/backend/express/start-express-app/util.d.ts +2 -0
- package/src/backend/express/start-express-app/util.js +8 -0
- package/src/backend/message-broker/index.d.ts +4 -0
- package/src/backend/message-broker/index.js +4 -0
- package/src/backend/message-broker/log-custom-error/index.d.ts +1 -0
- package/src/backend/message-broker/log-custom-error/index.js +1 -0
- package/src/backend/message-broker/log-custom-error/type.d.ts +2 -0
- package/src/backend/message-broker/log-custom-error/type.js +1 -0
- package/src/backend/message-broker/log-custom-error/util.d.ts +2 -0
- package/src/backend/message-broker/log-custom-error/util.js +2 -0
- package/src/backend/message-broker/message-broker/config.d.ts +4 -0
- package/src/backend/message-broker/message-broker/config.js +4 -0
- package/src/backend/message-broker/message-broker/index.d.ts +3 -0
- package/src/backend/message-broker/message-broker/index.js +3 -0
- package/src/backend/message-broker/message-broker/singleton.d.ts +7 -0
- package/src/backend/message-broker/message-broker/singleton.js +70 -0
- package/src/backend/message-broker/message-broker/type.d.ts +12 -0
- package/src/backend/message-broker/message-broker/type.js +1 -0
- package/src/backend/message-broker/message-broker-queue-name/index.d.ts +1 -0
- package/src/backend/message-broker/message-broker-queue-name/index.js +1 -0
- package/src/backend/message-broker/message-broker-queue-name/type.d.ts +2 -0
- package/src/backend/message-broker/message-broker-queue-name/type.js +1 -0
- package/src/backend/message-broker/message-broker-refresh-cache/index.d.ts +2 -0
- package/src/backend/message-broker/message-broker-refresh-cache/index.js +2 -0
- package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/index.d.ts +1 -0
- package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/index.js +1 -0
- package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/type.d.ts +2 -0
- package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/type.js +1 -0
- package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/util.d.ts +2 -0
- package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/util.js +6 -0
- package/src/backend/message-broker/message-broker-refresh-cache/type.d.ts +4 -0
- package/src/backend/message-broker/message-broker-refresh-cache/type.js +1 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
import { CacheKey } from '../cache-key/index.js';
|
2
|
+
import { Cache } from './type.js';
|
3
|
+
import { CustomError } from '../../../error/index.js';
|
4
|
+
export declare const CacheSingleton: {
|
5
|
+
get: <T extends CacheKey>(key: T) => Promise<{
|
6
|
+
data: Cache[T];
|
7
|
+
} | {
|
8
|
+
customError: CustomError;
|
9
|
+
}>;
|
10
|
+
init: (url: string, password: string, options?: {
|
11
|
+
isEnabled?: boolean;
|
12
|
+
}) => void;
|
13
|
+
mGet: <T extends CacheKey>(keys: CacheKey[]) => Promise<{
|
14
|
+
data: Pick<Cache, T>;
|
15
|
+
} | {
|
16
|
+
customError: CustomError;
|
17
|
+
}>;
|
18
|
+
set: <T extends CacheKey>(key: T, data: Cache[T]) => Promise<{
|
19
|
+
data: null;
|
20
|
+
} | {
|
21
|
+
customError: CustomError;
|
22
|
+
}>;
|
23
|
+
};
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import { createClient } from 'redis';
|
2
|
+
import { customErrorWorker } from '../../../error/index.js';
|
3
|
+
import { isArray, isString } from '../../../type/index.js';
|
4
|
+
export const CacheSingleton = (() => {
|
5
|
+
let _client;
|
6
|
+
let _isEnabled;
|
7
|
+
let _err;
|
8
|
+
let _customErrorWorker;
|
9
|
+
const checkErrorStatus = () => {
|
10
|
+
if (!_isEnabled) {
|
11
|
+
return _customErrorWorker.composeCustomError('Cache disabled');
|
12
|
+
}
|
13
|
+
if (_err) {
|
14
|
+
return _customErrorWorker.composeCustomError('Error connect Cache', { err: _err });
|
15
|
+
}
|
16
|
+
return;
|
17
|
+
};
|
18
|
+
const init = (url, password, options) => {
|
19
|
+
_isEnabled = Boolean(options?.isEnabled);
|
20
|
+
_customErrorWorker = customErrorWorker({ password, url, options });
|
21
|
+
_client = createClient({
|
22
|
+
password,
|
23
|
+
url,
|
24
|
+
});
|
25
|
+
_client.on('error', (error) => {
|
26
|
+
_err = error;
|
27
|
+
});
|
28
|
+
_client.on('ready', () => {
|
29
|
+
_err = undefined;
|
30
|
+
});
|
31
|
+
_client.connect();
|
32
|
+
};
|
33
|
+
const get = async (key) => {
|
34
|
+
_customErrorWorker.addInfo({ key });
|
35
|
+
const resp = checkErrorStatus();
|
36
|
+
if (resp) {
|
37
|
+
return resp;
|
38
|
+
}
|
39
|
+
let data;
|
40
|
+
try {
|
41
|
+
const cache = await _client.get(key);
|
42
|
+
if (cache) {
|
43
|
+
data = JSON.parse(cache);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
catch (err) {
|
47
|
+
return _customErrorWorker.composeCustomError('Error get data from Redis', { err });
|
48
|
+
}
|
49
|
+
if (!data) {
|
50
|
+
return _customErrorWorker.composeCustomError('No data in Redis');
|
51
|
+
}
|
52
|
+
return {
|
53
|
+
data,
|
54
|
+
};
|
55
|
+
};
|
56
|
+
const mGet = async (keys) => {
|
57
|
+
_customErrorWorker.addInfo({ keys });
|
58
|
+
const resp = checkErrorStatus();
|
59
|
+
if (resp) {
|
60
|
+
return resp;
|
61
|
+
}
|
62
|
+
const data = {};
|
63
|
+
try {
|
64
|
+
const cache = await _client.mGet(keys);
|
65
|
+
if (!isArray(cache, isString)) {
|
66
|
+
return _customErrorWorker.composeCustomError('Error get data from redis', { cache });
|
67
|
+
}
|
68
|
+
cache.forEach((it, i) => {
|
69
|
+
data[keys[i]] = JSON.parse(it);
|
70
|
+
});
|
71
|
+
}
|
72
|
+
catch (err) {
|
73
|
+
return _customErrorWorker.composeCustomError('Error get data from redis', { err });
|
74
|
+
}
|
75
|
+
if (Object.keys(data).length !== keys.length) {
|
76
|
+
return _customErrorWorker.composeCustomError('Missing data from redis', { data });
|
77
|
+
}
|
78
|
+
return {
|
79
|
+
data,
|
80
|
+
};
|
81
|
+
};
|
82
|
+
const set = async (key, data) => {
|
83
|
+
_customErrorWorker.addInfo({ key, data });
|
84
|
+
const resp = checkErrorStatus();
|
85
|
+
if (resp) {
|
86
|
+
return resp;
|
87
|
+
}
|
88
|
+
try {
|
89
|
+
await _client.set(key, JSON.stringify(data));
|
90
|
+
}
|
91
|
+
catch (err) {
|
92
|
+
return _customErrorWorker.composeCustomError('Error set data to redis', { err });
|
93
|
+
}
|
94
|
+
return {
|
95
|
+
data: null,
|
96
|
+
};
|
97
|
+
};
|
98
|
+
return {
|
99
|
+
get,
|
100
|
+
init,
|
101
|
+
mGet,
|
102
|
+
set,
|
103
|
+
};
|
104
|
+
})();
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const CACHE_KEYS: string[];
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export const CACHE_KEYS = [
|
2
|
+
'candle-details-page-dictionary-en',
|
3
|
+
'candle-details-page-dictionary-hu',
|
4
|
+
'candles-page-dictionary-en',
|
5
|
+
'candles-page-dictionary-hu',
|
6
|
+
'contact-page-dictionary-en',
|
7
|
+
'contact-page-dictionary-hu',
|
8
|
+
'cookie-policy-page-dictionary-en',
|
9
|
+
'cookie-policy-page-dictionary-hu',
|
10
|
+
'edit-candle-page-dictionary-en',
|
11
|
+
'edit-candle-page-dictionary-hu',
|
12
|
+
'light-candle-page-dictionary-en',
|
13
|
+
'light-candle-page-dictionary-hu',
|
14
|
+
'help-page-dictionary-en',
|
15
|
+
'help-page-dictionary-hu',
|
16
|
+
'terms-and-conditions-page-dictionary-en',
|
17
|
+
'terms-and-conditions-page-dictionary-hu',
|
18
|
+
];
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export type ConnectDatabase = (url: string) => Promise<void>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import * as mongoose from 'mongoose';
|
2
|
+
export const connectDatabase = async (url) => {
|
3
|
+
try {
|
4
|
+
await mongoose.connect(url);
|
5
|
+
mongoose.connection.on('error', () => {
|
6
|
+
setTimeout(connectDatabase, 5000);
|
7
|
+
});
|
8
|
+
}
|
9
|
+
catch {
|
10
|
+
setTimeout(connectDatabase, 5000);
|
11
|
+
}
|
12
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import * as mongoose from 'mongoose';
|
2
|
+
import { Translation } from './type.js';
|
3
|
+
export declare const TranslationDbModel: mongoose.Model<Translation & mongoose.Document<unknown, any, any>, {}, {}, {}, mongoose.Document<unknown, {}, Translation & mongoose.Document<unknown, any, any>> & Translation & mongoose.Document<unknown, any, any> & Required<{
|
4
|
+
_id: string;
|
5
|
+
}> & {
|
6
|
+
__v: number;
|
7
|
+
}, any>;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import * as mongoose from 'mongoose';
|
2
|
+
const TranslationSchema = new mongoose.Schema({
|
3
|
+
id: { type: String },
|
4
|
+
en: { type: String },
|
5
|
+
hu: { type: String },
|
6
|
+
}, { timestamps: true, versionKey: false });
|
7
|
+
export const TranslationDbModel = mongoose.model('translations', TranslationSchema);
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { TranslationId } from '../../../../../dictionary/index.js';
|
2
|
+
import { CustomError } from '../../../../../error/index.js';
|
3
|
+
import { Translation } from '../../../model/translation/index.js';
|
4
|
+
export type GetTranslations = (ids?: TranslationId[]) => Promise<{
|
5
|
+
data: Translation[];
|
6
|
+
} | {
|
7
|
+
customError: CustomError;
|
8
|
+
}>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { customErrorWorker } from '../../../../../error/index.js';
|
2
|
+
import { TranslationDbModel } from '../../../model/translation/index.js';
|
3
|
+
export const getTranslations = async (ids) => {
|
4
|
+
let query = {};
|
5
|
+
const _customErrorWorker = customErrorWorker({ ids });
|
6
|
+
if (ids) {
|
7
|
+
query = {
|
8
|
+
id: { $in: ids },
|
9
|
+
};
|
10
|
+
}
|
11
|
+
let resp;
|
12
|
+
try {
|
13
|
+
resp = await TranslationDbModel.find(query);
|
14
|
+
}
|
15
|
+
catch (err) {
|
16
|
+
return _customErrorWorker.composeCustomError('Get translations failed', { err, query });
|
17
|
+
}
|
18
|
+
if (ids && resp.length !== ids.length) {
|
19
|
+
return _customErrorWorker.composeCustomError('Missing ids from translations', {
|
20
|
+
info: {
|
21
|
+
missing: ids.filter((it) => !resp.find((it2) => it2.id === it)).join(', '),
|
22
|
+
value: ids,
|
23
|
+
},
|
24
|
+
});
|
25
|
+
}
|
26
|
+
const data = resp.map((it) => ({ ...it, _id: it._id.toString() }));
|
27
|
+
return {
|
28
|
+
data,
|
29
|
+
};
|
30
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Dictionary, Language, TranslationId } from '../../../../../dictionary/index.js';
|
2
|
+
import { CustomError } from '../../../../../error/index.js';
|
3
|
+
export declare const getTranslationsAsDictionary: <T extends TranslationId>(language: Language, ids?: readonly T[]) => Promise<{
|
4
|
+
data: Dictionary;
|
5
|
+
} | {
|
6
|
+
customError: CustomError;
|
7
|
+
}>;
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { customErrorWorker } from '../../../../../error/index.js';
|
2
|
+
import { TranslationDbModel } from '../../../model/translation/index.js';
|
3
|
+
export const getTranslationsAsDictionary = async (language, ids) => {
|
4
|
+
const aggregates = [];
|
5
|
+
const _customErrorWorker = customErrorWorker({ ids, language });
|
6
|
+
if (ids) {
|
7
|
+
aggregates.push({
|
8
|
+
$match: {
|
9
|
+
id: {
|
10
|
+
$in: ids,
|
11
|
+
},
|
12
|
+
},
|
13
|
+
});
|
14
|
+
}
|
15
|
+
aggregates.push(...[
|
16
|
+
{
|
17
|
+
$project: {
|
18
|
+
id: 1,
|
19
|
+
[language]: 1,
|
20
|
+
},
|
21
|
+
},
|
22
|
+
{
|
23
|
+
$group: {
|
24
|
+
_id: null,
|
25
|
+
root: {
|
26
|
+
$push: {
|
27
|
+
k: '$id',
|
28
|
+
v: `$${language}`,
|
29
|
+
},
|
30
|
+
},
|
31
|
+
},
|
32
|
+
},
|
33
|
+
{
|
34
|
+
$replaceRoot: {
|
35
|
+
newRoot: {
|
36
|
+
$arrayToObject: '$root',
|
37
|
+
},
|
38
|
+
},
|
39
|
+
},
|
40
|
+
]);
|
41
|
+
let data;
|
42
|
+
try {
|
43
|
+
data = await TranslationDbModel.aggregate(aggregates);
|
44
|
+
}
|
45
|
+
catch (err) {
|
46
|
+
return _customErrorWorker.composeCustomError('Get translations failed', { err });
|
47
|
+
}
|
48
|
+
return {
|
49
|
+
data: data[0],
|
50
|
+
};
|
51
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Dictionary, Language } from '../../../dictionary/index.js';
|
2
|
+
import { CustomError } from '../../../error/index.js';
|
3
|
+
import { Page } from '../../../page/index.js';
|
4
|
+
export type ComposeDictionary = (page: Page, language: Language, options?: {
|
5
|
+
isAuthenticated: boolean;
|
6
|
+
}) => Promise<{
|
7
|
+
data: Dictionary;
|
8
|
+
} | {
|
9
|
+
customError: CustomError;
|
10
|
+
}>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { DICTIONARY_CONFIG } from '../../../dictionary/index.js';
|
2
|
+
import { getTranslationsAsDictionary } from '../../database/mutation/translation/index.js';
|
3
|
+
import { getExcludedTranslationIds } from '../get-excluded-translation-ids/index.js';
|
4
|
+
export const composeDictionary = async (page, language, options) => {
|
5
|
+
let translationIds = [...DICTIONARY_CONFIG[page].translationIds];
|
6
|
+
const excludedIds = getExcludedTranslationIds(page, options);
|
7
|
+
translationIds = translationIds.filter((it) => !excludedIds.includes(it));
|
8
|
+
const resp = await getTranslationsAsDictionary(language, translationIds);
|
9
|
+
return resp;
|
10
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { isUndefined } from '../../../type/index.js';
|
2
|
+
export const getExcludedTranslationIds = (page, options) => {
|
3
|
+
const excludedIds = [`pageMenu.${page}`];
|
4
|
+
if (options) {
|
5
|
+
const { isAuthenticated } = options;
|
6
|
+
if (isUndefined(isAuthenticated))
|
7
|
+
excludedIds.push(isAuthenticated ? 'login' : 'logout');
|
8
|
+
}
|
9
|
+
return excludedIds;
|
10
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './start-express-app/util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './start-express-app/util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './util.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { MessageBrokerQueueName } from '../message-broker-queue-name/index.js';
|
2
|
+
import { MessageBroker } from './index.js';
|
3
|
+
export declare const MessageBrokerSingleton: {
|
4
|
+
init: (url: string) => void;
|
5
|
+
listenQueue: <T extends MessageBrokerQueueName>(queue: T, onMessage: (message: MessageBroker[T]) => void) => Promise<void>;
|
6
|
+
sendMessage: <T extends MessageBrokerQueueName>(queueName: T, message: MessageBroker[T]) => Promise<void>;
|
7
|
+
};
|