procode-lowcode-core 1.0.15 → 1.0.17
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/dist/index.esm.js +197 -109
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +197 -109
- package/dist/index.js.map +1 -1
- package/dist/types/Action/helpers/hasFieldValidationErrors.d.ts +2 -0
- package/dist/types/ApplicationStart/AppDependenceyProvider.d.ts +4 -1
- package/dist/types/ApplicationStart/HOC/FieldValidationDispatcher.d.ts +9 -0
- package/dist/types/Constant.d.ts +1 -0
- package/dist/types/DataModel/CoreViewModelHandler.d.ts +2 -0
- package/dist/types/DataModel/SupportiveFunctions/index.d.ts +2 -2
- package/dist/types/Services/CentralService.d.ts +1 -1
- package/dist/types/Services/helpers/defaultFieldErrorMapper.d.ts +4 -0
- package/dist/types/Utils/resolveBoundValue.d.ts +1 -1
- package/package.json +1 -1
- package/src/Action/StandardActions/handleCreateAndNavigate.ts +16 -11
- package/src/Action/StandardActions/handleUpdateAndNavigate.ts +16 -11
- package/src/Action/helpers/hasFieldValidationErrors.ts +16 -0
- package/src/ApplicationStart/AppDependenceyProvider.ts +13 -0
- package/src/ApplicationStart/HOC/FieldValidationDispatcher.ts +21 -0
- package/src/ApplicationStart/helper/setupStoreAction.ts +12 -1
- package/src/Constant.ts +1 -0
- package/src/DataModel/CoreViewModelHandler.ts +221 -241
- package/src/DataModel/SupportiveFunctions/index.ts +12 -8
- package/src/Services/CentralService.ts +66 -57
- package/src/Services/helpers/defaultFieldErrorMapper.ts +40 -0
- package/src/Utils/resolveBoundValue.ts +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FieldErrors } from "../../ApplicationStart/HOC/FieldValidationDispatcher";
|
|
2
|
+
|
|
3
|
+
// A FieldErrorMapper takes whatever shape the backend uses for validation
|
|
4
|
+
// payloads and returns a uniform Record<fieldName, messages[]>. Backends with
|
|
5
|
+
// non-standard key names register a custom mapper via
|
|
6
|
+
// `AppDependenceyProvider.initInstance({ fieldErrorMapper: ... })`.
|
|
7
|
+
export type FieldErrorMapper = (raw: unknown) => FieldErrors;
|
|
8
|
+
|
|
9
|
+
// Default mapper assumes the common `{ propertyName, message }` convention.
|
|
10
|
+
// Accepts either a single object or an array of them, and groups multiple
|
|
11
|
+
// messages on the same field into one bucket.
|
|
12
|
+
const defaultFieldErrorMapper: FieldErrorMapper = (raw) => {
|
|
13
|
+
const errors: FieldErrors = {};
|
|
14
|
+
const append = (item: unknown) => {
|
|
15
|
+
if (
|
|
16
|
+
item &&
|
|
17
|
+
typeof item === "object" &&
|
|
18
|
+
"propertyName" in item &&
|
|
19
|
+
"message" in item
|
|
20
|
+
) {
|
|
21
|
+
const { propertyName, message } = item as {
|
|
22
|
+
propertyName: unknown;
|
|
23
|
+
message: unknown;
|
|
24
|
+
};
|
|
25
|
+
if (typeof propertyName === "string" && propertyName.length > 0) {
|
|
26
|
+
const list = errors[propertyName] ?? [];
|
|
27
|
+
list.push(typeof message === "string" ? message : String(message ?? ""));
|
|
28
|
+
errors[propertyName] = list;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (Array.isArray(raw)) {
|
|
33
|
+
raw.forEach(append);
|
|
34
|
+
} else {
|
|
35
|
+
append(raw);
|
|
36
|
+
}
|
|
37
|
+
return errors;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default defaultFieldErrorMapper;
|