@wabot-dev/framework 0.1.0-beta.6 → 0.1.0-beta.7
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/ai/deepseek/DeepSeekChatBotAdapter.js +9 -8
- package/dist/src/channels/whatsapp/WhatsAppSender.js +5 -2
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +1 -1
- package/dist/src/index.d.ts +140 -3
- package/dist/src/index.js +25 -1
- package/dist/src/mindset/MindsetOperator.js +1 -1
- package/dist/src/rest-controller/metadata/@get.js +19 -0
- package/dist/src/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +37 -0
- package/dist/src/rest-controller/runRestControllers.js +75 -0
- package/dist/src/validation/metadata/@isBoolean.js +17 -0
- package/dist/src/validation/metadata/@isDate.js +17 -0
- package/dist/src/validation/metadata/@isNotEmpty.js +17 -0
- package/dist/src/validation/metadata/@isNumber.js +17 -0
- package/dist/src/validation/metadata/@isOptional.js +19 -0
- package/dist/src/validation/metadata/@isPresent.js +17 -0
- package/dist/src/validation/metadata/@isString.js +17 -0
- package/dist/src/validation/metadata/@max.js +18 -0
- package/dist/src/validation/metadata/@min.js +18 -0
- package/dist/src/validation/metadata/@validable.js +14 -0
- package/dist/src/validation/metadata/ValidationMetadataStore.js +55 -0
- package/dist/src/validation/validateModel2.js +11 -0
- package/dist/src/validation/validators/validateIsBoolean.js +12 -0
- package/dist/src/validation/validators/validateIsDate.js +16 -0
- package/dist/src/validation/validators/validateIsNotEmpty.js +12 -0
- package/dist/src/validation/validators/validateIsNumber.js +12 -0
- package/dist/src/validation/validators/validateIsPresent.js +12 -0
- package/dist/src/validation/validators/validateIsString.js +12 -0
- package/dist/src/validation/validators/validateMax.js +17 -0
- package/dist/src/validation/validators/validateMin.js +17 -0
- package/dist/src/validation/validators/validateModel.js +47 -0
- package/package.json +1 -3
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
|
@@ -21,7 +21,7 @@ let DeepSeekChatBotAdapter = class DeepSeekChatBotAdapter extends ChatBotAdapter
|
|
|
21
21
|
this.model = model || 'deepseek-chat';
|
|
22
22
|
this.deepSeek = new OpenAI({
|
|
23
23
|
apiKey: apiKey,
|
|
24
|
-
baseURL: baseURL
|
|
24
|
+
baseURL: baseURL,
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
validateEnvVariables(envVariables) {
|
|
@@ -36,14 +36,15 @@ let DeepSeekChatBotAdapter = class DeepSeekChatBotAdapter extends ChatBotAdapter
|
|
|
36
36
|
const tools = (await this.mindset.allFunctionsDescriptors()).map((fn) => {
|
|
37
37
|
const parameters = { ...fn.parameters, additionalProperties: false, type: 'object' };
|
|
38
38
|
return {
|
|
39
|
-
type: 'function',
|
|
39
|
+
type: 'function',
|
|
40
|
+
function: { name: fn.name, description: fn.description, parameters, strict: true },
|
|
40
41
|
};
|
|
41
42
|
});
|
|
42
43
|
const response = await this.deepSeek.chat.completions.create({
|
|
43
44
|
model: this.model,
|
|
44
45
|
messages: [{ role: 'system', content: systemPrompt }, ...this.mapChatItems(chatItems)],
|
|
45
46
|
tools: tools,
|
|
46
|
-
tool_choice: 'auto'
|
|
47
|
+
tool_choice: 'auto',
|
|
47
48
|
});
|
|
48
49
|
let newChatItem;
|
|
49
50
|
const { tool_calls: responseFunctionCall, content: responseText } = response.choices?.[0]?.message ?? {};
|
|
@@ -83,15 +84,15 @@ let DeepSeekChatBotAdapter = class DeepSeekChatBotAdapter extends ChatBotAdapter
|
|
|
83
84
|
type: 'function',
|
|
84
85
|
function: {
|
|
85
86
|
name: itemData.content.name,
|
|
86
|
-
arguments: JSON.stringify(itemData.content.arguments)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
]
|
|
87
|
+
arguments: JSON.stringify(itemData.content.arguments),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
],
|
|
90
91
|
});
|
|
91
92
|
deepSeekInput.push({
|
|
92
93
|
role: 'tool',
|
|
93
94
|
tool_call_id: itemData.content.id,
|
|
94
|
-
content: itemData.content.result
|
|
95
|
+
content: itemData.content.result,
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -55,7 +55,10 @@ class WhatsAppSender {
|
|
|
55
55
|
if (!template) {
|
|
56
56
|
throw new Error(`WhatsAppTemplate with name ${request.templateMessage.templateName} and language ${request.templateMessage.languageCode} not found`);
|
|
57
57
|
}
|
|
58
|
-
const components = template.components
|
|
58
|
+
const components = template.components
|
|
59
|
+
.filter((x) => x.text != null)
|
|
60
|
+
.map((x) => x.text)
|
|
61
|
+
.join('\n');
|
|
59
62
|
return {
|
|
60
63
|
text: this.replaceTemplateParameters(components, request.templateMessage.parameters),
|
|
61
64
|
senderName: request.senderName,
|
|
@@ -77,7 +80,7 @@ class WhatsAppSender {
|
|
|
77
80
|
}
|
|
78
81
|
replaceTemplateParameters(template, data) {
|
|
79
82
|
let result = template;
|
|
80
|
-
data.forEach(param => {
|
|
83
|
+
data.forEach((param) => {
|
|
81
84
|
if (param.type === 'text' && param.parameter_name) {
|
|
82
85
|
const tag = `{{${param.parameter_name}}}`;
|
|
83
86
|
result = result.split(tag).join(param.text);
|
|
@@ -42,7 +42,7 @@ let WhatsAppSenderByDevConnection = class WhatsAppSenderByDevConnection extends
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
async handleGetWhatsAppTemplate(request) {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error('Not implemented');
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
WhatsAppSenderByDevConnection = __decorate([
|
package/dist/src/index.d.ts
CHANGED
|
@@ -226,8 +226,6 @@ interface IMindsetModuleDecoration {
|
|
|
226
226
|
decorationConfig: any;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
declare function isOptional(): PropertyDecorator;
|
|
230
|
-
|
|
231
229
|
interface IParamConfig {
|
|
232
230
|
name?: string;
|
|
233
231
|
optional?: boolean;
|
|
@@ -972,4 +970,143 @@ declare class RamChatRepository implements IChatRepository {
|
|
|
972
970
|
private getMemory;
|
|
973
971
|
}
|
|
974
972
|
|
|
975
|
-
|
|
973
|
+
interface IGetConfig {
|
|
974
|
+
path?: string;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
declare function get(config?: IGetConfig): (target: object, propertyKey: string | symbol) => void;
|
|
978
|
+
|
|
979
|
+
interface IRestControllerConfig {
|
|
980
|
+
path: string;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
declare function restController(config: IRestControllerConfig): (target: IConstructor<any>) => void;
|
|
984
|
+
|
|
985
|
+
interface IEndPointMetadata {
|
|
986
|
+
method: 'get' | 'post';
|
|
987
|
+
path?: string;
|
|
988
|
+
controllerConstructor: IConstructor<any>;
|
|
989
|
+
functionName: string;
|
|
990
|
+
paramsTypes: any[];
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
interface IRestControllerMetadata {
|
|
994
|
+
controllerConstructor: IConstructor<any>;
|
|
995
|
+
path: string;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
declare class RestControllerMetadataStore {
|
|
999
|
+
private endPoints;
|
|
1000
|
+
private restControllers;
|
|
1001
|
+
saveControllerMetadata(controllerMetadata: IRestControllerMetadata): void;
|
|
1002
|
+
saveEndPointMetadata(endPointMetadata: IEndPointMetadata): void;
|
|
1003
|
+
getControllerEndPointsInfo(controllerConstructor: IConstructor<any>): {
|
|
1004
|
+
controller: IRestControllerMetadata;
|
|
1005
|
+
method: "get" | "post";
|
|
1006
|
+
path?: string;
|
|
1007
|
+
controllerConstructor: IConstructor<any>;
|
|
1008
|
+
functionName: string;
|
|
1009
|
+
paramsTypes: any[];
|
|
1010
|
+
}[];
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
declare function runRestControllers(controllers: IConstructor<any>[], container: DependencyContainer$1): void;
|
|
1014
|
+
|
|
1015
|
+
declare function isBoolean(): (target: object, propertyKey: string | symbol) => void;
|
|
1016
|
+
|
|
1017
|
+
declare function isDate(): (target: object, propertyKey: string | symbol) => void;
|
|
1018
|
+
|
|
1019
|
+
declare function isNotEmpty(): (target: object, propertyKey: string | symbol) => void;
|
|
1020
|
+
|
|
1021
|
+
declare function isNumber(): (target: object, propertyKey: string | symbol) => void;
|
|
1022
|
+
|
|
1023
|
+
declare const _IS_OPTIONAL_DUMMY_VALIDATOR_: (value: any) => {
|
|
1024
|
+
value: any;
|
|
1025
|
+
errors: never[];
|
|
1026
|
+
};
|
|
1027
|
+
declare function isOptional(): (target: object, propertyKey: string | symbol) => void;
|
|
1028
|
+
|
|
1029
|
+
declare function isPresent(): (target: object, propertyKey: string | symbol) => void;
|
|
1030
|
+
|
|
1031
|
+
declare function isString(): (target: object, propertyKey: string | symbol) => void;
|
|
1032
|
+
|
|
1033
|
+
declare function max(limit: any): (target: object, propertyKey: string | symbol) => void;
|
|
1034
|
+
|
|
1035
|
+
declare function min(limit: any): (target: object, propertyKey: string | symbol) => void;
|
|
1036
|
+
|
|
1037
|
+
declare function validable<A>(): (target: IConstructor<A>) => void;
|
|
1038
|
+
|
|
1039
|
+
interface IValidationError {
|
|
1040
|
+
description: string;
|
|
1041
|
+
}
|
|
1042
|
+
interface IModelValidationError {
|
|
1043
|
+
model: IValidationError[];
|
|
1044
|
+
properties: {
|
|
1045
|
+
name: string;
|
|
1046
|
+
errors: IValidationError[];
|
|
1047
|
+
}[];
|
|
1048
|
+
}
|
|
1049
|
+
interface IValidationResult<V> {
|
|
1050
|
+
value?: V;
|
|
1051
|
+
error?: IValidationError;
|
|
1052
|
+
}
|
|
1053
|
+
interface IModelValidationResult<V> {
|
|
1054
|
+
value?: V;
|
|
1055
|
+
error?: IModelValidationError;
|
|
1056
|
+
}
|
|
1057
|
+
type IValidator = (value: any, options: any) => IValidationResult<any>;
|
|
1058
|
+
interface IPropertyValidatorInfo {
|
|
1059
|
+
propertyName: string;
|
|
1060
|
+
validator: IValidator;
|
|
1061
|
+
validatorOptions?: any;
|
|
1062
|
+
}
|
|
1063
|
+
type IModelValidatorsInfo<V> = {
|
|
1064
|
+
modelConstructor: IConstructor<V>;
|
|
1065
|
+
properties: {
|
|
1066
|
+
[prop: string]: {
|
|
1067
|
+
isOptional?: boolean;
|
|
1068
|
+
validators?: IPropertyValidatorInfo[];
|
|
1069
|
+
} | undefined;
|
|
1070
|
+
};
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
interface IValidatorMetadata {
|
|
1074
|
+
modelConstructor: IConstructor<any>;
|
|
1075
|
+
propertyName: string;
|
|
1076
|
+
validator: IValidator;
|
|
1077
|
+
validatorOptions?: any;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
declare class ValidationMetadataStore {
|
|
1081
|
+
private validators;
|
|
1082
|
+
saveValidatorMetadata(validatorMetadata: IValidatorMetadata): void;
|
|
1083
|
+
getModelValidatorsInfo<V>(modelConstructor: IConstructor<V>): IModelValidatorsInfo<V>;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
declare function validateIsBoolean(value: any): IValidationResult<boolean>;
|
|
1087
|
+
|
|
1088
|
+
declare function validateIsDate(value: any): IValidationResult<Date>;
|
|
1089
|
+
|
|
1090
|
+
declare function validateIsNotEmpty(value: any): IValidationResult<any>;
|
|
1091
|
+
|
|
1092
|
+
declare function validateIsNumber(value: any): IValidationResult<number>;
|
|
1093
|
+
|
|
1094
|
+
declare function validateIsString(value: any): IValidationResult<string>;
|
|
1095
|
+
|
|
1096
|
+
interface IValidateMaxOptions {
|
|
1097
|
+
limit: any;
|
|
1098
|
+
}
|
|
1099
|
+
declare function validateMax(value: any, options: IValidateMaxOptions): IValidationResult<any>;
|
|
1100
|
+
|
|
1101
|
+
interface IValidateMinOptions {
|
|
1102
|
+
limit: any;
|
|
1103
|
+
}
|
|
1104
|
+
declare function validateMin(value: any, options: IValidateMinOptions): IValidationResult<any>;
|
|
1105
|
+
|
|
1106
|
+
declare function validateIsPresent(value: any): IValidationResult<any>;
|
|
1107
|
+
|
|
1108
|
+
declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IModelValidationResult<V>;
|
|
1109
|
+
|
|
1110
|
+
declare function validateModel2<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
|
|
1111
|
+
|
|
1112
|
+
export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, EnvWhatsAppRepository, ExpressProvider, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IEndPointMetadata, type IGetConfig, type IGetWhatsAppTemplateRequest, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, _IS_OPTIONAL_DUMMY_VALIDATOR_, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isNotEmpty, isNumber, isOptional, isPresent, isString, max, min, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram, validable, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, validateModel2, whatsapp };
|
package/dist/src/index.js
CHANGED
|
@@ -47,7 +47,6 @@ export { mindset } from './mindset/metadata/mindsets/@mindset.js';
|
|
|
47
47
|
export { MINDSET_DECORATION_MINDSET } from './mindset/metadata/mindsets/decoratorNames.js';
|
|
48
48
|
export { mindsetModule } from './mindset/metadata/modules/@mindsetModule.js';
|
|
49
49
|
export { MINDSET_MODULE_DECORATION_MODULE } from './mindset/metadata/modules/decoratorNames.js';
|
|
50
|
-
export { isOptional } from './mindset/metadata/params/@isOptional.js';
|
|
51
50
|
export { param } from './mindset/metadata/params/@param.js';
|
|
52
51
|
export { PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM } from './mindset/metadata/params/decoratorNames.js';
|
|
53
52
|
export { MindsetMetadataStore } from './mindset/metadata/MindsetMetadataStore.js';
|
|
@@ -73,4 +72,29 @@ export { PgCrudRepository } from './repository/pg/PgCrudRepository.js';
|
|
|
73
72
|
export { PgRepositoryBase } from './repository/pg/PgRepositoryBase.js';
|
|
74
73
|
export { Logger } from './logger/Logger.js';
|
|
75
74
|
export { WabotEnv } from './env/WabotEnv.js';
|
|
75
|
+
export { get } from './rest-controller/metadata/@get.js';
|
|
76
|
+
export { restController } from './rest-controller/metadata/@restController.js';
|
|
77
|
+
export { RestControllerMetadataStore } from './rest-controller/metadata/RestControllerMetadataStore.js';
|
|
78
|
+
export { runRestControllers } from './rest-controller/runRestControllers.js';
|
|
79
|
+
export { isBoolean } from './validation/metadata/@isBoolean.js';
|
|
80
|
+
export { isDate } from './validation/metadata/@isDate.js';
|
|
81
|
+
export { isNotEmpty } from './validation/metadata/@isNotEmpty.js';
|
|
82
|
+
export { isNumber } from './validation/metadata/@isNumber.js';
|
|
83
|
+
export { _IS_OPTIONAL_DUMMY_VALIDATOR_, isOptional } from './validation/metadata/@isOptional.js';
|
|
84
|
+
export { isPresent } from './validation/metadata/@isPresent.js';
|
|
85
|
+
export { isString } from './validation/metadata/@isString.js';
|
|
86
|
+
export { max } from './validation/metadata/@max.js';
|
|
87
|
+
export { min } from './validation/metadata/@min.js';
|
|
88
|
+
export { validable } from './validation/metadata/@validable.js';
|
|
89
|
+
export { ValidationMetadataStore } from './validation/metadata/ValidationMetadataStore.js';
|
|
90
|
+
export { validateIsBoolean } from './validation/validators/validateIsBoolean.js';
|
|
91
|
+
export { validateIsDate } from './validation/validators/validateIsDate.js';
|
|
92
|
+
export { validateIsNotEmpty } from './validation/validators/validateIsNotEmpty.js';
|
|
93
|
+
export { validateIsNumber } from './validation/validators/validateIsNumber.js';
|
|
94
|
+
export { validateIsString } from './validation/validators/validateIsString.js';
|
|
95
|
+
export { validateMax } from './validation/validators/validateMax.js';
|
|
96
|
+
export { validateMin } from './validation/validators/validateMin.js';
|
|
97
|
+
export { validateIsPresent } from './validation/validators/validateIsPresent.js';
|
|
98
|
+
export { validateModel } from './validation/validators/validateModel.js';
|
|
99
|
+
export { validateModel2 } from './validation/validateModel2.js';
|
|
76
100
|
export { Container } from './injection/Container.js';
|
|
@@ -60,7 +60,7 @@ let MindsetOperator = class MindsetOperator {
|
|
|
60
60
|
...prev,
|
|
61
61
|
[param.name]: this.toolParam(param),
|
|
62
62
|
}), {}),
|
|
63
|
-
required: fn.params.filter((param) => !param.config.optional).map((param) => param.name)
|
|
63
|
+
required: fn.params.filter((param) => !param.config.optional).map((param) => param.name),
|
|
64
64
|
},
|
|
65
65
|
};
|
|
66
66
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function get(config) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const functionName = propertyKey.toString();
|
|
7
|
+
const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
|
|
8
|
+
const store = container.resolve(RestControllerMetadataStore);
|
|
9
|
+
store.saveEndPointMetadata({
|
|
10
|
+
controllerConstructor: target.constructor,
|
|
11
|
+
functionName,
|
|
12
|
+
method: 'get',
|
|
13
|
+
path: config?.path,
|
|
14
|
+
paramsTypes,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { get };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { container, injectable } from '../../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './RestControllerMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function restController(config) {
|
|
5
|
+
return function (target) {
|
|
6
|
+
const metaDataStore = container.resolve(RestControllerMetadataStore);
|
|
7
|
+
metaDataStore.saveControllerMetadata({
|
|
8
|
+
controllerConstructor: target,
|
|
9
|
+
path: config.path,
|
|
10
|
+
});
|
|
11
|
+
injectable()(target);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { restController };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from 'tsyringe';
|
|
3
|
+
|
|
4
|
+
let RestControllerMetadataStore = class RestControllerMetadataStore {
|
|
5
|
+
endPoints = new Map();
|
|
6
|
+
restControllers = new Map();
|
|
7
|
+
saveControllerMetadata(controllerMetadata) {
|
|
8
|
+
this.restControllers.set(controllerMetadata.controllerConstructor, controllerMetadata);
|
|
9
|
+
}
|
|
10
|
+
saveEndPointMetadata(endPointMetadata) {
|
|
11
|
+
let controllerEndPoints = this.endPoints.get(endPointMetadata.controllerConstructor);
|
|
12
|
+
if (!controllerEndPoints) {
|
|
13
|
+
this.endPoints.set(endPointMetadata.controllerConstructor, (controllerEndPoints = new Map()));
|
|
14
|
+
}
|
|
15
|
+
controllerEndPoints.set(endPointMetadata.functionName, endPointMetadata);
|
|
16
|
+
}
|
|
17
|
+
getControllerEndPointsInfo(controllerConstructor) {
|
|
18
|
+
const controller = this.restControllers.get(controllerConstructor);
|
|
19
|
+
if (!controller) {
|
|
20
|
+
throw new Error(`${controllerConstructor.name} should be decorated with @restController`);
|
|
21
|
+
}
|
|
22
|
+
const endPoints = this.endPoints.get(controllerConstructor);
|
|
23
|
+
if (!endPoints?.size) {
|
|
24
|
+
// TODO: Warning
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
return [...endPoints.values()].map((endPoint) => ({
|
|
28
|
+
...endPoint,
|
|
29
|
+
controller: this.restControllers.get(endPoint.controllerConstructor),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
RestControllerMetadataStore = __decorate([
|
|
34
|
+
singleton()
|
|
35
|
+
], RestControllerMetadataStore);
|
|
36
|
+
|
|
37
|
+
export { RestControllerMetadataStore };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import '../injection/index.js';
|
|
2
|
+
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
3
|
+
import '../controller/channel/ChatResolver.js';
|
|
4
|
+
import '../controller/channel/UserResolver.js';
|
|
5
|
+
import '../controller/metadata/ControllerMetadataStore.js';
|
|
6
|
+
import '../channels/cmd/CmdChannel.js';
|
|
7
|
+
import { ExpressProvider } from '../channels/express/ExpressProvider.js';
|
|
8
|
+
import '../channels/http/HttpServerProvider.js';
|
|
9
|
+
import '../channels/socket/SocketChannel.js';
|
|
10
|
+
import '../channels/socket/SocketChannelConfig.js';
|
|
11
|
+
import '../channels/socket/SocketServerProvider.js';
|
|
12
|
+
import '../channels/telegram/TelegramChannel.js';
|
|
13
|
+
import '../channels/whatsapp/WhatsAppChannel.js';
|
|
14
|
+
import '../core/chat/repository/IChatRepository.js';
|
|
15
|
+
import '../core/user/IUserRepository.js';
|
|
16
|
+
import '../channels/whatsapp/WhatsAppReceiverByDevConnection.js';
|
|
17
|
+
import '../channels/whatsapp/WhatsAppReceiverByWebHook.js';
|
|
18
|
+
import '../channels/whatsapp/WhatsAppSenderByDevConnection.js';
|
|
19
|
+
import '../channels/whatsapp/WhatsAppSenderByCloudApi.js';
|
|
20
|
+
import '../channels/whatsapp/PgWhatsAppRepository.js';
|
|
21
|
+
import '../channels/whatsapp/EnvWhatsAppRepository.js';
|
|
22
|
+
import path from 'path';
|
|
23
|
+
import { Logger } from '../logger/Logger.js';
|
|
24
|
+
|
|
25
|
+
function buildRequest(req) {
|
|
26
|
+
return Object.assign({}, req.body, req.query, req.params);
|
|
27
|
+
}
|
|
28
|
+
function runRestControllers(controllers, container) {
|
|
29
|
+
const logger = new Logger('wabot:rest');
|
|
30
|
+
const metadataStore = container.resolve(RestControllerMetadataStore);
|
|
31
|
+
const expressProvider = container.resolve(ExpressProvider);
|
|
32
|
+
const expressApp = expressProvider.getExpress();
|
|
33
|
+
controllers.forEach((controller) => {
|
|
34
|
+
const endPoints = metadataStore.getControllerEndPointsInfo(controller);
|
|
35
|
+
endPoints.forEach((endPoint) => {
|
|
36
|
+
debugger;
|
|
37
|
+
const method = endPoint.method;
|
|
38
|
+
const route = path.join(endPoint.controller.path, endPoint.path ?? '');
|
|
39
|
+
logger.info(`config ${endPoint.method.toUpperCase()} ${route}`);
|
|
40
|
+
expressApp[method](route, async (req, res) => {
|
|
41
|
+
const requestContainer = container.createChildContainer();
|
|
42
|
+
const controllerInstance = requestContainer.resolve(endPoint.controllerConstructor);
|
|
43
|
+
const endPointArgs = [];
|
|
44
|
+
let defaultArgFound = false;
|
|
45
|
+
for (let paramIndex = 0; paramIndex < endPoint.paramsTypes.length; paramIndex++) {
|
|
46
|
+
const paramType = endPoint.paramsTypes[paramIndex];
|
|
47
|
+
if (defaultArgFound) {
|
|
48
|
+
throw new Error(`Cant determine de parameter ${paramIndex} value`);
|
|
49
|
+
}
|
|
50
|
+
defaultArgFound = true;
|
|
51
|
+
if (typeof paramType === 'function' && typeof paramType.__validate__ === 'function') {
|
|
52
|
+
const { value, error } = paramType.__validate__(buildRequest(req));
|
|
53
|
+
debugger;
|
|
54
|
+
if (error) {
|
|
55
|
+
res.status(400).json({ error });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
endPointArgs.push(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const response = await controllerInstance[endPoint.functionName].apply(controllerInstance, endPointArgs);
|
|
63
|
+
res.status(200).json(response);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
res.sendStatus(500);
|
|
67
|
+
}
|
|
68
|
+
requestContainer.dispose();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
expressProvider.listen();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { runRestControllers };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsBoolean } from '../validators/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 '../validators/validateIsDate.js';
|
|
3
|
+
import { ValidationMetadataStore } from './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,17 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsNotEmpty } from '../validators/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 '../validators/validateIsNumber.js';
|
|
3
|
+
import { ValidationMetadataStore } from './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,19 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
const _IS_OPTIONAL_DUMMY_VALIDATOR_ = (value) => {
|
|
5
|
+
return { value, errors: [] };
|
|
6
|
+
};
|
|
7
|
+
function isOptional() {
|
|
8
|
+
return function (target, propertyKey) {
|
|
9
|
+
const propertyName = propertyKey.toString();
|
|
10
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
11
|
+
store.saveValidatorMetadata({
|
|
12
|
+
modelConstructor: target.constructor,
|
|
13
|
+
propertyName,
|
|
14
|
+
validator: _IS_OPTIONAL_DUMMY_VALIDATOR_,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { _IS_OPTIONAL_DUMMY_VALIDATOR_, isOptional };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsPresent } from '../validators/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 './ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsString } from '../validators/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 './ValidationMetadataStore.js';
|
|
3
|
+
import { validateMax } from '../validators/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,18 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { validateMin } from '../validators/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,14 @@
|
|
|
1
|
+
import { container } from 'tsyringe';
|
|
2
|
+
import { ValidationMetadataStore } from './ValidationMetadataStore.js';
|
|
3
|
+
import { validateModel } from '../validators/validateModel.js';
|
|
4
|
+
|
|
5
|
+
function validable() {
|
|
6
|
+
return function (target) {
|
|
7
|
+
target.__validate__ = function (value) {
|
|
8
|
+
const info = container.resolve(ValidationMetadataStore).getModelValidatorsInfo(target);
|
|
9
|
+
return validateModel(value, info);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { validable };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from '../../injection/index.js';
|
|
3
|
+
import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from './@isOptional.js';
|
|
4
|
+
|
|
5
|
+
let ValidationMetadataStore = class ValidationMetadataStore {
|
|
6
|
+
validators = new Map();
|
|
7
|
+
saveValidatorMetadata(validatorMetadata) {
|
|
8
|
+
let modelValidators = this.validators.get(validatorMetadata.modelConstructor);
|
|
9
|
+
if (!modelValidators) {
|
|
10
|
+
this.validators.set(validatorMetadata.modelConstructor, (modelValidators = new Map()));
|
|
11
|
+
}
|
|
12
|
+
let propertyValidators = modelValidators.get(validatorMetadata.propertyName);
|
|
13
|
+
if (!propertyValidators) {
|
|
14
|
+
propertyValidators = [];
|
|
15
|
+
modelValidators.set(validatorMetadata.propertyName, propertyValidators);
|
|
16
|
+
}
|
|
17
|
+
propertyValidators.unshift(validatorMetadata);
|
|
18
|
+
}
|
|
19
|
+
getModelValidatorsInfo(modelConstructor) {
|
|
20
|
+
const modelValidators = {
|
|
21
|
+
modelConstructor: modelConstructor,
|
|
22
|
+
properties: {},
|
|
23
|
+
};
|
|
24
|
+
[...(this.validators.get(modelConstructor)?.values() ?? [])].forEach((propertyValidatorsMetadata) => {
|
|
25
|
+
const propertyName = propertyValidatorsMetadata.at(0)?.propertyName;
|
|
26
|
+
if (!propertyName) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let propertyInfo = modelValidators.properties[propertyName];
|
|
30
|
+
if (!propertyInfo) {
|
|
31
|
+
propertyInfo = {};
|
|
32
|
+
modelValidators.properties[propertyName] = propertyInfo;
|
|
33
|
+
}
|
|
34
|
+
let validators = propertyInfo.validators;
|
|
35
|
+
if (!validators) {
|
|
36
|
+
validators = [];
|
|
37
|
+
propertyInfo.validators = validators;
|
|
38
|
+
}
|
|
39
|
+
propertyValidatorsMetadata.forEach((propertyValidatorMetadata) => {
|
|
40
|
+
if (propertyValidatorMetadata.validator === _IS_OPTIONAL_DUMMY_VALIDATOR_) {
|
|
41
|
+
propertyInfo.isOptional = true;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
validators.push(propertyValidatorMetadata);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return modelValidators;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
ValidationMetadataStore = __decorate([
|
|
52
|
+
singleton()
|
|
53
|
+
], ValidationMetadataStore);
|
|
54
|
+
|
|
55
|
+
export { ValidationMetadataStore };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { container } from '../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from './metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateModel } from './validators/validateModel.js';
|
|
4
|
+
|
|
5
|
+
function validateModel2(value, modelConstructor) {
|
|
6
|
+
const metadataStore = container.resolve(ValidationMetadataStore);
|
|
7
|
+
const info = metadataStore.getModelValidatorsInfo(modelConstructor);
|
|
8
|
+
return validateModel(value, info);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { validateModel2 };
|
|
@@ -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
|
+
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,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,47 @@
|
|
|
1
|
+
function validateModel(value, info) {
|
|
2
|
+
const result = {};
|
|
3
|
+
if (typeof value !== 'object') {
|
|
4
|
+
result.error = {
|
|
5
|
+
model: [
|
|
6
|
+
{
|
|
7
|
+
description: `the value should be an object`,
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
properties: [],
|
|
11
|
+
};
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
const validatedValue = new info.modelConstructor();
|
|
15
|
+
for (const propertyName in info.properties) {
|
|
16
|
+
const propertyInfo = info.properties[propertyName];
|
|
17
|
+
const propertyValidators = propertyInfo.validators ?? [];
|
|
18
|
+
validatedValue[propertyName] = value[propertyName] ?? validatedValue[propertyName];
|
|
19
|
+
if (validatedValue[propertyName] == null && propertyInfo.isOptional) {
|
|
20
|
+
validatedValue[propertyName] = null;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
for (let propertyValidatorInfo of propertyValidators) {
|
|
24
|
+
const propertyValidatorResult = propertyValidatorInfo.validator(validatedValue[propertyName], propertyValidatorInfo.validatorOptions);
|
|
25
|
+
validatedValue[propertyName] = propertyValidatorResult.value;
|
|
26
|
+
if (propertyValidatorResult.error) {
|
|
27
|
+
let resultError = result.error;
|
|
28
|
+
if (!resultError) {
|
|
29
|
+
resultError = { model: [], properties: [] };
|
|
30
|
+
result.error = resultError;
|
|
31
|
+
}
|
|
32
|
+
let propertyErrors = resultError.properties.find((x) => x.name === propertyName);
|
|
33
|
+
if (!propertyErrors) {
|
|
34
|
+
propertyErrors = { name: propertyName, errors: [] };
|
|
35
|
+
resultError.properties.push(propertyErrors);
|
|
36
|
+
}
|
|
37
|
+
propertyErrors.errors.push(propertyValidatorResult.error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!result.error) {
|
|
42
|
+
result.value = validatedValue;
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { validateModel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wabot-dev/framework",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"description": "Framework for IA Chat Bots",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -39,8 +39,6 @@
|
|
|
39
39
|
"@types/pg": "^8.11.14",
|
|
40
40
|
"@yucacodes/ts": "^0.0.4",
|
|
41
41
|
"body-parser": "^2.2.0",
|
|
42
|
-
"class-transformer": "^0.5.1",
|
|
43
|
-
"class-validator": "^0.14.1",
|
|
44
42
|
"debug": "^4.4.0",
|
|
45
43
|
"dotenv": "^16.5.0",
|
|
46
44
|
"express": "^5.1.0",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
3
|
-
import { container } from '../../../injection/index.js';
|
|
4
|
-
import { PARAM_DECORATION_IS_OPTIONAL } from './decoratorNames.js';
|
|
5
|
-
|
|
6
|
-
function isOptional() {
|
|
7
|
-
return (target, propertyKey) => {
|
|
8
|
-
const paramName = propertyKey.toString();
|
|
9
|
-
const paramType = Reflect.getMetadata('design:type', target, paramName);
|
|
10
|
-
const store = container.resolve(MindsetMetadataStore);
|
|
11
|
-
store.saveParamDecoration({
|
|
12
|
-
decorationName: PARAM_DECORATION_IS_OPTIONAL,
|
|
13
|
-
paramType: paramType,
|
|
14
|
-
paramName: paramName,
|
|
15
|
-
constructor: target.constructor,
|
|
16
|
-
decorationConfig: {},
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { isOptional };
|