@bolttech/form-engine-core 0.0.1-beta.8 → 0.0.2-beta.1
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/README.md +40 -36
- package/index.esm.js +591 -278
- package/package.json +2 -2
- package/src/constants/constants.d.ts +6 -1
- package/src/helpers/SafeSubject.d.ts +11 -0
- package/src/helpers/helpers.d.ts +3 -1
- package/src/helpers/validation.d.ts +27 -0
- package/src/interfaces/schema.d.ts +30 -8
- package/src/managers/field.d.ts +18 -23
- package/src/managers/form.d.ts +50 -31
- package/src/managers/formGroup.d.ts +10 -2
- package/src/types/event.d.ts +2 -2
- package/src/types/form.d.ts +0 -5
- package/src/types/schema.d.ts +88 -40
- package/src/types/template.d.ts +19 -1
- package/src/types/utility.d.ts +2 -0
- package/src/validations/date.d.ts +1 -0
- package/src/validations/handler.d.ts +2 -2
- package/src/validations/multiple.d.ts +2 -2
- package/src/validations/namedRule.d.ts +22 -0
- package/src/validations/number.d.ts +30 -0
package/src/types/schema.d.ts
CHANGED
|
@@ -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.
|
|
@@ -311,9 +311,10 @@ type TDateValidation = {
|
|
|
311
311
|
*
|
|
312
312
|
* @property {number} [max] - Maximum value or length.
|
|
313
313
|
* @property {number} [min] - Minimum value or length.
|
|
314
|
+
* @property {number} [lessThan] - Minimum value or length.
|
|
315
|
+
* @property {number} [greaterThan] - Minimum value or length.
|
|
314
316
|
* @property {TLengthValidation} [length] - Length validation rule.
|
|
315
317
|
* @property {boolean} [required] - Indicates if the field is required.
|
|
316
|
-
* @property {number} [greaterThan] - Value must be greater than this number.
|
|
317
318
|
* @property {unknown} [value] - Specific value to match.
|
|
318
319
|
* @property {string} [regex] - Regular expression for validation.
|
|
319
320
|
* @property {boolean} [email] - Indicates if the value should be a valid email.
|
|
@@ -345,6 +346,8 @@ type TDateValidation = {
|
|
|
345
346
|
* const validationMethods: TValidationMethods = {
|
|
346
347
|
* max: 100,
|
|
347
348
|
* min: 1,
|
|
349
|
+
* lessThan: 1995,
|
|
350
|
+
* greaterThan: 82000,
|
|
348
351
|
* length: { rule: 'greaterOrEqual', target: 8 },
|
|
349
352
|
* required: true,
|
|
350
353
|
* regex: '^[a-zA-Z0-9]+$',
|
|
@@ -395,9 +398,10 @@ type TDateValidation = {
|
|
|
395
398
|
type TValidationMethods = {
|
|
396
399
|
max?: number;
|
|
397
400
|
min?: number;
|
|
401
|
+
lessThan?: number;
|
|
402
|
+
greaterThan?: number;
|
|
398
403
|
length?: TLengthValidation;
|
|
399
404
|
required?: boolean;
|
|
400
|
-
greaterThan?: number;
|
|
401
405
|
value?: unknown;
|
|
402
406
|
regex?: string;
|
|
403
407
|
email?: boolean;
|
|
@@ -424,6 +428,47 @@ type TValidationMethods = {
|
|
|
424
428
|
date?: TDateValidation;
|
|
425
429
|
validDate?: TDateFormatsValidation;
|
|
426
430
|
};
|
|
431
|
+
/**
|
|
432
|
+
* @type {Object.<string, TValidationMethods>} TGenericValidationRule
|
|
433
|
+
* Represents a generic validation rule where each key is associated with a set of validation methods.
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* const genericValidationRule = {
|
|
437
|
+
* email: {
|
|
438
|
+
* required: true,
|
|
439
|
+
* email: true,
|
|
440
|
+
* },
|
|
441
|
+
* password: {
|
|
442
|
+
* required: true,
|
|
443
|
+
* minLength: 8,
|
|
444
|
+
* },
|
|
445
|
+
* };
|
|
446
|
+
*/
|
|
447
|
+
type TGenericValidationRule = {
|
|
448
|
+
[key: string]: TValidationMethods;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* @type {TValidationMethods | TGenericValidationRule} TSchemaValidation
|
|
452
|
+
* Represents the schema validation which can be either a set of validation methods or a generic validation rule.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* const schemaValidation = {
|
|
456
|
+
* required: true,
|
|
457
|
+
* maxLength: 10,
|
|
458
|
+
* };
|
|
459
|
+
*
|
|
460
|
+
* const genericSchemaValidation = {
|
|
461
|
+
* email: {
|
|
462
|
+
* required: true,
|
|
463
|
+
* email: true,
|
|
464
|
+
* },
|
|
465
|
+
* password: {
|
|
466
|
+
* required: true,
|
|
467
|
+
* minLength: 8,
|
|
468
|
+
* },
|
|
469
|
+
* };
|
|
470
|
+
*/
|
|
471
|
+
type TSchemaValidation = TValidationMethods | TGenericValidationRule;
|
|
427
472
|
/**
|
|
428
473
|
* Formatter types
|
|
429
474
|
* @type TSplitterFormatterValue
|
|
@@ -579,19 +624,24 @@ type TMasks = {
|
|
|
579
624
|
* @type TVisibility
|
|
580
625
|
* Represents the visibility conditions for form fields based on validations.
|
|
581
626
|
*
|
|
582
|
-
* @property {
|
|
627
|
+
* @property {boolean} showOnlyIfTrue - Enables visibility of fields only if any or all validation conditions are positive.
|
|
628
|
+
* @property {TSchemaValidation} validations - The validation methods to determine visibility.
|
|
583
629
|
* @property {string[] | string} fields - The fields to be shown or hidden based on validations.
|
|
630
|
+
* @property {string[]} events - Events where visibility will occur.
|
|
584
631
|
*
|
|
585
632
|
* @example
|
|
586
633
|
* ```typescript
|
|
587
634
|
* const visibility: TVisibility = {
|
|
635
|
+
* showOnlyIfTrue: false,
|
|
588
636
|
* validations: { required: true },
|
|
589
|
-
* fields: ['fieldName']
|
|
637
|
+
* fields: ['fieldName'],
|
|
638
|
+
* events: ['ON_FIELD_CHANGE']
|
|
590
639
|
* };
|
|
591
640
|
* ```
|
|
592
641
|
*/
|
|
593
642
|
type TVisibility = {
|
|
594
|
-
|
|
643
|
+
showOnlyIfTrue?: boolean;
|
|
644
|
+
validations: TSchemaValidation;
|
|
595
645
|
fields: string[] | string;
|
|
596
646
|
events: Partial<TEvents>[];
|
|
597
647
|
};
|
|
@@ -610,8 +660,9 @@ type TVisibility = {
|
|
|
610
660
|
* };
|
|
611
661
|
* ```
|
|
612
662
|
*/
|
|
613
|
-
type TResetValueMethods = TVisibility & {
|
|
663
|
+
type TResetValueMethods = Omit<TVisibility, 'showOnlyIfTrue' | 'validations'> & {
|
|
614
664
|
resettledValue: unknown[] | unknown;
|
|
665
|
+
validations?: TSchemaValidation;
|
|
615
666
|
};
|
|
616
667
|
/**
|
|
617
668
|
* @type TApiConfig
|
|
@@ -622,7 +673,7 @@ type TResetValueMethods = TVisibility & {
|
|
|
622
673
|
* @property {OutgoingHttpHeaders} [headers] - The headers for the request.
|
|
623
674
|
* @property {string} [resultPath] - The path to extract the result from the response.
|
|
624
675
|
* @property {unknown} [fallbackValue] - The fallback value if the request fails.
|
|
625
|
-
* @property {
|
|
676
|
+
* @property {TSchemaValidation} preConditions - validation conditions to execute the API call
|
|
626
677
|
* @property {boolean} blockRequestWhenInvalid - blocks request when field validation fails
|
|
627
678
|
*
|
|
628
679
|
* @example
|
|
@@ -647,7 +698,7 @@ type TApiConfig = {
|
|
|
647
698
|
headers?: OutgoingHttpHeaders;
|
|
648
699
|
resultPath?: string;
|
|
649
700
|
fallbackValue?: unknown;
|
|
650
|
-
preConditions?:
|
|
701
|
+
preConditions?: TSchemaValidation;
|
|
651
702
|
blockRequestWhenInvalid?: boolean;
|
|
652
703
|
};
|
|
653
704
|
/**
|
|
@@ -657,40 +708,36 @@ type TApiConfig = {
|
|
|
657
708
|
type TProps = Record<string, unknown>;
|
|
658
709
|
/**
|
|
659
710
|
* @type TValidations
|
|
660
|
-
* Represents the validation
|
|
711
|
+
* Represents the validation configuration for form fields, including methods, event-specific messages, and error messages.
|
|
661
712
|
*
|
|
662
|
-
* @
|
|
663
|
-
*
|
|
664
|
-
*
|
|
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.
|
|
713
|
+
* @property {TSchemaValidation} methods - The validation methods to be applied.
|
|
714
|
+
* @property {Partial<Record<TEvents, string[]>>} eventMessages - The messages to be displayed for specific validation events.
|
|
715
|
+
* @property {TErrorMessages} messages - The general error messages for validation methods.
|
|
673
716
|
*
|
|
674
717
|
* @example
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
718
|
+
* const validations: TValidations = {
|
|
719
|
+
* methods: {
|
|
720
|
+
* max: 100,
|
|
721
|
+
* required: true,
|
|
722
|
+
* regex: '^[a-zA-Z0-9]+$',
|
|
723
|
+
* },
|
|
724
|
+
* eventMessages: {
|
|
725
|
+
* ON_FIELD_MOUNT: ['required'],
|
|
726
|
+
* ON_FIELD_CHANGE: ['regex', 'required'],
|
|
727
|
+
* ON_FIELD_BLUR: ['max', 'required'],
|
|
728
|
+
* },
|
|
729
|
+
* messages: {
|
|
730
|
+
* default: 'This field is required',
|
|
731
|
+
* max: 'Value exceeds the maximum limit',
|
|
732
|
+
* regex: 'Value does not match the pattern',
|
|
733
|
+
* },
|
|
690
734
|
* };
|
|
691
|
-
* ```
|
|
692
735
|
*/
|
|
693
|
-
type
|
|
736
|
+
type TValidations = {
|
|
737
|
+
methods: TSchemaValidation;
|
|
738
|
+
eventMessages?: Partial<Record<TEvents, string[]>>;
|
|
739
|
+
messages?: TErrorMessages;
|
|
740
|
+
};
|
|
694
741
|
/**
|
|
695
742
|
* @type TErrorMessages
|
|
696
743
|
* Represents the error messages for different validation methods.
|
|
@@ -700,10 +747,11 @@ type TResetValues = Partial<Record<TEvents, TResetValueMethods[]>>;
|
|
|
700
747
|
* const errorMessages: TErrorMessages = {
|
|
701
748
|
* required: 'This field is required.',
|
|
702
749
|
* max: 'The value cannot exceed the maximum limit.'
|
|
750
|
+
* default: 'Default error message'
|
|
703
751
|
* };
|
|
704
752
|
* ```
|
|
705
753
|
*/
|
|
706
|
-
type TErrorMessages = Partial<Record<keyof
|
|
754
|
+
type TErrorMessages = Partial<Record<keyof TSchemaValidation & 'default', string>>;
|
|
707
755
|
/**
|
|
708
756
|
* Represents an event configuration with a specific type.
|
|
709
757
|
*
|
|
@@ -749,4 +797,4 @@ type TSchemaFormConfig = {
|
|
|
749
797
|
defaultAPIdebounceTimeMS?: number;
|
|
750
798
|
defaultStateRefreshTimeMS?: number;
|
|
751
799
|
};
|
|
752
|
-
export { TApiConfig, TErrorMessages,
|
|
800
|
+
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, };
|
package/src/types/template.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
2
|
+
import { TMutationEvents } from './event';
|
|
1
3
|
/**
|
|
2
4
|
* @type TSubscribedTemplates
|
|
3
5
|
* Represents the subscribed templates for dynamic updates.
|
|
4
6
|
*
|
|
5
7
|
* @property {string} originExpression - The expression to evaluate.
|
|
8
|
+
* @property {(typeof TEMPLATE_AVALIABLE_SCOPES)[number][]} originScopeKeys - Origin scope of the updated template value
|
|
6
9
|
* @property {string[]} originPropertyKeys - The properties of the origin fields.
|
|
7
10
|
* @property {string[]} originFieldKeys - The keys of the origin fields.
|
|
8
11
|
* @property {string} destinationKey - The key of the destination field.
|
|
@@ -13,6 +16,7 @@
|
|
|
13
16
|
* ```typescript
|
|
14
17
|
* const subscribedTemplates: TSubscribedTemplates = {
|
|
15
18
|
* originExpression: 'originField1 + originField2',
|
|
19
|
+
* originScopeKeys: ['field','field'],
|
|
16
20
|
* originPropertyKeys: ['value', 'props'],
|
|
17
21
|
* originFieldKeys: ['originField1', 'originField2'],
|
|
18
22
|
* destinationKey: 'resultField',
|
|
@@ -23,10 +27,24 @@
|
|
|
23
27
|
*/
|
|
24
28
|
type TSubscribedTemplates = {
|
|
25
29
|
originExpression: string;
|
|
30
|
+
originScopeKeys: (typeof TEMPLATE_AVALIABLE_SCOPES)[number][];
|
|
26
31
|
originPropertyKeys: string[];
|
|
27
32
|
originFieldKeys: string[];
|
|
28
33
|
destinationKey: string;
|
|
29
34
|
destinationProperty: string;
|
|
30
35
|
destinationPath: string[];
|
|
31
36
|
};
|
|
32
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @type TTemplateEvent
|
|
39
|
+
* Represents the event occuring on templates that changes property values.
|
|
40
|
+
*
|
|
41
|
+
* @property {(typeof TEMPLATE_AVALIABLE_SCOPES)[number]} scope - template scope triggering the event.
|
|
42
|
+
* @property {string} key - field triggering the template refresh
|
|
43
|
+
* @property {TMutationEvents} event - template event triggering the template refresh.
|
|
44
|
+
*/
|
|
45
|
+
type TTemplateEvent = {
|
|
46
|
+
scope: (typeof TEMPLATE_AVALIABLE_SCOPES)[number];
|
|
47
|
+
key?: string;
|
|
48
|
+
event: TMutationEvents;
|
|
49
|
+
};
|
|
50
|
+
export { TSubscribedTemplates, TTemplateEvent };
|
package/src/types/utility.d.ts
CHANGED
|
@@ -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,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const validations:
|
|
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}
|
|
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,
|
|
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;
|
|
@@ -80,6 +80,36 @@ export declare const min: (value: unknown, validations: TValidationMethods) => b
|
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
82
|
export declare const between: (value: unknown, validations: TValidationMethods) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a given value is less than a specified threshold.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
87
|
+
* @param validations - An object containing validation methods, specifically the `lessThan` property which holds the threshold value.
|
|
88
|
+
* @returns Returns `false` if the `lessThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is greater than or equal to the `lessThan` threshold.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const validations = { lessThan: 10 };
|
|
93
|
+
* console.log(lessThan(5, validations)); // true
|
|
94
|
+
* console.log(lessThan(15, validations)); // false
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const lessThan: (value: unknown, validations: TValidationMethods) => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Checks if a given value is greater than a specified threshold.
|
|
100
|
+
*
|
|
101
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
102
|
+
* @param validations - An object containing validation methods, specifically the `greaterThan` property which holds the threshold value.
|
|
103
|
+
* @returns Returns `false` if the `greaterThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is less than or equal to the `greaterThan` threshold.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const validations = { greaterThan: 10 };
|
|
108
|
+
* console.log(greaterThan(15, validations)); // true
|
|
109
|
+
* console.log(greaterThan(5, validations)); // false
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare const greaterThan: (value: unknown, validations: TValidationMethods) => boolean;
|
|
83
113
|
/**
|
|
84
114
|
* Validates if a value contains sequential numbers.
|
|
85
115
|
*
|