procode-lowcode-core 1.0.10 → 1.0.11

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.
Files changed (30) hide show
  1. package/dist/index.esm.js +309 -5
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.js +309 -5
  4. package/dist/index.js.map +1 -1
  5. package/dist/types/Validation/IValidationFactory.d.ts +9 -1
  6. package/dist/types/Validation/StandardValidations/StandardValidationFactory.d.ts +24 -0
  7. package/dist/types/Validation/StandardValidations/betweenValidation.d.ts +5 -0
  8. package/dist/types/Validation/StandardValidations/comparisonValidationHelper.d.ts +20 -0
  9. package/dist/types/Validation/StandardValidations/greaterThanEqualValidation.d.ts +5 -0
  10. package/dist/types/Validation/StandardValidations/greaterThanValidation.d.ts +5 -0
  11. package/dist/types/Validation/StandardValidations/lessThanEqualValidation.d.ts +5 -0
  12. package/dist/types/Validation/StandardValidations/lessThanValidation.d.ts +5 -0
  13. package/dist/types/Validation/StandardValidations/maxCharCountValidation.d.ts +5 -0
  14. package/dist/types/Validation/StandardValidations/minCharCountValidation.d.ts +5 -0
  15. package/dist/types/Validation/StandardValidations/notBetweenValidation.d.ts +5 -0
  16. package/dist/types/Validation/Types.d.ts +1 -0
  17. package/package.json +1 -1
  18. package/src/Action/StandardActions/handleAPICreate.ts +19 -4
  19. package/src/Validation/IValidationFactory.ts +8 -0
  20. package/src/Validation/StandardValidations/StandardValidationFactory.ts +16 -0
  21. package/src/Validation/StandardValidations/betweenValidation.ts +62 -0
  22. package/src/Validation/StandardValidations/comparisonValidationHelper.ts +74 -0
  23. package/src/Validation/StandardValidations/greaterThanEqualValidation.ts +49 -0
  24. package/src/Validation/StandardValidations/greaterThanValidation.ts +48 -0
  25. package/src/Validation/StandardValidations/lessThanEqualValidation.ts +49 -0
  26. package/src/Validation/StandardValidations/lessThanValidation.ts +48 -0
  27. package/src/Validation/StandardValidations/maxCharCountValidation.ts +27 -0
  28. package/src/Validation/StandardValidations/minCharCountValidation.ts +27 -0
  29. package/src/Validation/StandardValidations/notBetweenValidation.ts +62 -0
  30. package/src/Validation/Types.ts +1 -0
@@ -1,7 +1,15 @@
1
1
  export declare enum StandardValidationType {
2
2
  REQUIRED = "REQUIRED",
3
3
  EMAIL = "EMAIL",
4
- BULK_EMAIL = "BULK_EMAIL"
4
+ BULK_EMAIL = "BULK_EMAIL",
5
+ MIN_CHAR_COUNT = "MIN_CHAR_COUNT",
6
+ MAX_CHAR_COUNT = "MAX_CHAR_COUNT",
7
+ GREATER_THAN = "GREATER_THAN",
8
+ GREATER_THAN_EQUAL = "GREATER_THAN_EQUAL",
9
+ LESS_THAN = "LESS_THAN",
10
+ LESS_THAN_EQUAL = "LESS_THAN_EQUAL",
11
+ BETWEEN = "BETWEEN",
12
+ NOT_BETWEEN = "NOT_BETWEEN"
5
13
  }
6
14
  export type ValidationFcResponse = {
7
15
  isValid: boolean;
@@ -10,6 +10,30 @@ declare class StandardValidationFactory implements IValidationFactory {
10
10
  }) | (({ validation, viewModel, eventService, value, }: import("../Types").ValidationFcProperties) => {
11
11
  isValid: boolean;
12
12
  message: string;
13
+ }) | (({ validation, value, }: import("../Types").ValidationFcProperties) => {
14
+ isValid: boolean;
15
+ message: string;
16
+ }) | (({ validation, value, }: import("../Types").ValidationFcProperties) => {
17
+ isValid: boolean;
18
+ message: string;
19
+ }) | (({ validation, viewModel, value, }: import("../Types").ValidationFcProperties) => {
20
+ isValid: boolean;
21
+ message: string;
22
+ }) | (({ validation, viewModel, value, }: import("../Types").ValidationFcProperties) => {
23
+ isValid: boolean;
24
+ message: string;
25
+ }) | (({ validation, viewModel, value, }: import("../Types").ValidationFcProperties) => {
26
+ isValid: boolean;
27
+ message: string;
28
+ }) | (({ validation, viewModel, value, }: import("../Types").ValidationFcProperties) => {
29
+ isValid: boolean;
30
+ message: string;
31
+ }) | (({ validation, viewModel, value, }: import("../Types").ValidationFcProperties) => {
32
+ isValid: boolean;
33
+ message: string;
34
+ }) | (({ validation, viewModel, value, }: import("../Types").ValidationFcProperties) => {
35
+ isValid: boolean;
36
+ message: string;
13
37
  });
14
38
  }
15
39
  export default StandardValidationFactory;
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const betweenValidation: ({ validation, viewModel, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,20 @@
1
+ import { ViewModel } from "../../DataModel/ViewModel";
2
+ export type CompareDataType = "number" | "date" | "list";
3
+ /**
4
+ * Resolves a comparison value from either a static param or a field path in the viewModel.
5
+ * fieldPath takes priority over static value when both are provided.
6
+ */
7
+ export declare const resolveCompareValue: (staticValue: any, fieldPath: string | undefined, viewModel: ViewModel) => any;
8
+ /**
9
+ * Parses a raw value into a comparable numeric representation based on dataType.
10
+ * Returns null if the value cannot be parsed.
11
+ */
12
+ export declare const parseValue: (raw: any, dataType: CompareDataType) => number | null;
13
+ /**
14
+ * Formats a raw value for display in validation messages.
15
+ */
16
+ export declare const formatValueForMessage: (raw: any, dataType: CompareDataType) => string;
17
+ /**
18
+ * Checks if a raw value is empty (null, undefined, or empty string).
19
+ */
20
+ export declare const isEmpty: (value: any) => boolean;
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const greaterThanEqualValidation: ({ validation, viewModel, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const greaterThanValidation: ({ validation, viewModel, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const lessThanEqualValidation: ({ validation, viewModel, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const lessThanValidation: ({ validation, viewModel, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const maxCharCountValidation: ({ validation, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const minCharCountValidation: ({ validation, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ export declare const notBetweenValidation: ({ validation, viewModel, value, }: ValidationFcProperties) => {
3
+ isValid: boolean;
4
+ message: string;
5
+ };
@@ -13,6 +13,7 @@ export type Validation = {
13
13
  executeMode: ExecuteMode;
14
14
  disabled: boolean;
15
15
  screenDataField?: string;
16
+ params?: Record<string, any>;
16
17
  };
17
18
  export type ValidationInvokerProperties = {
18
19
  validations: Validation[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "procode-lowcode-core",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "ProCode Core Library - React framework for low-code applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3,16 +3,31 @@ import { eventServiceType } from "../../Constant";
3
3
  import { ActionInvokerProperties } from "../Types";
4
4
  import { AppDependenceyProvider } from "../../ApplicationStart/AppDependenceyProvider";
5
5
 
6
+ const replaceEndPointParams = (endPoint: string, data: any): string => {
7
+ if (!endPoint || !data || typeof data !== "object") return endPoint;
8
+ return endPoint.replace(/:([a-zA-Z0-9_]+)/g, (match, paramName) => {
9
+ return data[paramName] !== undefined && data[paramName] !== null
10
+ ? encodeURIComponent(String(data[paramName]))
11
+ : match;
12
+ });
13
+ };
14
+
6
15
  const handleAPICreate = async (
7
16
  actionInvokerProps: ActionInvokerProperties,
8
- data: any | any[]
17
+ data: any | any[],
9
18
  ) => {
10
19
  const eventService = actionInvokerProps.eventService;
11
20
  const uiSchema = eventService?.emit(eventServiceType.UISCHEMA);
12
- const apiConfig =
13
- actionInvokerProps.actionProps.config.apiConfig ??
14
- _.cloneDeep(uiSchema.apiConfig);
21
+ const apiConfig = _.cloneDeep(
22
+ actionInvokerProps.actionProps.config.apiConfig ?? uiSchema.apiConfig,
23
+ );
15
24
 
25
+ if (apiConfig?.create?.endPoint && data) {
26
+ apiConfig.create.endPoint = replaceEndPointParams(
27
+ apiConfig.create.endPoint,
28
+ Array.isArray(data) ? data[0] : data,
29
+ );
30
+ }
16
31
  const response = await AppDependenceyProvider.getInstance()
17
32
  .getViewModelHandler()
18
33
  ?.createModel(data, apiConfig, eventService);
@@ -2,6 +2,14 @@ export enum StandardValidationType {
2
2
  REQUIRED = "REQUIRED",
3
3
  EMAIL = "EMAIL",
4
4
  BULK_EMAIL = "BULK_EMAIL",
5
+ MIN_CHAR_COUNT = "MIN_CHAR_COUNT",
6
+ MAX_CHAR_COUNT = "MAX_CHAR_COUNT",
7
+ GREATER_THAN = "GREATER_THAN",
8
+ GREATER_THAN_EQUAL = "GREATER_THAN_EQUAL",
9
+ LESS_THAN = "LESS_THAN",
10
+ LESS_THAN_EQUAL = "LESS_THAN_EQUAL",
11
+ BETWEEN = "BETWEEN",
12
+ NOT_BETWEEN = "NOT_BETWEEN",
5
13
  }
6
14
 
7
15
  export type ValidationFcResponse = { isValid: boolean; message: string };
@@ -1,8 +1,16 @@
1
1
  import IValidationFactory, {
2
2
  StandardValidationType,
3
3
  } from "../IValidationFactory";
4
+ import { betweenValidation } from "./betweenValidation";
4
5
  import { emailBulkValidation } from "./emailBulkValidation";
5
6
  import { emailValidation } from "./emailValidation";
7
+ import { greaterThanEqualValidation } from "./greaterThanEqualValidation";
8
+ import { greaterThanValidation } from "./greaterThanValidation";
9
+ import { lessThanEqualValidation } from "./lessThanEqualValidation";
10
+ import { lessThanValidation } from "./lessThanValidation";
11
+ import { maxCharCountValidation } from "./maxCharCountValidation";
12
+ import { minCharCountValidation } from "./minCharCountValidation";
13
+ import { notBetweenValidation } from "./notBetweenValidation";
6
14
  import { requiredValidation } from "./requiredValidation";
7
15
 
8
16
  class StandardValidationFactory implements IValidationFactory {
@@ -10,6 +18,14 @@ class StandardValidationFactory implements IValidationFactory {
10
18
  [StandardValidationType.REQUIRED]: requiredValidation,
11
19
  [StandardValidationType.EMAIL]: emailValidation,
12
20
  [StandardValidationType.BULK_EMAIL]: emailBulkValidation,
21
+ [StandardValidationType.MIN_CHAR_COUNT]: minCharCountValidation,
22
+ [StandardValidationType.MAX_CHAR_COUNT]: maxCharCountValidation,
23
+ [StandardValidationType.GREATER_THAN]: greaterThanValidation,
24
+ [StandardValidationType.GREATER_THAN_EQUAL]: greaterThanEqualValidation,
25
+ [StandardValidationType.LESS_THAN]: lessThanValidation,
26
+ [StandardValidationType.LESS_THAN_EQUAL]: lessThanEqualValidation,
27
+ [StandardValidationType.BETWEEN]: betweenValidation,
28
+ [StandardValidationType.NOT_BETWEEN]: notBetweenValidation,
13
29
  };
14
30
 
15
31
  getValidationFc(key: StandardValidationType) {
@@ -0,0 +1,62 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ import {
3
+ resolveCompareValue,
4
+ parseValue,
5
+ formatValueForMessage,
6
+ isEmpty,
7
+ } from "./comparisonValidationHelper";
8
+
9
+ export const betweenValidation = ({
10
+ validation,
11
+ viewModel,
12
+ value,
13
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
14
+ const {
15
+ minValue,
16
+ minFieldPath,
17
+ maxValue,
18
+ maxFieldPath,
19
+ dataType = "number",
20
+ } = validation.params || {};
21
+
22
+ if (minValue === undefined && !minFieldPath) {
23
+ console.error(
24
+ "BETWEEN validation requires 'minValue' or 'minFieldPath' in params"
25
+ );
26
+ return { isValid: false, message: "Validation misconfigured: min boundary is missing" };
27
+ }
28
+
29
+ if (maxValue === undefined && !maxFieldPath) {
30
+ console.error(
31
+ "BETWEEN validation requires 'maxValue' or 'maxFieldPath' in params"
32
+ );
33
+ return { isValid: false, message: "Validation misconfigured: max boundary is missing" };
34
+ }
35
+
36
+ if (isEmpty(value)) return { isValid: true, message: "" };
37
+
38
+ const rawMin = resolveCompareValue(minValue, minFieldPath, viewModel);
39
+ const rawMax = resolveCompareValue(maxValue, maxFieldPath, viewModel);
40
+
41
+ if (isEmpty(rawMin) || isEmpty(rawMax)) return { isValid: true, message: "" };
42
+
43
+ const parsedValue = parseValue(value, dataType);
44
+ const parsedMin = parseValue(rawMin, dataType);
45
+ const parsedMax = parseValue(rawMax, dataType);
46
+
47
+ if (parsedValue === null || parsedMin === null || parsedMax === null) {
48
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
49
+ }
50
+
51
+ const isValid = parsedValue >= parsedMin && parsedValue <= parsedMax;
52
+ const minLabel = formatValueForMessage(rawMin, dataType);
53
+ const maxLabel = formatValueForMessage(rawMax, dataType);
54
+
55
+ return {
56
+ isValid,
57
+ message: isValid
58
+ ? ""
59
+ : validation.message ||
60
+ `Value must be between ${minLabel} and ${maxLabel}`,
61
+ };
62
+ };
@@ -0,0 +1,74 @@
1
+ import { ViewModel } from "../../DataModel/ViewModel";
2
+ import { getValueFromNestedObject } from "../../Utils/getValueFromNestedObject";
3
+
4
+ export type CompareDataType = "number" | "date" | "list";
5
+
6
+ /**
7
+ * Resolves a comparison value from either a static param or a field path in the viewModel.
8
+ * fieldPath takes priority over static value when both are provided.
9
+ */
10
+ export const resolveCompareValue = (
11
+ staticValue: any,
12
+ fieldPath: string | undefined,
13
+ viewModel: ViewModel
14
+ ): any => {
15
+ if (fieldPath) {
16
+ return getValueFromNestedObject(fieldPath, viewModel);
17
+ }
18
+ return staticValue;
19
+ };
20
+
21
+ /**
22
+ * Parses a raw value into a comparable numeric representation based on dataType.
23
+ * Returns null if the value cannot be parsed.
24
+ */
25
+ export const parseValue = (
26
+ raw: any,
27
+ dataType: CompareDataType
28
+ ): number | null => {
29
+ if (raw === null || raw === undefined || raw === "") return null;
30
+
31
+ if (dataType === "number") {
32
+ const num = Number(raw);
33
+ return isNaN(num) ? null : num;
34
+ }
35
+
36
+ if (dataType === "date") {
37
+ const timestamp = new Date(raw).getTime();
38
+ return isNaN(timestamp) ? null : timestamp;
39
+ }
40
+
41
+ if (dataType === "list") {
42
+ if (Array.isArray(raw)) return raw.length;
43
+ const num = Number(raw);
44
+ return isNaN(num) ? null : num;
45
+ }
46
+
47
+ return null;
48
+ };
49
+
50
+ /**
51
+ * Formats a raw value for display in validation messages.
52
+ */
53
+ export const formatValueForMessage = (
54
+ raw: any,
55
+ dataType: CompareDataType
56
+ ): string => {
57
+ if (dataType === "date") {
58
+ const date = new Date(raw);
59
+ return isNaN(date.getTime()) ? String(raw) : date.toLocaleDateString();
60
+ }
61
+ if (dataType === "list") {
62
+ return `${raw} item${Number(raw) === 1 ? "" : "s"}`;
63
+ }
64
+ return String(raw);
65
+ };
66
+
67
+ /**
68
+ * Checks if a raw value is empty (null, undefined, or empty string).
69
+ */
70
+ export const isEmpty = (value: any): boolean =>
71
+ value === null ||
72
+ value === undefined ||
73
+ value === "" ||
74
+ (Array.isArray(value) && value.length === 0);
@@ -0,0 +1,49 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ import {
3
+ resolveCompareValue,
4
+ parseValue,
5
+ formatValueForMessage,
6
+ isEmpty,
7
+ } from "./comparisonValidationHelper";
8
+
9
+ export const greaterThanEqualValidation = ({
10
+ validation,
11
+ viewModel,
12
+ value,
13
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
14
+ const { compareValue, compareFieldPath, dataType = "number" } =
15
+ validation.params || {};
16
+
17
+ if (compareValue === undefined && !compareFieldPath) {
18
+ console.error(
19
+ "GREATER_THAN_EQUAL validation requires 'compareValue' or 'compareFieldPath' in params"
20
+ );
21
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
22
+ }
23
+
24
+ if (isEmpty(value)) return { isValid: true, message: "" };
25
+
26
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
27
+
28
+ if (isEmpty(rawCompare)) return { isValid: true, message: "" };
29
+
30
+ const parsedValue = parseValue(value, dataType);
31
+ const parsedCompare = parseValue(rawCompare, dataType);
32
+
33
+ if (parsedValue === null || parsedCompare === null) {
34
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
35
+ }
36
+
37
+ const isValid = parsedValue >= parsedCompare;
38
+ const compareLabel = compareFieldPath
39
+ ? formatValueForMessage(rawCompare, dataType)
40
+ : formatValueForMessage(compareValue, dataType);
41
+
42
+ return {
43
+ isValid,
44
+ message: isValid
45
+ ? ""
46
+ : validation.message ||
47
+ `Value must be greater than or equal to ${compareLabel}`,
48
+ };
49
+ };
@@ -0,0 +1,48 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ import {
3
+ resolveCompareValue,
4
+ parseValue,
5
+ formatValueForMessage,
6
+ isEmpty,
7
+ } from "./comparisonValidationHelper";
8
+
9
+ export const greaterThanValidation = ({
10
+ validation,
11
+ viewModel,
12
+ value,
13
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
14
+ const { compareValue, compareFieldPath, dataType = "number" } =
15
+ validation.params || {};
16
+
17
+ if (compareValue === undefined && !compareFieldPath) {
18
+ console.error(
19
+ "GREATER_THAN validation requires 'compareValue' or 'compareFieldPath' in params"
20
+ );
21
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
22
+ }
23
+
24
+ if (isEmpty(value)) return { isValid: true, message: "" };
25
+
26
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
27
+
28
+ if (isEmpty(rawCompare)) return { isValid: true, message: "" };
29
+
30
+ const parsedValue = parseValue(value, dataType);
31
+ const parsedCompare = parseValue(rawCompare, dataType);
32
+
33
+ if (parsedValue === null || parsedCompare === null) {
34
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
35
+ }
36
+
37
+ const isValid = parsedValue > parsedCompare;
38
+ const compareLabel = compareFieldPath
39
+ ? formatValueForMessage(rawCompare, dataType)
40
+ : formatValueForMessage(compareValue, dataType);
41
+
42
+ return {
43
+ isValid,
44
+ message: isValid
45
+ ? ""
46
+ : validation.message || `Value must be greater than ${compareLabel}`,
47
+ };
48
+ };
@@ -0,0 +1,49 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ import {
3
+ resolveCompareValue,
4
+ parseValue,
5
+ formatValueForMessage,
6
+ isEmpty,
7
+ } from "./comparisonValidationHelper";
8
+
9
+ export const lessThanEqualValidation = ({
10
+ validation,
11
+ viewModel,
12
+ value,
13
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
14
+ const { compareValue, compareFieldPath, dataType = "number" } =
15
+ validation.params || {};
16
+
17
+ if (compareValue === undefined && !compareFieldPath) {
18
+ console.error(
19
+ "LESS_THAN_EQUAL validation requires 'compareValue' or 'compareFieldPath' in params"
20
+ );
21
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
22
+ }
23
+
24
+ if (isEmpty(value)) return { isValid: true, message: "" };
25
+
26
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
27
+
28
+ if (isEmpty(rawCompare)) return { isValid: true, message: "" };
29
+
30
+ const parsedValue = parseValue(value, dataType);
31
+ const parsedCompare = parseValue(rawCompare, dataType);
32
+
33
+ if (parsedValue === null || parsedCompare === null) {
34
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
35
+ }
36
+
37
+ const isValid = parsedValue <= parsedCompare;
38
+ const compareLabel = compareFieldPath
39
+ ? formatValueForMessage(rawCompare, dataType)
40
+ : formatValueForMessage(compareValue, dataType);
41
+
42
+ return {
43
+ isValid,
44
+ message: isValid
45
+ ? ""
46
+ : validation.message ||
47
+ `Value must be less than or equal to ${compareLabel}`,
48
+ };
49
+ };
@@ -0,0 +1,48 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+ import {
3
+ resolveCompareValue,
4
+ parseValue,
5
+ formatValueForMessage,
6
+ isEmpty,
7
+ } from "./comparisonValidationHelper";
8
+
9
+ export const lessThanValidation = ({
10
+ validation,
11
+ viewModel,
12
+ value,
13
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
14
+ const { compareValue, compareFieldPath, dataType = "number" } =
15
+ validation.params || {};
16
+
17
+ if (compareValue === undefined && !compareFieldPath) {
18
+ console.error(
19
+ "LESS_THAN validation requires 'compareValue' or 'compareFieldPath' in params"
20
+ );
21
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
22
+ }
23
+
24
+ if (isEmpty(value)) return { isValid: true, message: "" };
25
+
26
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
27
+
28
+ if (isEmpty(rawCompare)) return { isValid: true, message: "" };
29
+
30
+ const parsedValue = parseValue(value, dataType);
31
+ const parsedCompare = parseValue(rawCompare, dataType);
32
+
33
+ if (parsedValue === null || parsedCompare === null) {
34
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
35
+ }
36
+
37
+ const isValid = parsedValue < parsedCompare;
38
+ const compareLabel = compareFieldPath
39
+ ? formatValueForMessage(rawCompare, dataType)
40
+ : formatValueForMessage(compareValue, dataType);
41
+
42
+ return {
43
+ isValid,
44
+ message: isValid
45
+ ? ""
46
+ : validation.message || `Value must be less than ${compareLabel}`,
47
+ };
48
+ };
@@ -0,0 +1,27 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+
3
+ export const maxCharCountValidation = ({
4
+ validation,
5
+ value,
6
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
7
+ const maxCharCount = validation.params?.maxCharCount;
8
+
9
+ if (maxCharCount === undefined || maxCharCount === null) {
10
+ console.error("MAX_CHAR_COUNT validation requires 'maxCharCount' in params");
11
+ return { isValid: false, message: "Validation misconfigured: maxCharCount param is missing" };
12
+ }
13
+
14
+ if (value === null || value === undefined || value === "") {
15
+ return { isValid: true, message: "" };
16
+ }
17
+
18
+ const strValue = String(value);
19
+ const isValid = strValue.length <= maxCharCount;
20
+
21
+ return {
22
+ isValid,
23
+ message: isValid
24
+ ? ""
25
+ : validation.message || `Maximum ${maxCharCount} characters allowed`,
26
+ };
27
+ };
@@ -0,0 +1,27 @@
1
+ import { ValidationFcProperties } from "../Types";
2
+
3
+ export const minCharCountValidation = ({
4
+ validation,
5
+ value,
6
+ }: ValidationFcProperties): { isValid: boolean; message: string } => {
7
+ const minCharCount = validation.params?.minCharCount;
8
+
9
+ if (minCharCount === undefined || minCharCount === null) {
10
+ console.error("MIN_CHAR_COUNT validation requires 'minCharCount' in params");
11
+ return { isValid: false, message: "Validation misconfigured: minCharCount param is missing" };
12
+ }
13
+
14
+ if (value === null || value === undefined || value === "") {
15
+ return { isValid: true, message: "" };
16
+ }
17
+
18
+ const strValue = String(value);
19
+ const isValid = strValue.length >= minCharCount;
20
+
21
+ return {
22
+ isValid,
23
+ message: isValid
24
+ ? ""
25
+ : validation.message || `Minimum ${minCharCount} characters required`,
26
+ };
27
+ };