@wabot-dev/framework 0.1.0-beta.14 → 0.1.0-beta.16

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.
@@ -26,7 +26,7 @@ class Entity extends Storable {
26
26
  return this.createdAt;
27
27
  }
28
28
  update(newData) {
29
- this.data = { ...this.data, newData, updatedAt: new Date().getTime() };
29
+ this.data = { ...this.data, ...newData, updatedAt: new Date().getTime() };
30
30
  }
31
31
  wasCreated() {
32
32
  return !!this.data.createdAt || !!this.data.id;
@@ -1072,7 +1072,7 @@ declare class RestControllerMetadataStore {
1072
1072
  }[];
1073
1073
  }
1074
1074
 
1075
- declare function runRestControllers(controllers: IConstructor<any>[], container: DependencyContainer$1): void;
1075
+ declare function runRestControllers(controllers: IConstructor<any>[]): void;
1076
1076
 
1077
1077
  declare function prepareChatContainer(container: DependencyContainer$1, context: IMessageContext, mindsetCtor?: IConstructor<IMindset>): Promise<DependencyContainer$1>;
1078
1078
 
@@ -1125,14 +1125,20 @@ interface IModelValidationError extends IValidationError {
1125
1125
  errors: IValidationError[];
1126
1126
  }[];
1127
1127
  }
1128
- interface IValidationResult<V> {
1129
- value?: V;
1130
- error?: IValidationError;
1131
- }
1132
- interface IModelValidationResult<V> {
1133
- value?: V;
1134
- error?: IModelValidationError;
1135
- }
1128
+ type IValidationResult<V> = {
1129
+ value: V;
1130
+ error?: undefined;
1131
+ } | {
1132
+ value?: undefined;
1133
+ error: IValidationError;
1134
+ };
1135
+ type IModelValidationResult<V> = {
1136
+ value: V;
1137
+ error?: undefined;
1138
+ } | {
1139
+ value?: undefined;
1140
+ error: IModelValidationError;
1141
+ };
1136
1142
  type IValidator = (value: any, options: any) => IValidationResult<any>;
1137
1143
  interface IPropertyValidatorInfo {
1138
1144
  propertyName: string;
@@ -1188,4 +1194,4 @@ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IM
1188
1194
 
1189
1195
  declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
1190
1196
 
1191
- export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, EnvWhatsAppRepository, ExpressProvider, HtmlModule, 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 ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddlewareMetadata, 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 IPostConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, 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 IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, 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, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, max, middleware, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram, validate, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
1197
+ export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, EnvWhatsAppRepository, ExpressProvider, HtmlModule, 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 ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddlewareMetadata, 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 IPostConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type IStorableData, 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 IWhatsAppTemplate, type IWhatsAppTemplateComponent, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppTemplateResponse, 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, Storable, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, max, middleware, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram, validate, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
package/dist/src/index.js CHANGED
@@ -41,6 +41,7 @@ export { User } from './core/user/User.js';
41
41
  export { UserRepository } from './core/user/IUserRepository.js';
42
42
  export { MessageContext } from './core/IMessageContext.js';
43
43
  export { Entity, Persistent } from './core/Entity.js';
44
+ export { Storable } from './core/Storable.js';
44
45
  export { WabotEnv } from './env/WabotEnv.js';
45
46
  export { CustomError } from './error/CustomError.js';
46
47
  export { container, inject, injectable, singleton } from './injection/index.js';
@@ -1,6 +1,6 @@
1
1
  import '../controller/channel/ChatResolver.js';
2
2
  import '../controller/channel/UserResolver.js';
3
- import '../injection/index.js';
3
+ import { container } from '../injection/index.js';
4
4
  import '../controller/metadata/ControllerMetadataStore.js';
5
5
  import '../channels/cmd/CmdChannel.js';
6
6
  import { ExpressProvider } from '../channels/express/ExpressProvider.js';
@@ -28,7 +28,7 @@ import { CustomError } from '../error/CustomError.js';
28
28
  function buildRequest(req) {
29
29
  return Object.assign({}, req.body, req.query, req.params);
30
30
  }
31
- function runRestControllers(controllers, container) {
31
+ function runRestControllers(controllers) {
32
32
  const logger = new Logger('wabot:rest');
33
33
  const metadataStore = container.resolve(RestControllerMetadataStore);
34
34
  const expressProvider = container.resolve(ExpressProvider);
@@ -1,43 +1,34 @@
1
1
  function validateModel(value, info) {
2
- const result = {};
3
- if (typeof value !== 'object') {
4
- result.error = {
5
- description: 'the value should be an object',
6
- properties: [],
7
- };
8
- return result;
2
+ if (typeof value !== 'object' || value === null) {
3
+ return { error: { description: 'Invalid object', properties: [] } };
9
4
  }
10
- const validatedValue = new info.modelConstructor();
5
+ let propertiesErrors = [];
6
+ let resultValue = new info.modelConstructor();
11
7
  for (const propertyName in info.properties) {
12
8
  const propertyInfo = info.properties[propertyName];
13
9
  const propertyValidators = propertyInfo.validators ?? [];
14
- validatedValue[propertyName] = value[propertyName] ?? validatedValue[propertyName];
15
- if (validatedValue[propertyName] == null && propertyInfo.isOptional) {
16
- validatedValue[propertyName] = null;
10
+ resultValue[propertyName] = value[propertyName] ?? resultValue[propertyName];
11
+ if (resultValue[propertyName] == null && propertyInfo.isOptional) {
12
+ resultValue[propertyName] = null;
17
13
  continue;
18
14
  }
19
15
  for (let propertyValidatorInfo of propertyValidators) {
20
- const propertyValidatorResult = propertyValidatorInfo.validator(validatedValue[propertyName], propertyValidatorInfo.validatorOptions);
21
- validatedValue[propertyName] = propertyValidatorResult.value;
16
+ const propertyValidatorResult = propertyValidatorInfo.validator(resultValue[propertyName], propertyValidatorInfo.validatorOptions);
17
+ resultValue[propertyName] = propertyValidatorResult.value;
22
18
  if (propertyValidatorResult.error) {
23
- let resultError = result.error;
24
- if (!resultError) {
25
- resultError = { description: `Error on properties`, properties: [] };
26
- result.error = resultError;
27
- }
28
- let propertyErrors = resultError.properties.find((x) => x.name === propertyName);
19
+ let propertyErrors = propertiesErrors.find((x) => x.name === propertyName);
29
20
  if (!propertyErrors) {
30
21
  propertyErrors = { name: propertyName, errors: [] };
31
- resultError.properties.push(propertyErrors);
22
+ propertiesErrors.push(propertyErrors);
32
23
  }
33
24
  propertyErrors.errors.push(propertyValidatorResult.error);
34
25
  }
35
26
  }
36
27
  }
37
- if (!result.error) {
38
- result.value = validatedValue;
28
+ if (propertiesErrors.length > 0) {
29
+ return { error: { description: 'Invalid properties', properties: propertiesErrors } };
39
30
  }
40
- return result;
31
+ return { value: resultValue };
41
32
  }
42
33
 
43
34
  export { validateModel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.14",
3
+ "version": "0.1.0-beta.16",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",