@bolttech/form-engine-core 0.0.1-beta.4 → 0.0.1-beta.41

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
  };
@@ -610,8 +654,9 @@ type TVisibility = {
610
654
  * };
611
655
  * ```
612
656
  */
613
- type TResetValueMethods = TVisibility & {
657
+ type TResetValueMethods = Omit<TVisibility, 'showOnlyIfTrue' | 'validations'> & {
614
658
  resettledValue: unknown[] | unknown;
659
+ validations?: TSchemaValidation;
615
660
  };
616
661
  /**
617
662
  * @type TApiConfig
@@ -622,7 +667,7 @@ type TResetValueMethods = TVisibility & {
622
667
  * @property {OutgoingHttpHeaders} [headers] - The headers for the request.
623
668
  * @property {string} [resultPath] - The path to extract the result from the response.
624
669
  * @property {unknown} [fallbackValue] - The fallback value if the request fails.
625
- * @property {TValidationMethods} preConditions - validation conditions to execute the API call
670
+ * @property {TSchemaValidation} preConditions - validation conditions to execute the API call
626
671
  * @property {boolean} blockRequestWhenInvalid - blocks request when field validation fails
627
672
  *
628
673
  * @example
@@ -647,7 +692,7 @@ type TApiConfig = {
647
692
  headers?: OutgoingHttpHeaders;
648
693
  resultPath?: string;
649
694
  fallbackValue?: unknown;
650
- preConditions?: TValidationMethods;
695
+ preConditions?: TSchemaValidation;
651
696
  blockRequestWhenInvalid?: boolean;
652
697
  };
653
698
  /**
@@ -657,40 +702,36 @@ type TApiConfig = {
657
702
  type TProps = Record<string, unknown>;
658
703
  /**
659
704
  * @type TValidations
660
- * Represents the validation methods for different events.
705
+ * Represents the validation configuration for form fields, including methods, event-specific messages, and error messages.
661
706
  *
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.
707
+ * @property {TSchemaValidation} methods - The validation methods to be applied.
708
+ * @property {Partial<Record<TEvents, string[]>>} eventMessages - The messages to be displayed for specific validation events.
709
+ * @property {TErrorMessages} messages - The general error messages for validation methods.
685
710
  *
686
711
  * @example
687
- * ```typescript
688
- * const resetValues: TResetValues = {
689
- * ON_FIELD_BLUR: [{ validations: { required: true }, fields: ['fieldName'], resettledValue: [''] }]
712
+ * const validations: TValidations = {
713
+ * methods: {
714
+ * max: 100,
715
+ * required: true,
716
+ * regex: '^[a-zA-Z0-9]+$',
717
+ * },
718
+ * eventMessages: {
719
+ * ON_FIELD_MOUNT: ['required'],
720
+ * ON_FIELD_CHANGE: ['regex', 'required'],
721
+ * ON_FIELD_BLUR: ['max', 'required'],
722
+ * },
723
+ * messages: {
724
+ * default: 'This field is required',
725
+ * max: 'Value exceeds the maximum limit',
726
+ * regex: 'Value does not match the pattern',
727
+ * },
690
728
  * };
691
- * ```
692
729
  */
693
- type TResetValues = Partial<Record<TEvents, TResetValueMethods[]>>;
730
+ type TValidations = {
731
+ methods: TSchemaValidation;
732
+ eventMessages?: Partial<Record<TEvents, string[]>>;
733
+ messages?: TErrorMessages;
734
+ };
694
735
  /**
695
736
  * @type TErrorMessages
696
737
  * Represents the error messages for different validation methods.
@@ -700,10 +741,11 @@ type TResetValues = Partial<Record<TEvents, TResetValueMethods[]>>;
700
741
  * const errorMessages: TErrorMessages = {
701
742
  * required: 'This field is required.',
702
743
  * max: 'The value cannot exceed the maximum limit.'
744
+ * default: 'Default error message'
703
745
  * };
704
746
  * ```
705
747
  */
706
- type TErrorMessages = Partial<Record<keyof TValidationMethods, string>>;
748
+ type TErrorMessages = Partial<Record<keyof TSchemaValidation & 'default', string>>;
707
749
  /**
708
750
  * Represents an event configuration with a specific type.
709
751
  *
@@ -749,4 +791,4 @@ type TSchemaFormConfig = {
749
791
  defaultAPIdebounceTimeMS?: number;
750
792
  defaultStateRefreshTimeMS?: number;
751
793
  };
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, };
794
+ 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;