@bolttech/form-engine-core 0.0.1-beta.3 → 0.0.1-beta.31

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.
@@ -159,7 +159,7 @@ type TConditionsValidation = {
159
159
  set: TConditionsValidationSet[];
160
160
  conditions?: TConditionsValidation;
161
161
  };
162
- type TAvailableValidations = Omit<TValidationMethods, 'multipleValidations'>;
162
+ type TAvailableValidations = Omit<TValidationMethods, 'multipleValidations'> | TGenericValidationRule;
163
163
  /**
164
164
  * @type TMultipleValidation
165
165
  * Represents a set of multiple validation methods combined with a logical rule.
@@ -313,7 +313,6 @@ type TDateValidation = {
313
313
  * @property {number} [min] - Minimum value or length.
314
314
  * @property {TLengthValidation} [length] - Length validation rule.
315
315
  * @property {boolean} [required] - Indicates if the field is required.
316
- * @property {number} [greaterThan] - Value must be greater than this number.
317
316
  * @property {unknown} [value] - Specific value to match.
318
317
  * @property {string} [regex] - Regular expression for validation.
319
318
  * @property {boolean} [email] - Indicates if the value should be a valid email.
@@ -397,7 +396,6 @@ type TValidationMethods = {
397
396
  min?: number;
398
397
  length?: TLengthValidation;
399
398
  required?: boolean;
400
- greaterThan?: number;
401
399
  value?: unknown;
402
400
  regex?: string;
403
401
  email?: boolean;
@@ -424,6 +422,47 @@ type TValidationMethods = {
424
422
  date?: TDateValidation;
425
423
  validDate?: TDateFormatsValidation;
426
424
  };
425
+ /**
426
+ * @type {Object.<string, TValidationMethods>} TGenericValidationRule
427
+ * Represents a generic validation rule where each key is associated with a set of validation methods.
428
+ *
429
+ * @example
430
+ * const genericValidationRule = {
431
+ * email: {
432
+ * required: true,
433
+ * email: true,
434
+ * },
435
+ * password: {
436
+ * required: true,
437
+ * minLength: 8,
438
+ * },
439
+ * };
440
+ */
441
+ type TGenericValidationRule = {
442
+ [key: string]: TValidationMethods;
443
+ };
444
+ /**
445
+ * @type {TValidationMethods | TGenericValidationRule} TSchemaValidation
446
+ * Represents the schema validation which can be either a set of validation methods or a generic validation rule.
447
+ *
448
+ * @example
449
+ * const schemaValidation = {
450
+ * required: true,
451
+ * maxLength: 10,
452
+ * };
453
+ *
454
+ * const genericSchemaValidation = {
455
+ * email: {
456
+ * required: true,
457
+ * email: true,
458
+ * },
459
+ * password: {
460
+ * required: true,
461
+ * minLength: 8,
462
+ * },
463
+ * };
464
+ */
465
+ type TSchemaValidation = TValidationMethods | TGenericValidationRule;
427
466
  /**
428
467
  * Formatter types
429
468
  * @type TSplitterFormatterValue
@@ -579,19 +618,24 @@ type TMasks = {
579
618
  * @type TVisibility
580
619
  * Represents the visibility conditions for form fields based on validations.
581
620
  *
582
- * @property {TValidationMethods} validations - The validation methods to determine visibility.
621
+ * @property {boolean} showOnlyIfTrue - Enables visibility of fields only if any or all validation conditions are positive.
622
+ * @property {TSchemaValidation} validations - The validation methods to determine visibility.
583
623
  * @property {string[] | string} fields - The fields to be shown or hidden based on validations.
624
+ * @property {string[]} events - Events where visibility will occur.
584
625
  *
585
626
  * @example
586
627
  * ```typescript
587
628
  * const visibility: TVisibility = {
629
+ * showOnlyIfTrue: false,
588
630
  * validations: { required: true },
589
- * fields: ['fieldName']
631
+ * fields: ['fieldName'],
632
+ * events: ['ON_FIELD_CHANGE']
590
633
  * };
591
634
  * ```
592
635
  */
593
636
  type TVisibility = {
594
- validations: TValidationMethods;
637
+ showOnlyIfTrue?: boolean;
638
+ validations: TSchemaValidation;
595
639
  fields: string[] | string;
596
640
  events: Partial<TEvents>[];
597
641
  };
@@ -622,7 +666,7 @@ type TResetValueMethods = TVisibility & {
622
666
  * @property {OutgoingHttpHeaders} [headers] - The headers for the request.
623
667
  * @property {string} [resultPath] - The path to extract the result from the response.
624
668
  * @property {unknown} [fallbackValue] - The fallback value if the request fails.
625
- * @property {TValidationMethods} preConditions - validation conditions to execute the API call
669
+ * @property {TSchemaValidation} preConditions - validation conditions to execute the API call
626
670
  * @property {boolean} blockRequestWhenInvalid - blocks request when field validation fails
627
671
  *
628
672
  * @example
@@ -647,7 +691,7 @@ type TApiConfig = {
647
691
  headers?: OutgoingHttpHeaders;
648
692
  resultPath?: string;
649
693
  fallbackValue?: unknown;
650
- preConditions?: TValidationMethods;
694
+ preConditions?: TSchemaValidation;
651
695
  blockRequestWhenInvalid?: boolean;
652
696
  };
653
697
  /**
@@ -657,40 +701,36 @@ type TApiConfig = {
657
701
  type TProps = Record<string, unknown>;
658
702
  /**
659
703
  * @type TValidations
660
- * Represents the validation methods for different events.
704
+ * Represents the validation configuration for form fields, including methods, event-specific messages, and error messages.
661
705
  *
662
- * @example
663
- * ```typescript
664
- * const validations: TValidations = {
665
- * ON_FIELD_BLUR: { required: true }
666
- * };
667
- * ```
668
- */
669
- type TValidations = Partial<Record<TEvents, TValidationMethods>>;
670
- /**
671
- * @type TVisibilityConditions
672
- * Represents the visibility conditions for different events.
673
- *
674
- * @example
675
- * ```typescript
676
- * const visibilityConditions: TVisibilityConditions = {
677
- * ON_FIELD_BLUR: [{ validations: { required: true }, fields: ['fieldName'] }]
678
- * };
679
- * ```
680
- */
681
- type TVisibilityConditions = Partial<Record<TEvents, TVisibility[]>>;
682
- /**
683
- * @type TResetValues
684
- * Represents the reset value methods for different events.
706
+ * @property {TSchemaValidation} methods - The validation methods to be applied.
707
+ * @property {Partial<Record<TEvents, string[]>>} eventMessages - The messages to be displayed for specific validation events.
708
+ * @property {TErrorMessages} messages - The general error messages for validation methods.
685
709
  *
686
710
  * @example
687
- * ```typescript
688
- * const resetValues: TResetValues = {
689
- * ON_FIELD_BLUR: [{ validations: { required: true }, fields: ['fieldName'], resettledValue: [''] }]
711
+ * const validations: TValidations = {
712
+ * methods: {
713
+ * max: 100,
714
+ * required: true,
715
+ * regex: '^[a-zA-Z0-9]+$',
716
+ * },
717
+ * eventMessages: {
718
+ * ON_FIELD_MOUNT: ['required'],
719
+ * ON_FIELD_CHANGE: ['regex', 'required'],
720
+ * ON_FIELD_BLUR: ['max', 'required'],
721
+ * },
722
+ * messages: {
723
+ * default: 'This field is required',
724
+ * max: 'Value exceeds the maximum limit',
725
+ * regex: 'Value does not match the pattern',
726
+ * },
690
727
  * };
691
- * ```
692
728
  */
693
- type TResetValues = Partial<Record<TEvents, TResetValueMethods[]>>;
729
+ type TValidations = {
730
+ methods: TSchemaValidation;
731
+ eventMessages?: Partial<Record<TEvents, string[]>>;
732
+ messages?: TErrorMessages;
733
+ };
694
734
  /**
695
735
  * @type TErrorMessages
696
736
  * Represents the error messages for different validation methods.
@@ -700,10 +740,11 @@ type TResetValues = Partial<Record<TEvents, TResetValueMethods[]>>;
700
740
  * const errorMessages: TErrorMessages = {
701
741
  * required: 'This field is required.',
702
742
  * max: 'The value cannot exceed the maximum limit.'
743
+ * default: 'Default error message'
703
744
  * };
704
745
  * ```
705
746
  */
706
- type TErrorMessages = Partial<Record<keyof TValidationMethods, string>>;
747
+ type TErrorMessages = Partial<Record<keyof TSchemaValidation & 'default', string>>;
707
748
  /**
708
749
  * Represents an event configuration with a specific type.
709
750
  *
@@ -749,4 +790,4 @@ type TSchemaFormConfig = {
749
790
  defaultAPIdebounceTimeMS?: number;
750
791
  defaultStateRefreshTimeMS?: number;
751
792
  };
752
- export { TApiConfig, TErrorMessages, TResetValues, TVisibilityConditions, TValidations, TMasks, TProps, TResetValueMethods, TFormatters, TValidationMethods, TEvent, TVisibility, TApiEvent, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, };
793
+ export { TApiConfig, TErrorMessages, TValidations, TMasks, TProps, TResetValueMethods, TFormatters, TValidationMethods, TGenericValidationRule, TSchemaValidation, TEvent, TVisibility, TApiEvent, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, };
@@ -1,4 +1,6 @@
1
+ import { TValidationMethods } from './schema';
1
2
  export type AllowOnly<T, K extends keyof T> = Pick<T, K> & {
2
3
  [P in keyof Omit<T, K>]?: never;
3
4
  };
4
5
  export type OneOf<T, K = keyof T> = K extends keyof T ? AllowOnly<T, K> : never;
6
+ export type TValidationHandler = Record<string, (value: unknown, validations: TValidationMethods) => boolean>;
@@ -1,5 +1,6 @@
1
1
  import { TValidationMethods } from '../types/schema';
2
2
  /**
3
+ * @function betweenDates
3
4
  * Validates if a date value falls between two specified dates.
4
5
  *
5
6
  * @param {string} value - The date value to be validated in string format.
@@ -1,2 +1,2 @@
1
- import { TValidationMethods } from '../types/schema';
2
- export declare const validations: Record<keyof TValidationMethods, (value: unknown, validations: TValidationMethods) => boolean>;
1
+ import { TValidationHandler } from '../types/utility';
2
+ export declare const validations: TValidationHandler;
@@ -3,7 +3,7 @@ import { TValidationMethods } from '../types/schema';
3
3
  * Validates that a value meets multiple validation rules.
4
4
  *
5
5
  * @param {number | string | boolean} value - The value to be validated.
6
- * @param {TValidationMethods} validations - The validation methods object containing the multipleValidations rule set.
6
+ * @param {TValidationMethods} methods - The validation methods object containing the multipleValidations rule set.
7
7
  * @returns {boolean} - Returns `true` if the value meets the specified multiple validation rules, otherwise `false`.
8
8
  *
9
9
  * @example
@@ -28,4 +28,4 @@ import { TValidationMethods } from '../types/schema';
28
28
  * console.log(result2); // false
29
29
  * ```
30
30
  */
31
- export declare const multipleValidations: (value: number | string | boolean, validations: TValidationMethods) => boolean;
31
+ export declare const multipleValidations: (value: number | string | boolean, methods: TValidationMethods) => boolean;
@@ -0,0 +1,22 @@
1
+ import { TValidationMethods } from '../types/schema';
2
+ import { TValidationHandler } from '../types/utility';
3
+ /**
4
+ * Validates a given value based on specified validation methods inside a custom named validation.
5
+ *
6
+ * @param {unknown} value - The value to be validated.
7
+ * @param {TValidationMethods} methods - The validation methods to be applied.
8
+ * @param {TValidationHandler} validations - An object containing every validation methods to be executed.
9
+ * @returns {boolean} - Returns true if any of the validation methods pass, otherwise false.
10
+ *
11
+ * @example
12
+ * const value = 'example@example.com';
13
+ * const methods = {
14
+ * required: true,
15
+ * email: true
16
+ * };
17
+ *
18
+ * const isValid = validateValue(value, methods);
19
+ * console.log(isValid); // Output: true
20
+ */
21
+ declare const _default: (value: unknown, methods: TValidationMethods, validations: TValidationHandler) => boolean;
22
+ export default _default;