@wabot-dev/framework 0.1.0-beta.9 → 0.2.0-beta.1
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/dist/src/addon/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
- package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
- package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
- package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
- package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/auth/jwt/Jwt.js +53 -0
- package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
- package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
- package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
- package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
- package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
- package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
- package/dist/src/core/auth/Auth.js +33 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
- package/dist/src/core/env/Env.js +39 -0
- package/dist/src/core/error/CustomError.js +15 -0
- package/dist/src/core/injection/index.js +4 -0
- package/dist/src/core/mapper/Mapper.js +42 -0
- package/dist/src/core/password/Password.js +30 -0
- package/dist/src/core/random/Random.js +65 -0
- package/dist/src/core/storable/Storable.js +8 -0
- package/dist/src/core/validation/core/validateArray.js +51 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
- package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
- package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
- package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
- package/dist/src/feature/async/@command.js +11 -0
- package/dist/src/feature/async/@commandHandler.js +12 -0
- package/dist/src/feature/async/Async.js +38 -0
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/feature/async/CommandMetadataStore.js +38 -0
- package/dist/src/feature/async/Job.js +27 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +48 -0
- package/dist/src/feature/async/JobsEventsHub.js +36 -0
- package/dist/src/feature/async/runCommandHandlers.js +29 -0
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +73 -0
- package/dist/src/feature/chat-bot/ChatItem.js +24 -0
- package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
- package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
- package/dist/src/feature/chat-bot/IChatItem.js +3 -0
- package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
- package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
- package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
- package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
- package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
- package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
- package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
- package/dist/src/feature/mindset/MindsetOperator.js +180 -0
- package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
- package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
- package/dist/src/feature/money/Money.js +61 -0
- package/dist/src/feature/money/MoneyDto.js +22 -0
- package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
- package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
- package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
- package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
- package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
- package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
- package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
- package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
- package/dist/src/index.d.ts +1219 -718
- package/dist/src/index.js +147 -102
- package/package.json +8 -2
- package/dist/src/_virtual/_commonjsHelpers.js +0 -5
- package/dist/src/_virtual/cjs.js +0 -7
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/cmd/CmdChannel.js +0 -73
- package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
- package/dist/src/chatbot/ChatBot.js +0 -51
- package/dist/src/chatbot/ChatBotAdapter.js +0 -72
- package/dist/src/controller/channel/UserResolver.js +0 -21
- package/dist/src/core/IMessageContext.js +0 -12
- package/dist/src/core/chat/ChatItem.js +0 -15
- package/dist/src/core/chat/repository/IChatMemory.js +0 -10
- package/dist/src/core/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/env/WabotEnv.js +0 -27
- package/dist/src/injection/index.js +0 -4
- package/dist/src/mindset/MindsetOperator.js +0 -101
- package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
- package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
- package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
- package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
- package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
- package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
- package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
- package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
- package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
- package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
- package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
- package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
- package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
- package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
- package/dist/src/node_modules/leac/lib/leac.js +0 -3
- package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
- package/dist/src/node_modules/peberminta/lib/core.js +0 -171
- package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
- package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
- package/dist/src/pre-made/service/EmailService.js +0 -13
- package/dist/src/pre-made/service/OtpService.js +0 -14
- package/dist/src/rest-controller/runRestControllers.js +0 -74
- package/dist/src/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- package/dist/src/validation/metadata/@validable.js +0 -14
- package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
- package/dist/src/validation/validators/validateModel.js +0 -47
- /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.js +0 -0
- /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function validateModel(value, info) {
|
|
2
|
+
if (typeof value !== 'object' || value === null) {
|
|
3
|
+
return { error: { description: 'Invalid object', properties: {} } };
|
|
4
|
+
}
|
|
5
|
+
let propertiesErrors = {};
|
|
6
|
+
let resultValue = new info.modelConstructor();
|
|
7
|
+
for (const propertyName in info.properties) {
|
|
8
|
+
const propertyInfo = info.properties[propertyName];
|
|
9
|
+
const propertyValidators = propertyInfo.validators ?? [];
|
|
10
|
+
resultValue[propertyName] = propertyInfo.isOptional
|
|
11
|
+
? (value[propertyName] ?? resultValue[propertyName])
|
|
12
|
+
: value[propertyName];
|
|
13
|
+
if (resultValue[propertyName] == null && propertyInfo.isOptional) {
|
|
14
|
+
resultValue[propertyName] = undefined;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
for (let propertyValidatorInfo of propertyValidators) {
|
|
18
|
+
const propertyValidatorResult = propertyValidatorInfo.validator(resultValue[propertyName], propertyValidatorInfo.validatorOptions);
|
|
19
|
+
resultValue[propertyName] = propertyValidatorResult.value;
|
|
20
|
+
if (propertyValidatorResult.error) {
|
|
21
|
+
let propertyErrors = propertiesErrors[propertyName];
|
|
22
|
+
if (!propertyErrors) {
|
|
23
|
+
propertyErrors = [];
|
|
24
|
+
propertiesErrors[propertyName] = propertyErrors;
|
|
25
|
+
}
|
|
26
|
+
propertyErrors.push(propertyValidatorResult.error.description);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (Object.keys(propertiesErrors).length > 0) {
|
|
31
|
+
return { error: { description: 'Invalid properties', properties: propertiesErrors } };
|
|
32
|
+
}
|
|
33
|
+
return { value: resultValue };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { validateModel };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { container } from '../../injection/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { validateArray } from '../core/validateArray.js';
|
|
3
3
|
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function isArray(options) {
|
|
6
6
|
return function (target, propertyKey) {
|
|
7
7
|
const propertyName = propertyKey.toString();
|
|
8
8
|
const store = container.resolve(ValidationMetadataStore);
|
|
9
9
|
store.saveValidatorMetadata({
|
|
10
10
|
modelConstructor: target.constructor,
|
|
11
11
|
propertyName,
|
|
12
|
-
validator:
|
|
12
|
+
validator: validateArray,
|
|
13
|
+
validatorOptions: options,
|
|
13
14
|
});
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export {
|
|
18
|
+
export { isArray };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { container } from '../../injection/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { validateModel } from '../core/validateModel.js';
|
|
3
3
|
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function isModel(model) {
|
|
6
6
|
return function (target, propertyKey) {
|
|
7
7
|
const propertyName = propertyKey.toString();
|
|
8
8
|
const store = container.resolve(ValidationMetadataStore);
|
|
9
9
|
store.saveValidatorMetadata({
|
|
10
10
|
modelConstructor: target.constructor,
|
|
11
11
|
propertyName,
|
|
12
|
-
validator:
|
|
12
|
+
validator: validateModel,
|
|
13
|
+
validatorOptions: store.getModelValidatorsInfo(model),
|
|
13
14
|
});
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export {
|
|
18
|
+
export { isModel };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { container } from '../../injection/index.js';
|
|
2
2
|
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
-
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../
|
|
3
|
+
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../core/validateIsOptional.js';
|
|
4
4
|
|
|
5
5
|
function isOptional() {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from '../../injection/index.js';
|
|
3
|
+
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../core/validateIsOptional.js';
|
|
4
|
+
import { validateArray } from '../core/validateArray.js';
|
|
5
|
+
|
|
6
|
+
function getClassHierarchy(cls) {
|
|
7
|
+
const classes = [];
|
|
8
|
+
let proto = Object.getPrototypeOf(cls.prototype);
|
|
9
|
+
while (proto && proto.constructor !== Object) {
|
|
10
|
+
classes.push(proto.constructor);
|
|
11
|
+
proto = Object.getPrototypeOf(proto);
|
|
12
|
+
}
|
|
13
|
+
return classes;
|
|
14
|
+
}
|
|
15
|
+
let ValidationMetadataStore = class ValidationMetadataStore {
|
|
16
|
+
validators = new Map();
|
|
17
|
+
saveValidatorMetadata(validatorMetadata) {
|
|
18
|
+
let modelValidators = this.validators.get(validatorMetadata.modelConstructor);
|
|
19
|
+
if (!modelValidators) {
|
|
20
|
+
this.validators.set(validatorMetadata.modelConstructor, (modelValidators = new Map()));
|
|
21
|
+
}
|
|
22
|
+
let propertyValidators = modelValidators.get(validatorMetadata.propertyName);
|
|
23
|
+
if (!propertyValidators) {
|
|
24
|
+
propertyValidators = [];
|
|
25
|
+
modelValidators.set(validatorMetadata.propertyName, propertyValidators);
|
|
26
|
+
}
|
|
27
|
+
propertyValidators.unshift(validatorMetadata);
|
|
28
|
+
const arrayValidatorMetadata = propertyValidators.find((x) => x.validator === validateArray);
|
|
29
|
+
if (!arrayValidatorMetadata) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!arrayValidatorMetadata.validatorOptions) {
|
|
33
|
+
arrayValidatorMetadata.validatorOptions = {};
|
|
34
|
+
}
|
|
35
|
+
const arrayValidatorOptions = arrayValidatorMetadata.validatorOptions;
|
|
36
|
+
if (!arrayValidatorOptions.itemsValidator) {
|
|
37
|
+
arrayValidatorOptions.itemsValidator = [];
|
|
38
|
+
}
|
|
39
|
+
const removeValidatorsMetadata = [];
|
|
40
|
+
for (const validatorMetadata of propertyValidators) {
|
|
41
|
+
if (validatorMetadata.validator === validateArray ||
|
|
42
|
+
validatorMetadata.validator === _IS_OPTIONAL_DUMMY_VALIDATOR_) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
arrayValidatorOptions.itemsValidator.push({
|
|
46
|
+
options: validatorMetadata.validatorOptions,
|
|
47
|
+
validator: validatorMetadata.validator,
|
|
48
|
+
});
|
|
49
|
+
removeValidatorsMetadata.push(validatorMetadata);
|
|
50
|
+
}
|
|
51
|
+
for (const toRemove of removeValidatorsMetadata) {
|
|
52
|
+
const indexToRemove = propertyValidators.indexOf(toRemove);
|
|
53
|
+
propertyValidators.splice(indexToRemove, 1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
getModelValidatorsInfo(modelConstructor) {
|
|
57
|
+
const constructors = getClassHierarchy(modelConstructor);
|
|
58
|
+
constructors.unshift(modelConstructor);
|
|
59
|
+
const modelValidators = {
|
|
60
|
+
modelConstructor: modelConstructor,
|
|
61
|
+
properties: Object.assign({}, ...constructors.map((x) => this.getConstructorPropertiesValidatorsInfo(x))),
|
|
62
|
+
};
|
|
63
|
+
return modelValidators;
|
|
64
|
+
}
|
|
65
|
+
getConstructorPropertiesValidatorsInfo(modelConstructor) {
|
|
66
|
+
const properties = {};
|
|
67
|
+
[...(this.validators.get(modelConstructor)?.values() ?? [])].forEach((propertyValidatorsMetadata) => {
|
|
68
|
+
const propertyName = propertyValidatorsMetadata.at(0)?.propertyName;
|
|
69
|
+
if (!propertyName) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let propertyInfo = properties[propertyName];
|
|
73
|
+
if (!propertyInfo) {
|
|
74
|
+
propertyInfo = {};
|
|
75
|
+
properties[propertyName] = propertyInfo;
|
|
76
|
+
}
|
|
77
|
+
let validators = propertyInfo.validators;
|
|
78
|
+
if (!validators) {
|
|
79
|
+
validators = [];
|
|
80
|
+
propertyInfo.validators = validators;
|
|
81
|
+
}
|
|
82
|
+
propertyValidatorsMetadata.forEach((propertyValidatorMetadata) => {
|
|
83
|
+
if (propertyValidatorMetadata.validator === _IS_OPTIONAL_DUMMY_VALIDATOR_) {
|
|
84
|
+
propertyInfo.isOptional = true;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
validators.push(propertyValidatorMetadata);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return properties;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
ValidationMetadataStore = __decorate([
|
|
95
|
+
singleton()
|
|
96
|
+
], ValidationMetadataStore);
|
|
97
|
+
|
|
98
|
+
export { ValidationMetadataStore };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { container } from '../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './metadata/ValidationMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function modelInfo(modelConstructor) {
|
|
5
|
+
const metadataStore = container.resolve(ValidationMetadataStore);
|
|
6
|
+
return metadataStore.getModelValidatorsInfo(modelConstructor);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { modelInfo };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { container } from '../injection/index.js';
|
|
2
2
|
import { ValidationMetadataStore } from './metadata/ValidationMetadataStore.js';
|
|
3
|
-
import { validateModel } from './
|
|
3
|
+
import { validateModel } from './core/validateModel.js';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function validate(value, modelConstructor) {
|
|
6
6
|
const metadataStore = container.resolve(ValidationMetadataStore);
|
|
7
7
|
const info = metadataStore.getModelValidatorsInfo(modelConstructor);
|
|
8
8
|
return validateModel(value, info);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export { validate };
|
package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { container } from '
|
|
2
|
-
import { ValidationMetadataStore } from '
|
|
3
|
-
import { validateIsBoolean } from '
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsBoolean } from './validateIsBoolean.js';
|
|
4
4
|
|
|
5
5
|
function isBoolean() {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { validateIsDate } from './validateIsDate.js';
|
|
3
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isDate() {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateIsDate,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isDate };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { validateIsIn } from './validateIsIn.js';
|
|
3
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isIn(values) {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateIsIn,
|
|
13
|
+
validatorOptions: { values },
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isIn };
|
package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { container } from '
|
|
2
|
-
import { ValidationMetadataStore } from '
|
|
3
|
-
import { validateIsNotEmpty } from '
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsNotEmpty } from './validateIsNotEmpty.js';
|
|
4
4
|
|
|
5
5
|
function isNotEmpty() {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { validateIsNumber } from './validateIsNumber.js';
|
|
3
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isNumber() {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateIsNumber,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isNumber };
|
package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { container } from '
|
|
2
|
-
import { ValidationMetadataStore } from '
|
|
3
|
-
import { validateIsPresent } from '
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsPresent } from './validateIsPresent.js';
|
|
4
4
|
|
|
5
5
|
function isPresent() {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { container } from '
|
|
2
|
-
import { ValidationMetadataStore } from '
|
|
3
|
-
import { validateIsString } from '
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsString } from './validateIsString.js';
|
|
4
4
|
|
|
5
5
|
function isString() {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { container } from '
|
|
2
|
-
import { ValidationMetadataStore } from '
|
|
3
|
-
import { validateMax } from '
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateMax } from './validateMax.js';
|
|
4
4
|
|
|
5
5
|
function max(limit) {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { container } from '
|
|
2
|
-
import { ValidationMetadataStore } from '
|
|
3
|
-
import { validateMin } from '
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateMin } from './validateMin.js';
|
|
4
4
|
|
|
5
5
|
function min(limit) {
|
|
6
6
|
return function (target, propertyKey) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommandMetadataStore } from './CommandMetadataStore.js';
|
|
2
|
+
import { container } from '../../core/injection/index.js';
|
|
3
|
+
|
|
4
|
+
function command(config) {
|
|
5
|
+
return function (target) {
|
|
6
|
+
const handlerContainer = container.resolve(CommandMetadataStore);
|
|
7
|
+
handlerContainer.registerCommand(target, config?.name ?? target.name);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { command };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CommandMetadataStore } from './CommandMetadataStore.js';
|
|
2
|
+
import { container, injectable } from '../../core/injection/index.js';
|
|
3
|
+
|
|
4
|
+
function commandHandler(config) {
|
|
5
|
+
return function (target) {
|
|
6
|
+
const handlerContainer = container.resolve(CommandMetadataStore);
|
|
7
|
+
handlerContainer.registerHandler(config.command, target);
|
|
8
|
+
injectable()(target);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { commandHandler };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { singleton } from '../../core/injection/index.js';
|
|
3
|
+
import { CommandMetadataStore } from './CommandMetadataStore.js';
|
|
4
|
+
import { Job } from './Job.js';
|
|
5
|
+
import { JobRepository } from './JobRepository.js';
|
|
6
|
+
import { JobsEventsHub } from './JobsEventsHub.js';
|
|
7
|
+
|
|
8
|
+
let Async = class Async {
|
|
9
|
+
jobRepository;
|
|
10
|
+
handlerContainer;
|
|
11
|
+
jobsEventsHub;
|
|
12
|
+
constructor(jobRepository, handlerContainer, jobsEventsHub) {
|
|
13
|
+
this.jobRepository = jobRepository;
|
|
14
|
+
this.handlerContainer = handlerContainer;
|
|
15
|
+
this.jobsEventsHub = jobsEventsHub;
|
|
16
|
+
}
|
|
17
|
+
async run(command) {
|
|
18
|
+
const commandName = this.handlerContainer.getCommandName(command.constructor);
|
|
19
|
+
if (!commandName) {
|
|
20
|
+
throw new Error(`${command.constructor.name} is not registered as command`);
|
|
21
|
+
}
|
|
22
|
+
const job = new Job({
|
|
23
|
+
commandName,
|
|
24
|
+
commandData: command['data'],
|
|
25
|
+
});
|
|
26
|
+
await this.jobRepository.create(job);
|
|
27
|
+
this.jobsEventsHub.notifyJobCreated(job);
|
|
28
|
+
return job;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Async = __decorate([
|
|
32
|
+
singleton(),
|
|
33
|
+
__metadata("design:paramtypes", [JobRepository,
|
|
34
|
+
CommandMetadataStore,
|
|
35
|
+
JobsEventsHub])
|
|
36
|
+
], Async);
|
|
37
|
+
|
|
38
|
+
export { Async };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from '../../core/injection/index.js';
|
|
3
|
+
|
|
4
|
+
let CommandMetadataStore = class CommandMetadataStore {
|
|
5
|
+
handlersMap = new Map();
|
|
6
|
+
handlersInverseMap = new Map();
|
|
7
|
+
commandsMap = new Map();
|
|
8
|
+
commandsInverseMap = new Map();
|
|
9
|
+
registerCommand(command, commandName) {
|
|
10
|
+
this.commandsMap.set(commandName, command);
|
|
11
|
+
this.commandsInverseMap.set(command, commandName);
|
|
12
|
+
}
|
|
13
|
+
registerHandler(command, handlerConstructor) {
|
|
14
|
+
let commandName = this.commandsInverseMap.get(command);
|
|
15
|
+
if (!commandName) {
|
|
16
|
+
throw new Error(`Should use @command decorator on command class ${command.name}`);
|
|
17
|
+
}
|
|
18
|
+
this.handlersMap.set(commandName, handlerConstructor);
|
|
19
|
+
this.handlersInverseMap.set(handlerConstructor, commandName);
|
|
20
|
+
}
|
|
21
|
+
getHandlerForCommandName(commandName) {
|
|
22
|
+
return this.handlersMap.get(commandName) ?? null;
|
|
23
|
+
}
|
|
24
|
+
getCommandNameForHandler(handlerConstructor) {
|
|
25
|
+
return this.handlersInverseMap.get(handlerConstructor) ?? null;
|
|
26
|
+
}
|
|
27
|
+
getCommandName(command) {
|
|
28
|
+
return this.commandsInverseMap.get(command) ?? null;
|
|
29
|
+
}
|
|
30
|
+
getCommandForCommandName(commandName) {
|
|
31
|
+
return this.commandsMap.get(commandName) ?? null;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
CommandMetadataStore = __decorate([
|
|
35
|
+
singleton()
|
|
36
|
+
], CommandMetadataStore);
|
|
37
|
+
|
|
38
|
+
export { CommandMetadataStore };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Entity } from '../../core/entity/Entity.js';
|
|
2
|
+
import { CustomError } from '../../core/error/CustomError.js';
|
|
3
|
+
|
|
4
|
+
class Job extends Entity {
|
|
5
|
+
get commandName() {
|
|
6
|
+
return this.data.commandName;
|
|
7
|
+
}
|
|
8
|
+
hasFinished() {
|
|
9
|
+
return this.data.successAt != null || this.data.failedAt != null;
|
|
10
|
+
}
|
|
11
|
+
setAsStarted() {
|
|
12
|
+
this.data.startedAt = new Date().getTime();
|
|
13
|
+
}
|
|
14
|
+
setAsSuccess() {
|
|
15
|
+
this.data.successAt = new Date().getTime();
|
|
16
|
+
}
|
|
17
|
+
setAsFailed(error) {
|
|
18
|
+
this.data.failedAt = new Date().getTime();
|
|
19
|
+
this.data.error = {
|
|
20
|
+
message: error.message,
|
|
21
|
+
stack: error.stack,
|
|
22
|
+
info: error instanceof CustomError ? error.info : undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { Job };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from '../../core/injection/index.js';
|
|
3
|
+
|
|
4
|
+
let JobRepository = class JobRepository {
|
|
5
|
+
find(id) {
|
|
6
|
+
throw new Error('Method not implemented.');
|
|
7
|
+
}
|
|
8
|
+
findOrThrow(id) {
|
|
9
|
+
throw new Error('Method not implemented.');
|
|
10
|
+
}
|
|
11
|
+
findByIds(ids) {
|
|
12
|
+
throw new Error('Method not implemented.');
|
|
13
|
+
}
|
|
14
|
+
findAll(id) {
|
|
15
|
+
throw new Error('Method not implemented.');
|
|
16
|
+
}
|
|
17
|
+
create(item) {
|
|
18
|
+
throw new Error('Method not implemented.');
|
|
19
|
+
}
|
|
20
|
+
update(item) {
|
|
21
|
+
throw new Error('Method not implemented.');
|
|
22
|
+
}
|
|
23
|
+
delete(item) {
|
|
24
|
+
throw new Error('Method not implemented.');
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
JobRepository = __decorate([
|
|
28
|
+
singleton()
|
|
29
|
+
], JobRepository);
|
|
30
|
+
|
|
31
|
+
export { JobRepository };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { CommandMetadataStore } from './CommandMetadataStore.js';
|
|
3
|
+
import { JobRepository } from './JobRepository.js';
|
|
4
|
+
import { singleton, container } from '../../core/injection/index.js';
|
|
5
|
+
import { Logger } from '../../core/logger/Logger.js';
|
|
6
|
+
|
|
7
|
+
let JobRunner = class JobRunner {
|
|
8
|
+
jobRepository;
|
|
9
|
+
handlerContainer;
|
|
10
|
+
logger = new Logger('wabot:job-runner');
|
|
11
|
+
constructor(jobRepository, handlerContainer) {
|
|
12
|
+
this.jobRepository = jobRepository;
|
|
13
|
+
this.handlerContainer = handlerContainer;
|
|
14
|
+
}
|
|
15
|
+
async run(job) {
|
|
16
|
+
try {
|
|
17
|
+
const { commandName, commandData } = job['data'];
|
|
18
|
+
const handlerConstructor = this.handlerContainer.getHandlerForCommandName(commandName);
|
|
19
|
+
if (!handlerConstructor) {
|
|
20
|
+
throw new Error(`Not found handler for command '${commandName}'`);
|
|
21
|
+
}
|
|
22
|
+
const handler = container.resolve(handlerConstructor);
|
|
23
|
+
const commandConstructor = this.handlerContainer.getCommandForCommandName(commandName);
|
|
24
|
+
if (!commandConstructor) {
|
|
25
|
+
throw new Error(`Not found class for command name '${commandName}'`);
|
|
26
|
+
}
|
|
27
|
+
job.setAsStarted();
|
|
28
|
+
await this.jobRepository.update(job);
|
|
29
|
+
const command = new commandConstructor(commandData);
|
|
30
|
+
await handler.handle(command);
|
|
31
|
+
job.setAsSuccess();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
this.logger.error(e);
|
|
35
|
+
job.setAsFailed(e instanceof Error ? e : new Error('Invalid Job error'));
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await this.jobRepository.update(job);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
JobRunner = __decorate([
|
|
43
|
+
singleton(),
|
|
44
|
+
__metadata("design:paramtypes", [JobRepository,
|
|
45
|
+
CommandMetadataStore])
|
|
46
|
+
], JobRunner);
|
|
47
|
+
|
|
48
|
+
export { JobRunner };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from '../../core/injection/index.js';
|
|
3
|
+
import { Logger } from '../../core/logger/Logger.js';
|
|
4
|
+
|
|
5
|
+
let JobsEventsHub = class JobsEventsHub {
|
|
6
|
+
logger = new Logger('wabot:jobs-events-hub');
|
|
7
|
+
jobsEventsListener = null;
|
|
8
|
+
notifyJobCreated(job) {
|
|
9
|
+
const timer = setTimeout(async () => {
|
|
10
|
+
if (!this.jobsEventsListener) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
await this.jobsEventsListener({
|
|
15
|
+
jobId: job.id,
|
|
16
|
+
commandName: job.commandName,
|
|
17
|
+
type: 'created',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
this.logger.error(err);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
}
|
|
26
|
+
}, 1000);
|
|
27
|
+
}
|
|
28
|
+
listenJobsEvents(listener) {
|
|
29
|
+
this.jobsEventsListener = listener;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
JobsEventsHub = __decorate([
|
|
33
|
+
singleton()
|
|
34
|
+
], JobsEventsHub);
|
|
35
|
+
|
|
36
|
+
export { JobsEventsHub };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { JobsEventsHub } from './JobsEventsHub.js';
|
|
2
|
+
import { JobRunner } from './JobRunner.js';
|
|
3
|
+
import { CommandMetadataStore } from './CommandMetadataStore.js';
|
|
4
|
+
import { JobRepository } from './JobRepository.js';
|
|
5
|
+
import { container } from '../../core/injection/index.js';
|
|
6
|
+
|
|
7
|
+
function runAsyncCommandHandlers(handlers) {
|
|
8
|
+
const eventsHub = container.resolve(JobsEventsHub);
|
|
9
|
+
const jobRunner = container.resolve(JobRunner);
|
|
10
|
+
const jobRepository = container.resolve(JobRepository);
|
|
11
|
+
const commandsHandlersContainer = container.resolve(CommandMetadataStore);
|
|
12
|
+
const handledCommands = handlers
|
|
13
|
+
.map((x) => commandsHandlersContainer.getCommandNameForHandler(x))
|
|
14
|
+
.filter((x) => x)
|
|
15
|
+
.map((x) => x);
|
|
16
|
+
eventsHub.listenJobsEvents(async (event) => {
|
|
17
|
+
try {
|
|
18
|
+
const job = await jobRepository.findOrThrow(event.jobId);
|
|
19
|
+
if (handledCommands.includes(job.commandName)) {
|
|
20
|
+
jobRunner.run(job);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { runAsyncCommandHandlers };
|