@wabot-dev/framework 0.1.0-beta.26 → 0.1.0-beta.27

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.
@@ -1341,6 +1341,9 @@ interface IModelValidationError extends IValidationError {
1341
1341
  [key: string]: string[];
1342
1342
  };
1343
1343
  }
1344
+ interface IArrayValidationError extends IValidationError {
1345
+ items: (IValidationError[] | null)[];
1346
+ }
1344
1347
  type IValidationResult<V> = {
1345
1348
  value: V;
1346
1349
  error?: undefined;
@@ -1355,7 +1358,14 @@ type IModelValidationResult<V> = {
1355
1358
  value?: undefined;
1356
1359
  error: IModelValidationError;
1357
1360
  };
1358
- type IValidator = (value: any, options: any) => IValidationResult<any>;
1361
+ type IArrayValidationResult<V> = {
1362
+ value: V[];
1363
+ error?: undefined;
1364
+ } | {
1365
+ value?: undefined;
1366
+ error: IArrayValidationError;
1367
+ };
1368
+ type IValidator<V = any, O = any> = (value: V, options: O) => IValidationResult<V>;
1359
1369
  interface IPropertyValidatorInfo {
1360
1370
  propertyName: string;
1361
1371
  validator: IValidator;
@@ -1385,6 +1395,18 @@ declare class ValidationMetadataStore {
1385
1395
  private getConstructorPropertiesValidatorsInfo;
1386
1396
  }
1387
1397
 
1398
+ interface IValidateArrayOptions {
1399
+ }
1400
+ interface IValidateArrayOptionsWithItemsValidators extends IValidateArrayOptions {
1401
+ itemsValidator?: {
1402
+ validator: IValidator;
1403
+ options: any;
1404
+ }[];
1405
+ }
1406
+ declare function validateArray(value: any, options?: IValidateArrayOptionsWithItemsValidators): IArrayValidationResult<any>;
1407
+
1408
+ declare function isArray(options?: IValidateArrayOptions): (target: object, propertyKey: string | symbol) => void;
1409
+
1388
1410
  declare function validateIsBoolean(value: any): IValidationResult<boolean>;
1389
1411
 
1390
1412
  declare function validateIsDate(value: any): IValidationResult<Date>;
@@ -1411,4 +1433,6 @@ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IM
1411
1433
 
1412
1434
  declare function validate<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
1413
1435
 
1414
- export { Async, Auth, AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemRawData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatTool, type IChatToolParameter, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IEnvType, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IJobData, type IJobEvent, type IJobEventListener, type IJwtRefreshTokenData, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, 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 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, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, Random, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, command, commandHandler, container, get, inject, injectable, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runAsyncCommandHandlers, runChannel, runRestControllers, runServer, scoped, singleton, socket, telegram, validate, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
1436
+ declare function modelInfo<V>(modelConstructor: IConstructor<V>): IModelValidatorsInfo<V>;
1437
+
1438
+ export { Async, Auth, AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, ClaudeChatBotAdapter, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatBotAdapter, EmailService, Entity, Env, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IArrayValidationError, type IArrayValidationResult, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemReq, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemRawData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatTool, type IChatToolParameter, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEmailService, type IEndPointMetadata, type IEntityData, type IEnvType, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IJobData, type IJobEvent, type IJobEventListener, type IJwtRefreshTokenData, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMiddleware, 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 IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, 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, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, Mapper, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatAdapter, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, Random, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, command, commandHandler, container, get, inject, injectable, isArray, isBoolean, isDate, isModel, isNotEmpty, isNumber, isOptional, isPresent, isString, jwtGuard, max, middleware, min, mindset, mindsetFunction, mindsetModule, modelInfo, param, post, prepareChatContainer, restController, runAsyncCommandHandlers, runChannel, runRestControllers, runServer, scoped, singleton, socket, telegram, validate, validateArray, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, whatsapp };
package/dist/src/index.js CHANGED
@@ -116,6 +116,7 @@ export { isString } from './validation/metadata/@isString.js';
116
116
  export { max } from './validation/metadata/@max.js';
117
117
  export { min } from './validation/metadata/@min.js';
118
118
  export { ValidationMetadataStore } from './validation/metadata/ValidationMetadataStore.js';
119
+ export { isArray } from './validation/metadata/@isArray.js';
119
120
  export { validateIsBoolean } from './validation/validators/validateIsBoolean.js';
120
121
  export { validateIsDate } from './validation/validators/validateIsDate.js';
121
122
  export { validateIsNotEmpty } from './validation/validators/validateIsNotEmpty.js';
@@ -125,5 +126,7 @@ export { validateMax } from './validation/validators/validateMax.js';
125
126
  export { validateMin } from './validation/validators/validateMin.js';
126
127
  export { validateIsPresent } from './validation/validators/validateIsPresent.js';
127
128
  export { validateModel } from './validation/validators/validateModel.js';
129
+ export { validateArray } from './validation/validators/validateArray.js';
128
130
  export { validate } from './validation/validate.js';
131
+ export { modelInfo } from './validation/modelInfo.js';
129
132
  export { Container } from './injection/Container.js';
@@ -0,0 +1,18 @@
1
+ import { container } from '../../injection/index.js';
2
+ import { validateArray } from '../validators/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 };
@@ -1,6 +1,7 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { singleton } from '../../injection/index.js';
3
3
  import { _IS_OPTIONAL_DUMMY_VALIDATOR_ } from '../validators/validateIsOptional.js';
4
+ import { validateArray } from '../validators/validateArray.js';
4
5
 
5
6
  function getClassHierarchy(cls) {
6
7
  const classes = [];
@@ -24,6 +25,33 @@ let ValidationMetadataStore = class ValidationMetadataStore {
24
25
  modelValidators.set(validatorMetadata.propertyName, propertyValidators);
25
26
  }
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
+ }
27
55
  }
28
56
  getModelValidatorsInfo(modelConstructor) {
29
57
  const constructors = getClassHierarchy(modelConstructor);
@@ -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,41 @@
1
+ function validateArray(value, options) {
2
+ if (!Array.isArray(value)) {
3
+ return {
4
+ error: { description: 'Should be an array', items: [] },
5
+ };
6
+ }
7
+ const { itemsValidator } = options ?? {};
8
+ const valueOut = [];
9
+ const errorItems = [];
10
+ for (const item of value) {
11
+ let itemOut = item;
12
+ const itemErrors = [];
13
+ for (const itemValidator of itemsValidator ?? []) {
14
+ const { error, value } = itemValidator.validator(itemOut, itemValidator.options);
15
+ if (error) {
16
+ itemErrors.push(error);
17
+ }
18
+ else {
19
+ itemOut = value;
20
+ }
21
+ }
22
+ if (itemErrors.length == 0) {
23
+ valueOut.push(itemOut);
24
+ errorItems.push(null);
25
+ }
26
+ else {
27
+ valueOut.push(null);
28
+ errorItems.push(itemErrors);
29
+ }
30
+ }
31
+ if (errorItems.some((x) => x != null)) {
32
+ return {
33
+ error: { description: 'Error on some items', items: errorItems },
34
+ };
35
+ }
36
+ return {
37
+ value: valueOut,
38
+ };
39
+ }
40
+
41
+ export { validateArray };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.1.0-beta.26",
3
+ "version": "0.1.0-beta.27",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",