@wabot-dev/framework 0.1.0-beta.6 → 0.1.0-beta.60
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 +53 -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 +35 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +28 -0
- package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +42 -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 +23 -0
- package/dist/src/{channels → addon/chat-controller}/cmd/CmdChannel.js +4 -26
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +5 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +9 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +25 -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 +20 -41
- 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 +26 -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 +60 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/addon/mindset/html/HtmlModule.js +70 -0
- package/dist/src/core/auth/Auth.js +24 -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/validateIsOptional.js +5 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/core/validation/metadata/@isArray.js +18 -0
- package/dist/src/core/validation/metadata/@isModel.js +18 -0
- package/dist/src/core/validation/metadata/@isOptional.js +17 -0
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/core/validation/validate.js +11 -0
- package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +17 -0
- package/dist/src/core/validation/validators/is-boolean/validateIsBoolean.js +12 -0
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-date/validateIsDate.js +16 -0
- package/dist/src/core/validation/validators/is-not-empty/@isNotEmpty.js +17 -0
- package/dist/src/core/validation/validators/is-not-empty/validateIsNotEmpty.js +12 -0
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/core/validation/validators/is-number/validateIsNumber.js +12 -0
- package/dist/src/core/validation/validators/is-present/@isPresent.js +17 -0
- package/dist/src/core/validation/validators/is-present/validateIsPresent.js +12 -0
- package/dist/src/core/validation/validators/is-string/@isString.js +17 -0
- package/dist/src/core/validation/validators/is-string/validateIsString.js +12 -0
- package/dist/src/core/validation/validators/max/@max.js +18 -0
- package/dist/src/core/validation/validators/max/validateMax.js +17 -0
- package/dist/src/core/validation/validators/min/@min.js +18 -0
- package/dist/src/core/validation/validators/min/validateMin.js +17 -0
- 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 +69 -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 +3 -0
- package/dist/src/{mindset → feature/mindset}/MindsetOperator.js +69 -42
- 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 +30 -9
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/feature/rest-controller/metadata/@middleware.js +16 -0
- 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/feature/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/feature/rest-controller/metadata/RestControllerMetadataStore.js +50 -0
- package/dist/src/feature/rest-controller/metadata/methodDecorator.js +19 -0
- 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 +1202 -575
- package/dist/src/index.js +145 -76
- package/package.json +10 -4
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -106
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/channels/cmd/@cmd.js +0 -18
- 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/metadata/params/@isOptional.js +0 -21
- 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/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- /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/{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,51 @@
|
|
|
1
|
+
function validateArray(value, options) {
|
|
2
|
+
if (!Array.isArray(value)) {
|
|
3
|
+
return {
|
|
4
|
+
error: { description: 'Should be an array', items: [] },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
if (options?.minLength != null && value.length < options.minLength) {
|
|
8
|
+
return {
|
|
9
|
+
error: { description: 'exceeds the established min length limit', items: [] },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (options?.maxLength != null && value.length > options.maxLength) {
|
|
13
|
+
return {
|
|
14
|
+
error: { description: 'exceeds the established max length limit', items: [] },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const { itemsValidator } = options ?? {};
|
|
18
|
+
const valueOut = [];
|
|
19
|
+
const errorItems = [];
|
|
20
|
+
for (const item of value) {
|
|
21
|
+
let itemOut = item;
|
|
22
|
+
const itemErrors = [];
|
|
23
|
+
for (const itemValidator of itemsValidator ?? []) {
|
|
24
|
+
const { error, value } = itemValidator.validator(itemOut, itemValidator.options);
|
|
25
|
+
if (error) {
|
|
26
|
+
itemErrors.push(error);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
itemOut = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (itemErrors.length == 0) {
|
|
33
|
+
valueOut.push(itemOut);
|
|
34
|
+
errorItems.push(null);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
valueOut.push(null);
|
|
38
|
+
errorItems.push(itemErrors);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (errorItems.some((x) => x != null)) {
|
|
42
|
+
return {
|
|
43
|
+
error: { description: 'Error on some items', items: errorItems },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
value: valueOut,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { validateArray };
|
|
@@ -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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { validateArray } from '../core/validateArray.js';
|
|
3
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isArray(options) {
|
|
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: validateArray,
|
|
13
|
+
validatorOptions: options,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isArray };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { validateModel } from '../core/validateModel.js';
|
|
3
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
4
|
+
|
|
5
|
+
function isModel(model) {
|
|
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: validateModel,
|
|
13
|
+
validatorOptions: store.getModelValidatorsInfo(model),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isModel };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../core/validateIsOptional.js';
|
|
4
|
+
|
|
5
|
+
function isOptional() {
|
|
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: _IS_OPTIONAL_DUMMY_VALIDATOR_,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isOptional };
|
|
@@ -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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { container } from '../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateModel } from './core/validateModel.js';
|
|
4
|
+
|
|
5
|
+
function validate(value, modelConstructor) {
|
|
6
|
+
const metadataStore = container.resolve(ValidationMetadataStore);
|
|
7
|
+
const info = metadataStore.getModelValidatorsInfo(modelConstructor);
|
|
8
|
+
return validateModel(value, info);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { validate };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsBoolean } from './validateIsBoolean.js';
|
|
4
|
+
|
|
5
|
+
function isBoolean() {
|
|
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: validateIsBoolean,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isBoolean };
|
|
@@ -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,16 @@
|
|
|
1
|
+
function validateIsDate(value) {
|
|
2
|
+
const _value = new Date(value);
|
|
3
|
+
const time = _value.getTime();
|
|
4
|
+
if ((typeof value !== 'number' && typeof value !== 'string' && !(value instanceof Date)) ||
|
|
5
|
+
isNaN(time) ||
|
|
6
|
+
time < 0) {
|
|
7
|
+
return {
|
|
8
|
+
error: { description: `Date value is not valid` },
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
value: _value,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { validateIsDate };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsNotEmpty } from './validateIsNotEmpty.js';
|
|
4
|
+
|
|
5
|
+
function isNotEmpty() {
|
|
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: validateIsNotEmpty,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isNotEmpty };
|
|
@@ -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 };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsPresent } from './validateIsPresent.js';
|
|
4
|
+
|
|
5
|
+
function isPresent() {
|
|
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: validateIsPresent,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isPresent };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsString } from './validateIsString.js';
|
|
4
|
+
|
|
5
|
+
function isString() {
|
|
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: validateIsString,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isString };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateMax } from './validateMax.js';
|
|
4
|
+
|
|
5
|
+
function max(limit) {
|
|
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: validateMax,
|
|
13
|
+
validatorOptions: { limit },
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { max };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function validateMax(value, options) {
|
|
2
|
+
if (value == null) {
|
|
3
|
+
return {
|
|
4
|
+
error: { description: `null or undefined value can't be validated with max` },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
if (Number(value) > Number(options.limit)) {
|
|
8
|
+
return {
|
|
9
|
+
error: { description: `exceeds the established max limit` },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
value,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { validateMax };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateMin } from './validateMin.js';
|
|
4
|
+
|
|
5
|
+
function min(limit) {
|
|
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: validateMin,
|
|
13
|
+
validatorOptions: { limit },
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { min };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function validateMin(value, options) {
|
|
2
|
+
if (value == null) {
|
|
3
|
+
return {
|
|
4
|
+
error: { description: `null or undefined value can't be validated with min` },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
if (Number(value) < Number(options.limit)) {
|
|
8
|
+
return {
|
|
9
|
+
error: { description: `exceeds the established min limit` },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
value,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { validateMin };
|
|
@@ -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 };
|