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
package/dist/index.esm.js CHANGED
@@ -18706,14 +18706,26 @@ const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
18706
18706
  }
18707
18707
  });
18708
18708
 
18709
+ const replaceEndPointParams = (endPoint, data) => {
18710
+ if (!endPoint || !data || typeof data !== "object")
18711
+ return endPoint;
18712
+ return endPoint.replace(/:([a-zA-Z0-9_]+)/g, (match, paramName) => {
18713
+ return data[paramName] !== undefined && data[paramName] !== null
18714
+ ? encodeURIComponent(String(data[paramName]))
18715
+ : match;
18716
+ });
18717
+ };
18709
18718
  const handleAPICreate = (actionInvokerProps, data) => __awaiter(void 0, void 0, void 0, function* () {
18710
- var _a, _b, _c;
18719
+ var _a, _b, _c, _d;
18711
18720
  const eventService = actionInvokerProps.eventService;
18712
18721
  const uiSchema = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.UISCHEMA);
18713
- const apiConfig = (_a = actionInvokerProps.actionProps.config.apiConfig) !== null && _a !== void 0 ? _a : _.cloneDeep(uiSchema.apiConfig);
18714
- const response = yield ((_b = AppDependenceyProvider.getInstance()
18715
- .getViewModelHandler()) === null || _b === void 0 ? void 0 : _b.createModel(data, apiConfig, eventService));
18716
- (_c = actionInvokerProps.callBack) === null || _c === void 0 ? void 0 : _c.call(actionInvokerProps, response);
18722
+ const apiConfig = _.cloneDeep((_a = actionInvokerProps.actionProps.config.apiConfig) !== null && _a !== void 0 ? _a : uiSchema.apiConfig);
18723
+ if (((_b = apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.create) === null || _b === void 0 ? void 0 : _b.endPoint) && data) {
18724
+ apiConfig.create.endPoint = replaceEndPointParams(apiConfig.create.endPoint, Array.isArray(data) ? data[0] : data);
18725
+ }
18726
+ const response = yield ((_c = AppDependenceyProvider.getInstance()
18727
+ .getViewModelHandler()) === null || _c === void 0 ? void 0 : _c.createModel(data, apiConfig, eventService));
18728
+ (_d = actionInvokerProps.callBack) === null || _d === void 0 ? void 0 : _d.call(actionInvokerProps, response);
18717
18729
  });
18718
18730
 
18719
18731
  const handleAPIUpdate = (actionInvokerProps, data) => __awaiter(void 0, void 0, void 0, function* () {
@@ -18862,8 +18874,104 @@ var StandardValidationType;
18862
18874
  StandardValidationType["REQUIRED"] = "REQUIRED";
18863
18875
  StandardValidationType["EMAIL"] = "EMAIL";
18864
18876
  StandardValidationType["BULK_EMAIL"] = "BULK_EMAIL";
18877
+ StandardValidationType["MIN_CHAR_COUNT"] = "MIN_CHAR_COUNT";
18878
+ StandardValidationType["MAX_CHAR_COUNT"] = "MAX_CHAR_COUNT";
18879
+ StandardValidationType["GREATER_THAN"] = "GREATER_THAN";
18880
+ StandardValidationType["GREATER_THAN_EQUAL"] = "GREATER_THAN_EQUAL";
18881
+ StandardValidationType["LESS_THAN"] = "LESS_THAN";
18882
+ StandardValidationType["LESS_THAN_EQUAL"] = "LESS_THAN_EQUAL";
18883
+ StandardValidationType["BETWEEN"] = "BETWEEN";
18884
+ StandardValidationType["NOT_BETWEEN"] = "NOT_BETWEEN";
18865
18885
  })(StandardValidationType || (StandardValidationType = {}));
18866
18886
 
18887
+ /**
18888
+ * Resolves a comparison value from either a static param or a field path in the viewModel.
18889
+ * fieldPath takes priority over static value when both are provided.
18890
+ */
18891
+ const resolveCompareValue = (staticValue, fieldPath, viewModel) => {
18892
+ if (fieldPath) {
18893
+ return getValueFromNestedObject(fieldPath, viewModel);
18894
+ }
18895
+ return staticValue;
18896
+ };
18897
+ /**
18898
+ * Parses a raw value into a comparable numeric representation based on dataType.
18899
+ * Returns null if the value cannot be parsed.
18900
+ */
18901
+ const parseValue = (raw, dataType) => {
18902
+ if (raw === null || raw === undefined || raw === "")
18903
+ return null;
18904
+ if (dataType === "number") {
18905
+ const num = Number(raw);
18906
+ return isNaN(num) ? null : num;
18907
+ }
18908
+ if (dataType === "date") {
18909
+ const timestamp = new Date(raw).getTime();
18910
+ return isNaN(timestamp) ? null : timestamp;
18911
+ }
18912
+ if (dataType === "list") {
18913
+ if (Array.isArray(raw))
18914
+ return raw.length;
18915
+ const num = Number(raw);
18916
+ return isNaN(num) ? null : num;
18917
+ }
18918
+ return null;
18919
+ };
18920
+ /**
18921
+ * Formats a raw value for display in validation messages.
18922
+ */
18923
+ const formatValueForMessage = (raw, dataType) => {
18924
+ if (dataType === "date") {
18925
+ const date = new Date(raw);
18926
+ return isNaN(date.getTime()) ? String(raw) : date.toLocaleDateString();
18927
+ }
18928
+ if (dataType === "list") {
18929
+ return `${raw} item${Number(raw) === 1 ? "" : "s"}`;
18930
+ }
18931
+ return String(raw);
18932
+ };
18933
+ /**
18934
+ * Checks if a raw value is empty (null, undefined, or empty string).
18935
+ */
18936
+ const isEmpty = (value) => value === null ||
18937
+ value === undefined ||
18938
+ value === "" ||
18939
+ (Array.isArray(value) && value.length === 0);
18940
+
18941
+ const betweenValidation = ({ validation, viewModel, value, }) => {
18942
+ const { minValue, minFieldPath, maxValue, maxFieldPath, dataType = "number", } = validation.params || {};
18943
+ if (minValue === undefined && !minFieldPath) {
18944
+ console.error("BETWEEN validation requires 'minValue' or 'minFieldPath' in params");
18945
+ return { isValid: false, message: "Validation misconfigured: min boundary is missing" };
18946
+ }
18947
+ if (maxValue === undefined && !maxFieldPath) {
18948
+ console.error("BETWEEN validation requires 'maxValue' or 'maxFieldPath' in params");
18949
+ return { isValid: false, message: "Validation misconfigured: max boundary is missing" };
18950
+ }
18951
+ if (isEmpty(value))
18952
+ return { isValid: true, message: "" };
18953
+ const rawMin = resolveCompareValue(minValue, minFieldPath, viewModel);
18954
+ const rawMax = resolveCompareValue(maxValue, maxFieldPath, viewModel);
18955
+ if (isEmpty(rawMin) || isEmpty(rawMax))
18956
+ return { isValid: true, message: "" };
18957
+ const parsedValue = parseValue(value, dataType);
18958
+ const parsedMin = parseValue(rawMin, dataType);
18959
+ const parsedMax = parseValue(rawMax, dataType);
18960
+ if (parsedValue === null || parsedMin === null || parsedMax === null) {
18961
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
18962
+ }
18963
+ const isValid = parsedValue >= parsedMin && parsedValue <= parsedMax;
18964
+ const minLabel = formatValueForMessage(rawMin, dataType);
18965
+ const maxLabel = formatValueForMessage(rawMax, dataType);
18966
+ return {
18967
+ isValid,
18968
+ message: isValid
18969
+ ? ""
18970
+ : validation.message ||
18971
+ `Value must be between ${minLabel} and ${maxLabel}`,
18972
+ };
18973
+ };
18974
+
18867
18975
  const emailBulkValidation = ({ validation, viewModel, eventService, value, }) => {
18868
18976
  const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
18869
18977
  const emails = String(value).toLowerCase().split(";");
@@ -18885,6 +18993,194 @@ const emailValidation = ({ validation, viewModel, eventService, value, }) => {
18885
18993
  };
18886
18994
  };
18887
18995
 
18996
+ const greaterThanEqualValidation = ({ validation, viewModel, value, }) => {
18997
+ const { compareValue, compareFieldPath, dataType = "number" } = validation.params || {};
18998
+ if (compareValue === undefined && !compareFieldPath) {
18999
+ console.error("GREATER_THAN_EQUAL validation requires 'compareValue' or 'compareFieldPath' in params");
19000
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
19001
+ }
19002
+ if (isEmpty(value))
19003
+ return { isValid: true, message: "" };
19004
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
19005
+ if (isEmpty(rawCompare))
19006
+ return { isValid: true, message: "" };
19007
+ const parsedValue = parseValue(value, dataType);
19008
+ const parsedCompare = parseValue(rawCompare, dataType);
19009
+ if (parsedValue === null || parsedCompare === null) {
19010
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
19011
+ }
19012
+ const isValid = parsedValue >= parsedCompare;
19013
+ const compareLabel = compareFieldPath
19014
+ ? formatValueForMessage(rawCompare, dataType)
19015
+ : formatValueForMessage(compareValue, dataType);
19016
+ return {
19017
+ isValid,
19018
+ message: isValid
19019
+ ? ""
19020
+ : validation.message ||
19021
+ `Value must be greater than or equal to ${compareLabel}`,
19022
+ };
19023
+ };
19024
+
19025
+ const greaterThanValidation = ({ validation, viewModel, value, }) => {
19026
+ const { compareValue, compareFieldPath, dataType = "number" } = validation.params || {};
19027
+ if (compareValue === undefined && !compareFieldPath) {
19028
+ console.error("GREATER_THAN validation requires 'compareValue' or 'compareFieldPath' in params");
19029
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
19030
+ }
19031
+ if (isEmpty(value))
19032
+ return { isValid: true, message: "" };
19033
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
19034
+ if (isEmpty(rawCompare))
19035
+ return { isValid: true, message: "" };
19036
+ const parsedValue = parseValue(value, dataType);
19037
+ const parsedCompare = parseValue(rawCompare, dataType);
19038
+ if (parsedValue === null || parsedCompare === null) {
19039
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
19040
+ }
19041
+ const isValid = parsedValue > parsedCompare;
19042
+ const compareLabel = compareFieldPath
19043
+ ? formatValueForMessage(rawCompare, dataType)
19044
+ : formatValueForMessage(compareValue, dataType);
19045
+ return {
19046
+ isValid,
19047
+ message: isValid
19048
+ ? ""
19049
+ : validation.message || `Value must be greater than ${compareLabel}`,
19050
+ };
19051
+ };
19052
+
19053
+ const lessThanEqualValidation = ({ validation, viewModel, value, }) => {
19054
+ const { compareValue, compareFieldPath, dataType = "number" } = validation.params || {};
19055
+ if (compareValue === undefined && !compareFieldPath) {
19056
+ console.error("LESS_THAN_EQUAL validation requires 'compareValue' or 'compareFieldPath' in params");
19057
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
19058
+ }
19059
+ if (isEmpty(value))
19060
+ return { isValid: true, message: "" };
19061
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
19062
+ if (isEmpty(rawCompare))
19063
+ return { isValid: true, message: "" };
19064
+ const parsedValue = parseValue(value, dataType);
19065
+ const parsedCompare = parseValue(rawCompare, dataType);
19066
+ if (parsedValue === null || parsedCompare === null) {
19067
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
19068
+ }
19069
+ const isValid = parsedValue <= parsedCompare;
19070
+ const compareLabel = compareFieldPath
19071
+ ? formatValueForMessage(rawCompare, dataType)
19072
+ : formatValueForMessage(compareValue, dataType);
19073
+ return {
19074
+ isValid,
19075
+ message: isValid
19076
+ ? ""
19077
+ : validation.message ||
19078
+ `Value must be less than or equal to ${compareLabel}`,
19079
+ };
19080
+ };
19081
+
19082
+ const lessThanValidation = ({ validation, viewModel, value, }) => {
19083
+ const { compareValue, compareFieldPath, dataType = "number" } = validation.params || {};
19084
+ if (compareValue === undefined && !compareFieldPath) {
19085
+ console.error("LESS_THAN validation requires 'compareValue' or 'compareFieldPath' in params");
19086
+ return { isValid: false, message: "Validation misconfigured: comparison value is missing" };
19087
+ }
19088
+ if (isEmpty(value))
19089
+ return { isValid: true, message: "" };
19090
+ const rawCompare = resolveCompareValue(compareValue, compareFieldPath, viewModel);
19091
+ if (isEmpty(rawCompare))
19092
+ return { isValid: true, message: "" };
19093
+ const parsedValue = parseValue(value, dataType);
19094
+ const parsedCompare = parseValue(rawCompare, dataType);
19095
+ if (parsedValue === null || parsedCompare === null) {
19096
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
19097
+ }
19098
+ const isValid = parsedValue < parsedCompare;
19099
+ const compareLabel = compareFieldPath
19100
+ ? formatValueForMessage(rawCompare, dataType)
19101
+ : formatValueForMessage(compareValue, dataType);
19102
+ return {
19103
+ isValid,
19104
+ message: isValid
19105
+ ? ""
19106
+ : validation.message || `Value must be less than ${compareLabel}`,
19107
+ };
19108
+ };
19109
+
19110
+ const maxCharCountValidation = ({ validation, value, }) => {
19111
+ var _a;
19112
+ const maxCharCount = (_a = validation.params) === null || _a === void 0 ? void 0 : _a.maxCharCount;
19113
+ if (maxCharCount === undefined || maxCharCount === null) {
19114
+ console.error("MAX_CHAR_COUNT validation requires 'maxCharCount' in params");
19115
+ return { isValid: false, message: "Validation misconfigured: maxCharCount param is missing" };
19116
+ }
19117
+ if (value === null || value === undefined || value === "") {
19118
+ return { isValid: true, message: "" };
19119
+ }
19120
+ const strValue = String(value);
19121
+ const isValid = strValue.length <= maxCharCount;
19122
+ return {
19123
+ isValid,
19124
+ message: isValid
19125
+ ? ""
19126
+ : validation.message || `Maximum ${maxCharCount} characters allowed`,
19127
+ };
19128
+ };
19129
+
19130
+ const minCharCountValidation = ({ validation, value, }) => {
19131
+ var _a;
19132
+ const minCharCount = (_a = validation.params) === null || _a === void 0 ? void 0 : _a.minCharCount;
19133
+ if (minCharCount === undefined || minCharCount === null) {
19134
+ console.error("MIN_CHAR_COUNT validation requires 'minCharCount' in params");
19135
+ return { isValid: false, message: "Validation misconfigured: minCharCount param is missing" };
19136
+ }
19137
+ if (value === null || value === undefined || value === "") {
19138
+ return { isValid: true, message: "" };
19139
+ }
19140
+ const strValue = String(value);
19141
+ const isValid = strValue.length >= minCharCount;
19142
+ return {
19143
+ isValid,
19144
+ message: isValid
19145
+ ? ""
19146
+ : validation.message || `Minimum ${minCharCount} characters required`,
19147
+ };
19148
+ };
19149
+
19150
+ const notBetweenValidation = ({ validation, viewModel, value, }) => {
19151
+ const { minValue, minFieldPath, maxValue, maxFieldPath, dataType = "number", } = validation.params || {};
19152
+ if (minValue === undefined && !minFieldPath) {
19153
+ console.error("NOT_BETWEEN validation requires 'minValue' or 'minFieldPath' in params");
19154
+ return { isValid: false, message: "Validation misconfigured: min boundary is missing" };
19155
+ }
19156
+ if (maxValue === undefined && !maxFieldPath) {
19157
+ console.error("NOT_BETWEEN validation requires 'maxValue' or 'maxFieldPath' in params");
19158
+ return { isValid: false, message: "Validation misconfigured: max boundary is missing" };
19159
+ }
19160
+ if (isEmpty(value))
19161
+ return { isValid: true, message: "" };
19162
+ const rawMin = resolveCompareValue(minValue, minFieldPath, viewModel);
19163
+ const rawMax = resolveCompareValue(maxValue, maxFieldPath, viewModel);
19164
+ if (isEmpty(rawMin) || isEmpty(rawMax))
19165
+ return { isValid: true, message: "" };
19166
+ const parsedValue = parseValue(value, dataType);
19167
+ const parsedMin = parseValue(rawMin, dataType);
19168
+ const parsedMax = parseValue(rawMax, dataType);
19169
+ if (parsedValue === null || parsedMin === null || parsedMax === null) {
19170
+ return { isValid: false, message: validation.message || `Invalid ${dataType} value` };
19171
+ }
19172
+ const isValid = parsedValue < parsedMin || parsedValue > parsedMax;
19173
+ const minLabel = formatValueForMessage(rawMin, dataType);
19174
+ const maxLabel = formatValueForMessage(rawMax, dataType);
19175
+ return {
19176
+ isValid,
19177
+ message: isValid
19178
+ ? ""
19179
+ : validation.message ||
19180
+ `Value must not be between ${minLabel} and ${maxLabel}`,
19181
+ };
19182
+ };
19183
+
18888
19184
  const requiredValidation = ({ validation, viewModel, eventService, value, }) => {
18889
19185
  const isValid = !((Array.isArray(value) && value.length === 0) ||
18890
19186
  value === null ||
@@ -18906,6 +19202,14 @@ class StandardValidationFactory {
18906
19202
  [StandardValidationType.REQUIRED]: requiredValidation,
18907
19203
  [StandardValidationType.EMAIL]: emailValidation,
18908
19204
  [StandardValidationType.BULK_EMAIL]: emailBulkValidation,
19205
+ [StandardValidationType.MIN_CHAR_COUNT]: minCharCountValidation,
19206
+ [StandardValidationType.MAX_CHAR_COUNT]: maxCharCountValidation,
19207
+ [StandardValidationType.GREATER_THAN]: greaterThanValidation,
19208
+ [StandardValidationType.GREATER_THAN_EQUAL]: greaterThanEqualValidation,
19209
+ [StandardValidationType.LESS_THAN]: lessThanValidation,
19210
+ [StandardValidationType.LESS_THAN_EQUAL]: lessThanEqualValidation,
19211
+ [StandardValidationType.BETWEEN]: betweenValidation,
19212
+ [StandardValidationType.NOT_BETWEEN]: notBetweenValidation,
18909
19213
  }
18910
19214
  });
18911
19215
  }