@candlerip/shared 0.0.84 → 0.0.86
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/common/index.d.ts +0 -1
- package/cache/common/index.js +0 -1
- package/cache/redis/domains.d.ts +8 -7
- package/database/aggregate/translation/utils/compose-get-translations-as-dictionary-aggregates/index.js +4 -2
- package/message-broker/index.d.ts +2 -0
- package/message-broker/index.js +2 -0
- package/message-broker/message-broker/domains.d.ts +9 -0
- package/message-broker/message-broker/index.d.ts +2 -0
- package/message-broker/message-broker/index.js +2 -0
- package/message-broker/message-broker/singletons/base/index.d.ts +12 -0
- package/message-broker/message-broker/singletons/base/index.js +54 -0
- package/message-broker/message-broker/singletons/base/type.d.ts +8 -0
- package/message-broker/message-broker/singletons/base/type.js +1 -0
- package/message-broker/message-broker/singletons/index.d.ts +6 -0
- package/message-broker/message-broker/singletons/index.js +42 -0
- package/message-broker/message-broker/singletons/type.d.ts +4 -0
- package/message-broker/message-broker/singletons/type.js +1 -0
- package/message-broker/message-broker-queue-name/domains.d.ts +2 -0
- package/package.json +5 -2
- package/cache/common/cache-service/index.d.ts +0 -2
- package/cache/common/cache-service/index.js +0 -2
- package/cache/common/cache-service/refresh-cache/domains.d.ts +0 -4
- package/cache/common/cache-service/workers/index.d.ts +0 -2
- package/cache/common/cache-service/workers/index.js +0 -39
- package/cache/common/cache-service/workers/type.d.ts +0 -14
- /package/{cache/common/cache-service/workers/type.js → message-broker/message-broker/domains.js} +0 -0
- /package/{cache/common/cache-service/refresh-cache → message-broker/message-broker-queue-name}/domains.js +0 -0
- /package/{cache/common/cache-service/refresh-cache → message-broker/message-broker-queue-name}/index.d.ts +0 -0
- /package/{cache/common/cache-service/refresh-cache → message-broker/message-broker-queue-name}/index.js +0 -0
package/cache/common/index.d.ts
CHANGED
package/cache/common/index.js
CHANGED
package/cache/redis/domains.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { CandlesPageServerData, CountryDictionary, Dictionary, HomePageServerData, Language, PersonsMapPageServerData, PersonsPageServerData } from '../../common/index.js';
|
|
2
2
|
import { CountryDictionaryCacheKey, PageDictionaryCacheKey } from '../common/index.js';
|
|
3
|
+
type PageServerDataMap = {
|
|
4
|
+
'candles-page': CandlesPageServerData;
|
|
5
|
+
'home-page': HomePageServerData;
|
|
6
|
+
'persons-page': PersonsPageServerData;
|
|
7
|
+
'persons-map-page': PersonsMapPageServerData;
|
|
8
|
+
};
|
|
3
9
|
export type Cache = {
|
|
4
10
|
[key in PageDictionaryCacheKey]: Dictionary;
|
|
5
11
|
} & {
|
|
6
12
|
[key in CountryDictionaryCacheKey]: CountryDictionary;
|
|
7
13
|
} & {
|
|
8
|
-
[key in
|
|
9
|
-
} & {
|
|
10
|
-
[key in `home-page-server-data-${Language}`]: HomePageServerData;
|
|
11
|
-
} & {
|
|
12
|
-
[key in `persons-page-server-data-${Language}`]: PersonsPageServerData;
|
|
13
|
-
} & {
|
|
14
|
-
[key in `persons-map-page-server-data-${Language}`]: PersonsMapPageServerData;
|
|
14
|
+
[key in keyof PageServerDataMap as `${key}-server-data-${Language}`]: PageServerDataMap[key];
|
|
15
15
|
};
|
|
16
|
+
export {};
|
|
@@ -13,7 +13,9 @@ export const composeGetTranslationsAsDictionaryAggregates = ({ codes, language }
|
|
|
13
13
|
{
|
|
14
14
|
$project: {
|
|
15
15
|
code: 1,
|
|
16
|
-
|
|
16
|
+
translation: {
|
|
17
|
+
[language]: 1,
|
|
18
|
+
},
|
|
17
19
|
},
|
|
18
20
|
},
|
|
19
21
|
{
|
|
@@ -22,7 +24,7 @@ export const composeGetTranslationsAsDictionaryAggregates = ({ codes, language }
|
|
|
22
24
|
root: {
|
|
23
25
|
$push: {
|
|
24
26
|
k: '$code',
|
|
25
|
-
v:
|
|
27
|
+
v: `$translation.${language}`,
|
|
26
28
|
},
|
|
27
29
|
},
|
|
28
30
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CacheKey } from '../../cache/common/index.js';
|
|
2
|
+
import { Page } from '../../common/index.js';
|
|
3
|
+
export type MessageBroker = {
|
|
4
|
+
'cache-service:refresh-cache': {
|
|
5
|
+
cacheKeys?: CacheKey[];
|
|
6
|
+
pageDictionaries?: Page[];
|
|
7
|
+
pageServerData?: Array<'candles-page' | 'home-page' | 'persons-page' | 'persons-map-page'>;
|
|
8
|
+
} | 'full';
|
|
9
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GetChannel, Init } from './type.js';
|
|
2
|
+
export declare const BaseMessageBrokerSingleton: {
|
|
3
|
+
errorWorker: {
|
|
4
|
+
addCustomErrorInfo: import("../../../../common/custom-error/workers/type.js").AddCustomErrorInfo;
|
|
5
|
+
addCustomErrorMessage: import("../../../../common/custom-error/workers/type.js").AddCustomErrorMessage;
|
|
6
|
+
composeCustomError: import("../../../../common/custom-error/workers/type.js").ComposeCustomError;
|
|
7
|
+
getCustomError: import("../../../../common/custom-error/workers/type.js").GetCustomError;
|
|
8
|
+
resetCustomError: import("../../../../common/custom-error/workers/type.js").ResetCustomError;
|
|
9
|
+
};
|
|
10
|
+
getChannel: GetChannel;
|
|
11
|
+
init: Init;
|
|
12
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import amqp from 'amqplib';
|
|
2
|
+
import { CustomErrorWorker } from '../../../../common/index.js';
|
|
3
|
+
export const BaseMessageBrokerSingleton = (() => {
|
|
4
|
+
let _channel;
|
|
5
|
+
let _connection;
|
|
6
|
+
let _url;
|
|
7
|
+
const errorWorker = CustomErrorWorker();
|
|
8
|
+
const _handleError = (err) => {
|
|
9
|
+
errorWorker.addCustomErrorMessage('Error connect RabbitMQ');
|
|
10
|
+
errorWorker.addCustomErrorInfo({ err });
|
|
11
|
+
setTimeout(() => _connect(), 5000);
|
|
12
|
+
};
|
|
13
|
+
const _connect = async () => {
|
|
14
|
+
if (!_url) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
_connection = await amqp.connect(_url);
|
|
19
|
+
_connection.on('error', (err) => {
|
|
20
|
+
_handleError(err);
|
|
21
|
+
});
|
|
22
|
+
_channel = await _connection.createChannel();
|
|
23
|
+
console.info('Successfully connected to RabbitMQ!');
|
|
24
|
+
errorWorker.resetCustomError();
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
_handleError(err);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const getChannel = () => {
|
|
31
|
+
if (!_channel) {
|
|
32
|
+
return {
|
|
33
|
+
customError: errorWorker.composeCustomError('MessageBrokerSingleton not initialized'),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
data: _channel,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const init = (url) => {
|
|
41
|
+
const error = errorWorker.getCustomError();
|
|
42
|
+
if (error) {
|
|
43
|
+
return error;
|
|
44
|
+
}
|
|
45
|
+
errorWorker.addCustomErrorMessage('MessageBroker initializing...');
|
|
46
|
+
_url = url;
|
|
47
|
+
_connect();
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
errorWorker,
|
|
51
|
+
getChannel,
|
|
52
|
+
init,
|
|
53
|
+
};
|
|
54
|
+
})();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import amqp from 'amqplib';
|
|
2
|
+
import { CustomError, TCustomError } from '../../../../common/index.js';
|
|
3
|
+
export type _Connect = () => Promise<void>;
|
|
4
|
+
export type _HandleError = (err: unknown) => void;
|
|
5
|
+
export type GetChannel = () => TCustomError<amqp.Channel>;
|
|
6
|
+
export type Init = (url: string) => {
|
|
7
|
+
customError: CustomError;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { composeCustomError, consoleCustomError, stringify } from '../../../common/index.js';
|
|
2
|
+
import { BaseMessageBrokerSingleton } from './base/index.js';
|
|
3
|
+
export const MessageBrokerSingleton = (() => {
|
|
4
|
+
const { errorWorker, getChannel, init } = BaseMessageBrokerSingleton;
|
|
5
|
+
const listenQueue = async (queueName, onMessage) => {
|
|
6
|
+
errorWorker.addCustomErrorInfo({ queueName, onMessage });
|
|
7
|
+
const { data: channel, customError } = getChannel();
|
|
8
|
+
if (customError) {
|
|
9
|
+
setTimeout(() => listenQueue(queueName, onMessage), 5000);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
await channel.assertQueue(queueName, { durable: true });
|
|
13
|
+
channel.consume(queueName, (msg) => {
|
|
14
|
+
if (msg) {
|
|
15
|
+
let parsedMsg;
|
|
16
|
+
try {
|
|
17
|
+
parsedMsg = JSON.parse(msg.content.toString());
|
|
18
|
+
onMessage(parsedMsg);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
const error = composeCustomError('Error parsing message', { err, msg });
|
|
22
|
+
consoleCustomError(error);
|
|
23
|
+
}
|
|
24
|
+
channel.ack(msg);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const sendMessage = async (queueName, message) => {
|
|
29
|
+
errorWorker.addCustomErrorInfo({ message, queueName });
|
|
30
|
+
const { data: channel, customError } = getChannel();
|
|
31
|
+
if (customError) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await channel.assertQueue(queueName, { durable: true });
|
|
35
|
+
channel.sendToQueue(queueName, Buffer.from(stringify(message)));
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
init,
|
|
39
|
+
listenQueue,
|
|
40
|
+
sendMessage,
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MessageBrokerQueueName } from '../../message-broker-queue-name/index.js';
|
|
2
|
+
import { MessageBroker } from '../domains.js';
|
|
3
|
+
export type ListenQueue = <T extends MessageBrokerQueueName>(queueName: T, onMessage: (message: MessageBroker[T]) => void) => Promise<void>;
|
|
4
|
+
export type SendMessage = <T extends MessageBrokerQueueName>(queueName: T, message: MessageBroker[T]) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@candlerip/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.86",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "=22.19.0"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"./aws/sdk": "./aws/sdk/index.js",
|
|
13
13
|
"./cache/common": "./cache/common/index.js",
|
|
14
14
|
"./cache/redis": "./cache/redis/index.js",
|
|
15
|
-
"./database": "./database/index.js"
|
|
15
|
+
"./database": "./database/index.js",
|
|
16
|
+
"./message-broker": "./message-broker/index.js"
|
|
16
17
|
},
|
|
17
18
|
"scripts": {
|
|
18
19
|
"dev": "crs-tsc-watch"
|
|
@@ -22,7 +23,9 @@
|
|
|
22
23
|
"@aws-sdk/client-route-53": "^3.936.0",
|
|
23
24
|
"@aws-sdk/client-sqs": "^3.936.0",
|
|
24
25
|
"@candlerip/shared-devops": "^0.0.50",
|
|
26
|
+
"@types/amqplib": "^0.10.8",
|
|
25
27
|
"@types/node": "^24.9.1",
|
|
28
|
+
"amqplib": "^0.10.9",
|
|
26
29
|
"aws-cdk-lib": "^2.227.0",
|
|
27
30
|
"eslint": "^9.39.0",
|
|
28
31
|
"globals": "^16.5.0",
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { SqsWorker } from '../../../../aws/sdk/index.js';
|
|
2
|
-
import { LANGUAGES } from '../../../../common/index.js';
|
|
3
|
-
export const CacheServiceSqsWorker = ({ awsRegion, environmentMode }) => {
|
|
4
|
-
const _sqsWorker = SqsWorker({ awsRegion });
|
|
5
|
-
const refreshCache = async (props) => {
|
|
6
|
-
let refreshCache;
|
|
7
|
-
if (!props) {
|
|
8
|
-
refreshCache = 'full';
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
const { cacheKeys, pageDictionaries, pageServerData } = props;
|
|
12
|
-
const updatableCacheKeys = [];
|
|
13
|
-
if (cacheKeys) {
|
|
14
|
-
updatableCacheKeys.forEach((it) => updatableCacheKeys.push(it));
|
|
15
|
-
}
|
|
16
|
-
if (pageDictionaries) {
|
|
17
|
-
pageDictionaries.forEach((page) => {
|
|
18
|
-
LANGUAGES.forEach((lang) => {
|
|
19
|
-
updatableCacheKeys.push(`${page}-dictionary-${lang}`);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (pageServerData) {
|
|
24
|
-
pageServerData.forEach((page) => {
|
|
25
|
-
LANGUAGES.forEach((lang) => {
|
|
26
|
-
updatableCacheKeys.push(`${page}-server-data-${lang}`);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
refreshCache = {
|
|
31
|
-
cacheKeys: updatableCacheKeys,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
await _sqsWorker.sendSqsMessage(`cache-service-${environmentMode}`, { refreshCache });
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
refreshCache,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { EnvironmentMode, Page } from '../../../../common/index.js';
|
|
2
|
-
import { AwsRegion } from '../../../../aws/common/index.js';
|
|
3
|
-
import { CacheKey } from '../../cache-key/index.js';
|
|
4
|
-
export type TCacheServiceSqsWorker = (props: {
|
|
5
|
-
awsRegion: AwsRegion;
|
|
6
|
-
environmentMode: EnvironmentMode;
|
|
7
|
-
}) => {
|
|
8
|
-
refreshCache: RefreshCache;
|
|
9
|
-
};
|
|
10
|
-
export type RefreshCache = (props?: {
|
|
11
|
-
cacheKeys?: CacheKey[];
|
|
12
|
-
pageDictionaries?: Page[];
|
|
13
|
-
pageServerData?: Array<'candles-page' | 'home-page' | 'persons-page' | 'persons-map-page'>;
|
|
14
|
-
}) => Promise<void>;
|
/package/{cache/common/cache-service/workers/type.js → message-broker/message-broker/domains.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|