@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.
Files changed (195) hide show
  1. package/package.json +16 -1
  2. package/src/_devops/get-project-config/domains/args/index.d.ts +5 -0
  3. package/src/_devops/get-project-config/domains/args/index.js +1 -0
  4. package/src/_devops/get-project-config/domains/index.d.ts +1 -0
  5. package/src/_devops/get-project-config/domains/index.js +1 -0
  6. package/src/_devops/get-project-config/index.d.ts +2 -0
  7. package/src/_devops/get-project-config/index.js +18 -0
  8. package/src/aws/account-id/config.d.ts +1 -0
  9. package/src/aws/account-id/config.js +1 -0
  10. package/src/aws/account-id/index.d.ts +1 -0
  11. package/src/aws/account-id/index.js +1 -0
  12. package/src/aws/app-config/get-app-config/index.d.ts +1 -0
  13. package/src/aws/app-config/get-app-config/index.js +1 -0
  14. package/src/aws/app-config/get-app-config/util.d.ts +10 -0
  15. package/src/aws/app-config/get-app-config/util.js +79 -0
  16. package/src/aws/app-config/index.d.ts +1 -0
  17. package/src/aws/app-config/index.js +1 -0
  18. package/src/aws/cdk/attach-policy/index.d.ts +1 -0
  19. package/src/aws/cdk/attach-policy/index.js +1 -0
  20. package/src/aws/cdk/attach-policy/type.d.ts +24 -0
  21. package/src/aws/cdk/attach-policy/type.js +1 -0
  22. package/src/aws/cdk/attach-policy/util.d.ts +2 -0
  23. package/src/aws/cdk/attach-policy/util.js +33 -0
  24. package/src/aws/cdk/compose-cdk-stack/index.d.ts +1 -0
  25. package/src/aws/cdk/compose-cdk-stack/index.js +1 -0
  26. package/src/aws/cdk/compose-cdk-stack/type.d.ts +2 -0
  27. package/src/aws/cdk/compose-cdk-stack/type.js +1 -0
  28. package/src/aws/cdk/compose-cdk-stack/util.d.ts +2 -0
  29. package/src/aws/cdk/compose-cdk-stack/util.js +2 -0
  30. package/src/aws/cdk/index.d.ts +2 -0
  31. package/src/aws/cdk/index.js +2 -0
  32. package/src/aws/index.d.ts +7 -0
  33. package/src/aws/index.js +7 -0
  34. package/src/aws/lambda/index.d.ts +2 -0
  35. package/src/aws/lambda/index.js +2 -0
  36. package/src/aws/lambda/lambda-arn/compose-lambda-arn/index.d.ts +1 -0
  37. package/src/aws/lambda/lambda-arn/compose-lambda-arn/index.js +1 -0
  38. package/src/aws/lambda/lambda-arn/compose-lambda-arn/type.d.ts +2 -0
  39. package/src/aws/lambda/lambda-arn/compose-lambda-arn/type.js +1 -0
  40. package/src/aws/lambda/lambda-arn/compose-lambda-arn/util.d.ts +2 -0
  41. package/src/aws/lambda/lambda-arn/compose-lambda-arn/util.js +2 -0
  42. package/src/aws/lambda/lambda-arn/config.d.ts +1 -0
  43. package/src/aws/lambda/lambda-arn/config.js +3 -0
  44. package/src/aws/lambda/lambda-arn/index.d.ts +2 -0
  45. package/src/aws/lambda/lambda-arn/index.js +2 -0
  46. package/src/aws/lambda/lambda-name/config.d.ts +1 -0
  47. package/src/aws/lambda/lambda-name/config.js +1 -0
  48. package/src/aws/lambda/lambda-name/index.d.ts +2 -0
  49. package/src/aws/lambda/lambda-name/index.js +2 -0
  50. package/src/aws/lambda/lambda-name/type.d.ts +2 -0
  51. package/src/aws/lambda/lambda-name/type.js +1 -0
  52. package/src/aws/region/config.d.ts +1 -0
  53. package/src/aws/region/config.js +1 -0
  54. package/src/aws/region/default.d.ts +2 -0
  55. package/src/aws/region/default.js +1 -0
  56. package/src/aws/region/index.d.ts +3 -0
  57. package/src/aws/region/index.js +3 -0
  58. package/src/aws/region/type.d.ts +2 -0
  59. package/src/aws/region/type.js +1 -0
  60. package/src/aws/s3/index.d.ts +1 -0
  61. package/src/aws/s3/index.js +1 -0
  62. package/src/aws/s3/s3-arn/compose-s3-arn/index.d.ts +1 -0
  63. package/src/aws/s3/s3-arn/compose-s3-arn/index.js +1 -0
  64. package/src/aws/s3/s3-arn/compose-s3-arn/type.d.ts +1 -0
  65. package/src/aws/s3/s3-arn/compose-s3-arn/type.js +1 -0
  66. package/src/aws/s3/s3-arn/compose-s3-arn/util.d.ts +2 -0
  67. package/src/aws/s3/s3-arn/compose-s3-arn/util.js +2 -0
  68. package/src/aws/s3/s3-arn/config.d.ts +1 -0
  69. package/src/aws/s3/s3-arn/config.js +1 -0
  70. package/src/aws/s3/s3-arn/index.d.ts +2 -0
  71. package/src/aws/s3/s3-arn/index.js +2 -0
  72. package/src/aws/sqs/index.d.ts +2 -0
  73. package/src/aws/sqs/index.js +2 -0
  74. package/src/aws/sqs/queue-arn/compose-queue-arn/index.d.ts +1 -0
  75. package/src/aws/sqs/queue-arn/compose-queue-arn/index.js +1 -0
  76. package/src/aws/sqs/queue-arn/compose-queue-arn/type.d.ts +2 -0
  77. package/src/aws/sqs/queue-arn/compose-queue-arn/type.js +1 -0
  78. package/src/aws/sqs/queue-arn/compose-queue-arn/util.d.ts +2 -0
  79. package/src/aws/sqs/queue-arn/compose-queue-arn/util.js +2 -0
  80. package/src/aws/sqs/queue-arn/config.d.ts +1 -0
  81. package/src/aws/sqs/queue-arn/config.js +3 -0
  82. package/src/aws/sqs/queue-arn/index.d.ts +2 -0
  83. package/src/aws/sqs/queue-arn/index.js +2 -0
  84. package/src/aws/sqs/queue-name/cache/config.d.ts +1 -0
  85. package/src/aws/sqs/queue-name/cache/config.js +1 -0
  86. package/src/aws/sqs/queue-name/cache/index.d.ts +2 -0
  87. package/src/aws/sqs/queue-name/cache/index.js +2 -0
  88. package/src/aws/sqs/queue-name/cache/type.d.ts +2 -0
  89. package/src/aws/sqs/queue-name/cache/type.js +1 -0
  90. package/src/aws/sqs/queue-name/index.d.ts +3 -0
  91. package/src/aws/sqs/queue-name/index.js +3 -0
  92. package/src/aws/sqs/queue-name/logger/config.d.ts +1 -0
  93. package/src/aws/sqs/queue-name/logger/config.js +1 -0
  94. package/src/aws/sqs/queue-name/logger/index.d.ts +2 -0
  95. package/src/aws/sqs/queue-name/logger/index.js +2 -0
  96. package/src/aws/sqs/queue-name/logger/type.d.ts +2 -0
  97. package/src/aws/sqs/queue-name/logger/type.js +1 -0
  98. package/src/aws/sqs/queue-name/queue-name/config.d.ts +1 -0
  99. package/src/aws/sqs/queue-name/queue-name/config.js +3 -0
  100. package/src/aws/sqs/queue-name/queue-name/index.d.ts +2 -0
  101. package/src/aws/sqs/queue-name/queue-name/index.js +2 -0
  102. package/src/aws/sqs/queue-name/queue-name/type.d.ts +2 -0
  103. package/src/aws/sqs/queue-name/queue-name/type.js +1 -0
  104. package/src/backend/cache/cache/index.d.ts +2 -0
  105. package/src/backend/cache/cache/index.js +2 -0
  106. package/src/backend/cache/cache/singleton.d.ts +23 -0
  107. package/src/backend/cache/cache/singleton.js +104 -0
  108. package/src/backend/cache/cache/type.d.ts +5 -0
  109. package/src/backend/cache/cache/type.js +1 -0
  110. package/src/backend/cache/cache-key/config.d.ts +1 -0
  111. package/src/backend/cache/cache-key/config.js +18 -0
  112. package/src/backend/cache/cache-key/index.d.ts +3 -0
  113. package/src/backend/cache/cache-key/index.js +3 -0
  114. package/src/backend/cache/cache-key/type-guard.d.ts +2 -0
  115. package/src/backend/cache/cache-key/type-guard.js +4 -0
  116. package/src/backend/cache/cache-key/type.d.ts +2 -0
  117. package/src/backend/cache/cache-key/type.js +1 -0
  118. package/src/backend/cache/index.d.ts +2 -0
  119. package/src/backend/cache/index.js +2 -0
  120. package/src/backend/database/connect-database/index.d.ts +1 -0
  121. package/src/backend/database/connect-database/index.js +1 -0
  122. package/src/backend/database/connect-database/type.d.ts +1 -0
  123. package/src/backend/database/connect-database/type.js +1 -0
  124. package/src/backend/database/connect-database/util.d.ts +2 -0
  125. package/src/backend/database/connect-database/util.js +12 -0
  126. package/src/backend/database/model/translation/index.d.ts +2 -0
  127. package/src/backend/database/model/translation/index.js +2 -0
  128. package/src/backend/database/model/translation/type.d.ts +7 -0
  129. package/src/backend/database/model/translation/type.js +1 -0
  130. package/src/backend/database/model/translation/util.d.ts +7 -0
  131. package/src/backend/database/model/translation/util.js +7 -0
  132. package/src/backend/database/mutation/translation/get-translations/index.d.ts +1 -0
  133. package/src/backend/database/mutation/translation/get-translations/index.js +1 -0
  134. package/src/backend/database/mutation/translation/get-translations/type.d.ts +8 -0
  135. package/src/backend/database/mutation/translation/get-translations/type.js +1 -0
  136. package/src/backend/database/mutation/translation/get-translations/util.d.ts +2 -0
  137. package/src/backend/database/mutation/translation/get-translations/util.js +30 -0
  138. package/src/backend/database/mutation/translation/get-translations-as-dictionary/index.d.ts +1 -0
  139. package/src/backend/database/mutation/translation/get-translations-as-dictionary/index.js +1 -0
  140. package/src/backend/database/mutation/translation/get-translations-as-dictionary/util.d.ts +7 -0
  141. package/src/backend/database/mutation/translation/get-translations-as-dictionary/util.js +51 -0
  142. package/src/backend/database/mutation/translation/index.d.ts +2 -0
  143. package/src/backend/database/mutation/translation/index.js +2 -0
  144. package/src/backend/dictionary/compose-dictionary/index.d.ts +1 -0
  145. package/src/backend/dictionary/compose-dictionary/index.js +1 -0
  146. package/src/backend/dictionary/compose-dictionary/type.d.ts +10 -0
  147. package/src/backend/dictionary/compose-dictionary/type.js +1 -0
  148. package/src/backend/dictionary/compose-dictionary/util.d.ts +2 -0
  149. package/src/backend/dictionary/compose-dictionary/util.js +10 -0
  150. package/src/backend/dictionary/get-excluded-translation-ids/index.d.ts +1 -0
  151. package/src/backend/dictionary/get-excluded-translation-ids/index.js +1 -0
  152. package/src/backend/dictionary/get-excluded-translation-ids/type.d.ts +5 -0
  153. package/src/backend/dictionary/get-excluded-translation-ids/type.js +1 -0
  154. package/src/backend/dictionary/get-excluded-translation-ids/util.d.ts +2 -0
  155. package/src/backend/dictionary/get-excluded-translation-ids/util.js +10 -0
  156. package/src/backend/dictionary/index.d.ts +2 -0
  157. package/src/backend/dictionary/index.js +2 -0
  158. package/src/backend/express/index.d.ts +1 -0
  159. package/src/backend/express/index.js +1 -0
  160. package/src/backend/express/start-express-app/index.d.ts +1 -0
  161. package/src/backend/express/start-express-app/index.js +1 -0
  162. package/src/backend/express/start-express-app/type.d.ts +2 -0
  163. package/src/backend/express/start-express-app/type.js +1 -0
  164. package/src/backend/express/start-express-app/util.d.ts +2 -0
  165. package/src/backend/express/start-express-app/util.js +8 -0
  166. package/src/backend/message-broker/index.d.ts +4 -0
  167. package/src/backend/message-broker/index.js +4 -0
  168. package/src/backend/message-broker/log-custom-error/index.d.ts +1 -0
  169. package/src/backend/message-broker/log-custom-error/index.js +1 -0
  170. package/src/backend/message-broker/log-custom-error/type.d.ts +2 -0
  171. package/src/backend/message-broker/log-custom-error/type.js +1 -0
  172. package/src/backend/message-broker/log-custom-error/util.d.ts +2 -0
  173. package/src/backend/message-broker/log-custom-error/util.js +2 -0
  174. package/src/backend/message-broker/message-broker/config.d.ts +4 -0
  175. package/src/backend/message-broker/message-broker/config.js +4 -0
  176. package/src/backend/message-broker/message-broker/index.d.ts +3 -0
  177. package/src/backend/message-broker/message-broker/index.js +3 -0
  178. package/src/backend/message-broker/message-broker/singleton.d.ts +7 -0
  179. package/src/backend/message-broker/message-broker/singleton.js +70 -0
  180. package/src/backend/message-broker/message-broker/type.d.ts +12 -0
  181. package/src/backend/message-broker/message-broker/type.js +1 -0
  182. package/src/backend/message-broker/message-broker-queue-name/index.d.ts +1 -0
  183. package/src/backend/message-broker/message-broker-queue-name/index.js +1 -0
  184. package/src/backend/message-broker/message-broker-queue-name/type.d.ts +2 -0
  185. package/src/backend/message-broker/message-broker-queue-name/type.js +1 -0
  186. package/src/backend/message-broker/message-broker-refresh-cache/index.d.ts +2 -0
  187. package/src/backend/message-broker/message-broker-refresh-cache/index.js +2 -0
  188. package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/index.d.ts +1 -0
  189. package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/index.js +1 -0
  190. package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/type.d.ts +2 -0
  191. package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/type.js +1 -0
  192. package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/util.d.ts +2 -0
  193. package/src/backend/message-broker/message-broker-refresh-cache/refresh-cache/util.js +6 -0
  194. package/src/backend/message-broker/message-broker-refresh-cache/type.d.ts +4 -0
  195. package/src/backend/message-broker/message-broker-refresh-cache/type.js +1 -0
@@ -0,0 +1,2 @@
1
+ export * from './type.js';
2
+ export * from './singleton.js';
@@ -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,5 @@
1
+ import { Dictionary } from '../../../dictionary/index.js';
2
+ import { CacheKey } from '../cache-key/index.js';
3
+ export type Cache = {
4
+ [key in CacheKey]: Dictionary;
5
+ };
@@ -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,3 @@
1
+ export * from './config.js';
2
+ export * from './type.js';
3
+ export * from './type-guard.js';
@@ -0,0 +1,3 @@
1
+ export * from './config.js';
2
+ export * from './type.js';
3
+ export * from './type-guard.js';
@@ -0,0 +1,2 @@
1
+ import { CacheKey } from './type.js';
2
+ export declare const isCacheKey: (data?: unknown) => data is CacheKey;
@@ -0,0 +1,4 @@
1
+ import { CACHE_KEYS } from './config.js';
2
+ export const isCacheKey = (data) => {
3
+ return CACHE_KEYS.some((it) => data === it);
4
+ };
@@ -0,0 +1,2 @@
1
+ import { CACHE_KEYS } from './config.js';
2
+ export type CacheKey = (typeof CACHE_KEYS)[number];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './cache/index.js';
2
+ export * from './cache-key/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './cache/index.js';
2
+ export * from './cache-key/index.js';
@@ -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,2 @@
1
+ import { ConnectDatabase } from './type.js';
2
+ export declare const connectDatabase: ConnectDatabase;
@@ -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,2 @@
1
+ export * from './type.js';
2
+ export * from './util.js';
@@ -0,0 +1,2 @@
1
+ export * from './type.js';
2
+ export * from './util.js';
@@ -0,0 +1,7 @@
1
+ import { TranslationId } from '../../../../dictionary/index.js';
2
+ export interface Translation {
3
+ _id: string;
4
+ id: TranslationId;
5
+ hu: string;
6
+ en: string;
7
+ }
@@ -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,2 @@
1
+ import { GetTranslations } from './type.js';
2
+ export declare const getTranslations: GetTranslations;
@@ -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,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,2 @@
1
+ export * from './get-translations/index.js';
2
+ export * from './get-translations-as-dictionary/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './get-translations/index.js';
2
+ export * from './get-translations-as-dictionary/index.js';
@@ -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,2 @@
1
+ import { ComposeDictionary } from './type.js';
2
+ export declare const composeDictionary: ComposeDictionary;
@@ -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,5 @@
1
+ import { TranslationId } from '../../../dictionary/index.js';
2
+ import { Page } from '../../../page/index.js';
3
+ export type GetExcludedTranslationIds = (page: Page, options?: {
4
+ isAuthenticated?: boolean;
5
+ }) => TranslationId[];
@@ -0,0 +1,2 @@
1
+ import { GetExcludedTranslationIds } from './type.js';
2
+ export declare const getExcludedTranslationIds: GetExcludedTranslationIds;
@@ -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,2 @@
1
+ export * from './get-excluded-translation-ids/index.js';
2
+ export * from './compose-dictionary/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './get-excluded-translation-ids/index.js';
2
+ export * from './compose-dictionary/index.js';
@@ -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,2 @@
1
+ import express from 'express';
2
+ export type StartExpressApp = (port: number) => express.Express;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { StartExpressApp } from './type.js';
2
+ export declare const startExpressApp: StartExpressApp;
@@ -0,0 +1,8 @@
1
+ import express from 'express';
2
+ export const startExpressApp = (port) => {
3
+ const app = express();
4
+ app.listen(port, () => {
5
+ console.error(`Server running on port ${port}`);
6
+ });
7
+ return app;
8
+ };
@@ -0,0 +1,4 @@
1
+ export * from './message-broker/index.js';
2
+ export * from './message-broker-queue-name/index.js';
3
+ export * from './message-broker-refresh-cache/index.js';
4
+ export * from './log-custom-error/index.js';
@@ -0,0 +1,4 @@
1
+ export * from './message-broker/index.js';
2
+ export * from './message-broker-queue-name/index.js';
3
+ export * from './message-broker-refresh-cache/index.js';
4
+ export * from './log-custom-error/index.js';
@@ -0,0 +1 @@
1
+ export * from './util.js';
@@ -0,0 +1 @@
1
+ export * from './util.js';
@@ -0,0 +1,2 @@
1
+ import { CustomError } from '../../../error/index.js';
2
+ export type LogCustomError = (customError: CustomError) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import { LogCustomError } from './type.js';
2
+ export declare const logCustomError: LogCustomError;
@@ -0,0 +1,2 @@
1
+ import { MessageBrokerSingleton } from '../message-broker/index.js';
2
+ export const logCustomError = (customError) => MessageBrokerSingleton.sendMessage('logger-service:log-custom-error', customError);
@@ -0,0 +1,4 @@
1
+ export declare const MESSAGE_BROKER_CONFIG: {
2
+ readonly 'cache-service:refresh-cache': "MessageBrokerRefreshCache | null";
3
+ readonly 'logger-service:log-custom-error': "CustomError";
4
+ };
@@ -0,0 +1,4 @@
1
+ export const MESSAGE_BROKER_CONFIG = {
2
+ 'cache-service:refresh-cache': 'MessageBrokerRefreshCache | null',
3
+ 'logger-service:log-custom-error': 'CustomError',
4
+ };
@@ -0,0 +1,3 @@
1
+ export * from './config.js';
2
+ export * from './type.js';
3
+ export * from './singleton.js';
@@ -0,0 +1,3 @@
1
+ export * from './config.js';
2
+ export * from './type.js';
3
+ export * from './singleton.js';
@@ -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
+ };