@bolttech/form-engine-core 1.1.0-beta.0 → 1.1.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.
@@ -0,0 +1,20 @@
1
+ import { TValidationHandler } from './types/utility';
2
+ /**
3
+ * Global mutable registries for validations, formatters, and masks.
4
+ * Plugins (sub-path exports) can extend these at import time.
5
+ */
6
+ export declare const validationRegistry: TValidationHandler;
7
+ export declare const formatterRegistry: Record<string, (value: unknown, formatters?: any) => unknown>;
8
+ export declare const maskRegistry: Record<string, (value: unknown, masks?: any) => unknown>;
9
+ /**
10
+ * Registers additional validation methods into the global registry.
11
+ */
12
+ export declare function registerValidations(methods: TValidationHandler): void;
13
+ /**
14
+ * Registers additional formatter methods into the global registry.
15
+ */
16
+ export declare function registerFormatters(methods: Record<string, (value: unknown, formatters?: any) => unknown>): void;
17
+ /**
18
+ * Registers additional mask methods into the global registry.
19
+ */
20
+ export declare function registerMasks(methods: Record<string, (value: unknown, masks?: any) => unknown>): void;
@@ -1,10 +1,23 @@
1
- /// <reference types="node" />
2
1
  /** @virtual */
3
2
  import { TCurrencyCode, TCurrencyLocalCode } from '@gaignoux/currency';
4
- import { OutgoingHttpHeaders } from 'http2';
5
3
  import { TEvents } from './event';
6
4
  import { TFormValues } from './form';
7
5
  import { ALLOWED_RESET_PROPS_MUTATIONS } from '../constants/constants';
6
+ type TAllowedResetPropsMutations = (typeof ALLOWED_RESET_PROPS_MUTATIONS)[number];
7
+ /**
8
+ * @type TAllowedResetPropsMutationsEnum
9
+ * Represents the allowed properties to be changed on resetPropertyValues.
10
+ *
11
+ * @property {never} api - api property
12
+ * @property {never} apiSchema - apiSchema property
13
+ * @property {never} props - props property
14
+ * @property {never} validations - validations property
15
+ * @property {never} visibilityConditions - visibilityConditions property
16
+ * @property {never} resetValues - resetValues property
17
+ *
18
+ * @interface
19
+ */
20
+ type TAllowedResetPropsMutationsEnum = Record<TAllowedResetPropsMutations, never>;
8
21
  /**
9
22
  * @type TLengthValidation
10
23
  * Represents the validation rules based on the length of the input.
@@ -33,7 +46,7 @@ type TLengthValidation = {
33
46
  * const callbackValidation: TCallbackValidation = (value) => typeof value === 'string';
34
47
  * ```
35
48
  */
36
- type TCallbackValidation = (value: unknown) => boolean;
49
+ type TCallbackValidation = (value: unknown, formValues: Pick<TFormValues<unknown>, 'values' | 'metadata'>) => boolean;
37
50
  /**
38
51
  * @type TBetweenValidation
39
52
  * Represents validation rules that check if a value is between a range.
@@ -536,19 +549,21 @@ type TSplitterFormatterValue = {
536
549
  * @property {number} [maxLength] - Truncates the input value to a specified maximum length if necessary.
537
550
  *
538
551
  * @example
539
- * ```typescript
540
- * const formatters: TFormatters = {
541
- * dotEvery3chars: true,
542
- * capitalize: true,
543
- * uppercase: true,
544
- * onlyNumbers: true,
545
- * regex: '^[a-zA-Z0-9]+$',
546
- * gapsCreditCard: [' ', ' '],
547
- * callback: (value) => value.toString().toUpperCase(),
548
- * splitter: [{ value: '-', position: 3 }],
549
- * trim: true,
550
- * maxLength: 15
551
- * };
552
+ * ```json
553
+ * {
554
+ * formatters: {
555
+ * dotEvery3chars: true,
556
+ * capitalize: true,
557
+ * uppercase: true,
558
+ * onlyNumbers: true,
559
+ * regex: '^[a-zA-Z0-9]+$',
560
+ * gapsCreditCard: [' ', ' '],
561
+ * callback: (value) => value.toString().toUpperCase(),
562
+ * splitter: [{ value: '-', position: 3 }],
563
+ * trim: true,
564
+ * maxLength: 15
565
+ * }
566
+ * }
552
567
  * ```
553
568
  */
554
569
  type TFormatters = {
@@ -712,7 +727,8 @@ type TVisibility = {
712
727
  * const resetValueMethods: TResetValueMethods = {
713
728
  * validations: { required: true },
714
729
  * fields: ['fieldName'],
715
- * resettledValue: ['']
730
+ * resettledValue: [''],
731
+ * events: ['ON_FIELD_CHANGE]
716
732
  * };
717
733
  * ```
718
734
  * @interface
@@ -725,7 +741,7 @@ type TResetValueMethods = Omit<TVisibility, 'showOnlyIfTrue' | 'validations'> &
725
741
  * @type TResetPathMethods
726
742
  * Method to reset some field properties other than component props or field value
727
743
  *
728
- * @property {(typeof ALLOWED_RESET_PROPS_MUTATIONS)[number]} property property to be changed, ex: api, resetValues, etc..
744
+ * @property {TAllowedResetPropsMutations} property property to be changed, ex: api, resetValues, etc..
729
745
  * @property {string} path path where the property to be changed is located
730
746
  * @property {string} field field that will recieve the property change
731
747
  * @property {unknown} resettledValue value to be replaced onto the property
@@ -742,7 +758,7 @@ type TResetValueMethods = Omit<TVisibility, 'showOnlyIfTrue' | 'validations'> &
742
758
  * ```
743
759
  */
744
760
  type TResetPathMethods = {
745
- property: (typeof ALLOWED_RESET_PROPS_MUTATIONS)[number];
761
+ property: TAllowedResetPropsMutations;
746
762
  path: string;
747
763
  field: string;
748
764
  resettledValue: unknown;
@@ -755,7 +771,7 @@ type TResetPathMethods = {
755
771
  *
756
772
  * @property {'GET' | 'POST'} method - The HTTP method for the request.
757
773
  * @property {string} url - The URL for the request.
758
- * @property {OutgoingHttpHeaders} [headers] - The headers for the request.
774
+ * @property {Record<string, string>} [headers] - The headers for the request.
759
775
  * @property {Record<string, string>} queryParams - query parameters for request.
760
776
  * @property {string} [resultPath] - The path to extract the result from the response.
761
777
  * @property {unknown} [fallbackValue] - The fallback value if the request fails.
@@ -785,7 +801,7 @@ type TApiConfig = {
785
801
  /** The body payload for the request. */
786
802
  body?: Record<string, unknown>;
787
803
  /** The headers for the request. */
788
- headers?: OutgoingHttpHeaders;
804
+ headers?: Record<string, string>;
789
805
  /** Query parameters for the request. */
790
806
  queryParams?: Record<string, string>;
791
807
  /** The path to extract the result from the response. */
@@ -817,7 +833,10 @@ type TProps = Record<string, unknown>;
817
833
  * @property {Partial<Record<TEvents, string[]>>} eventMessages - The messages to be displayed for specific validation events.
818
834
  * @property {TErrorMessages} messages - The general error messages for validation methods.
819
835
  *
836
+ * @interface
837
+ *
820
838
  * @example
839
+ * ```typescript
821
840
  * const validations: TValidations = {
822
841
  * methods: {
823
842
  * max: 100,
@@ -835,7 +854,7 @@ type TProps = Record<string, unknown>;
835
854
  * regex: 'Value does not match the pattern',
836
855
  * },
837
856
  * };
838
- * @interface
857
+ * ```
839
858
  */
840
859
  type TValidations = {
841
860
  methods: TSchemaValidation;
@@ -979,4 +998,4 @@ type TSchemaFormConfig = {
979
998
  defaultStateRefreshTimeMS?: number;
980
999
  defaultLogVerbose?: boolean;
981
1000
  };
982
- export { TApiConfig, TErrorMessages, TValidations, TMasks, TProps, TResetValueMethods, TResetPathMethods, TFormatters, TValidationMethods, TGenericValidationRule, TSchemaValidation, TEvent, TVisibility, TApiEvent, TApiResponsePayload, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, TEventMessages, TEventMessagesValidationMethods, };
1001
+ export { TApiConfig, TErrorMessages, TValidations, TMasks, TProps, TResetValueMethods, TResetPathMethods, TFormatters, TValidationMethods, TGenericValidationRule, TSchemaValidation, TEvent, TVisibility, TApiEvent, TApiResponsePayload, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, TEventMessages, TEventMessagesValidationMethods, TAllowedResetPropsMutationsEnum, };
@@ -1,9 +1,12 @@
1
+ import { TFormValues } from './form';
1
2
  import { TValidationMethods } from './schema';
2
3
  export type AllowOnly<T, K extends keyof T> = Pick<T, K> & {
3
4
  [P in keyof Omit<T, K>]?: never;
4
5
  };
5
6
  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>;
7
- export type Prettify<T> = {
8
- [K in keyof T]: T[K];
9
- } & {};
7
+ export type TValidationPayload = [
8
+ unknown,
9
+ TValidationMethods,
10
+ TFormValues<unknown>?
11
+ ];
12
+ export type TValidationHandler = Record<string, (...args: TValidationPayload) => boolean>;
@@ -1,9 +1,11 @@
1
+ import { TFormValues } from '../types/form';
1
2
  import { TValidationMethods } from '../types/schema';
2
3
  /**
3
4
  * Executes a custom callback validation function if provided.
4
5
  *
5
6
  * @param value - The value to be validated.
6
7
  * @param validations - An object containing validation methods, including a custom callback function.
8
+ * @param formValues - An object containing the form state, NOTE: validations might be dirty here
7
9
  * @returns `true` if the custom callback validation function returns `true`, otherwise `false`.
8
10
  *
9
11
  * @example
@@ -22,4 +24,4 @@ import { TValidationMethods } from '../types/schema';
22
24
  * };
23
25
  * ```
24
26
  */
25
- export declare const callback: (value: unknown, validations: TValidationMethods) => boolean;
27
+ export declare const callback: (value: unknown, validations: TValidationMethods, { values, metadata }?: TFormValues<unknown>) => boolean;
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";