@m4l/components 9.82.0 → 9.82.1-beta-hotfix-790-m4l-components-dynamic-form-validation.0

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 (26) hide show
  1. package/components/DynamicForm/DynamicForm.d.ts.map +1 -1
  2. package/components/DynamicForm/DynamicForm.js +69 -69
  3. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.d.ts +11 -0
  4. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.d.ts.map +1 -0
  5. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.js +64 -0
  6. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.d.ts +3 -0
  7. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.d.ts.map +1 -0
  8. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.js +10 -0
  9. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/index.d.ts +3 -0
  10. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/index.d.ts.map +1 -0
  11. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/types.d.ts +13 -0
  12. package/components/DynamicForm/helpers/buildDynamicFormBatchPayload/types.d.ts.map +1 -0
  13. package/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.d.ts.map +1 -1
  14. package/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.js +68 -49
  15. package/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.d.ts.map +1 -1
  16. package/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.js +103 -101
  17. package/components/DynamicForm/hooks/useDynamicForm/useDynamicForm.d.ts.map +1 -1
  18. package/components/DynamicForm/hooks/useDynamicForm/useDynamicForm.js +52 -48
  19. package/components/DynamicForm/hooks/useDynamicFormData/types.d.ts +3 -2
  20. package/components/DynamicForm/hooks/useDynamicFormData/types.d.ts.map +1 -1
  21. package/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.d.ts +2 -2
  22. package/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.d.ts.map +1 -1
  23. package/components/DynamicForm/hooks/useDynamicFormData/useDynamicFormData.js +106 -82
  24. package/components/DynamicForm/types.d.ts +8 -6
  25. package/components/DynamicForm/types.d.ts.map +1 -1
  26. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"DynamicForm.d.ts","sourceRoot":"","sources":["../../../../../../packages/components/src/components/DynamicForm/DynamicForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqF,MAAM,OAAO,CAAC;AAU1G,OAAO,EAEL,gBAAgB,EAChB,cAAc,EAGf,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW,yFA2RtB,CAAC"}
1
+ {"version":3,"file":"DynamicForm.d.ts","sourceRoot":"","sources":["../../../../../../packages/components/src/components/DynamicForm/DynamicForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqF,MAAM,OAAO,CAAC;AAU1G,OAAO,EAEL,gBAAgB,EAChB,cAAc,EAGf,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW,yFAiStB,CAAC"}
@@ -1,6 +1,6 @@
1
- import { jsx as r } from "@emotion/react/jsx-runtime";
2
- import Z, { forwardRef as $, useMemo as c, useState as tt, useEffect as et, useImperativeHandle as ot, useCallback as N } from "react";
3
- import P from "clsx";
1
+ import { jsx as i } from "@emotion/react/jsx-runtime";
2
+ import Z, { forwardRef as $, useMemo as c, useState as tt, useEffect as et, useImperativeHandle as ot, useCallback as P } from "react";
3
+ import T from "clsx";
4
4
  import { useModuleSkeleton as rt } from "@m4l/core";
5
5
  import { useComponentSize as it } from "../../hooks/useComponentSize/index.js";
6
6
  import { TEST_PROP_ID as st } from "../../test/constants_no_mock.js";
@@ -9,24 +9,24 @@ import { DynamicFormContentRootStyled as at, DynamicFormFormProviderStyled as mt
9
9
  import { DYNAMIC_FORM_CLASSES as b, EMPTY_DATA as ut } from "./constants.js";
10
10
  import { useDynamicForm as dt } from "./hooks/useDynamicForm/useDynamicForm.js";
11
11
  import { useDynamicFormData as lt } from "./hooks/useDynamicFormData/useDynamicFormData.js";
12
- import { DynamicFormContent as T } from "./subcomponents/DynamicFormContent/DynamicFormContent.js";
12
+ import { DynamicFormContent as C } from "./subcomponents/DynamicFormContent/DynamicFormContent.js";
13
13
  import { useFieldsWithFetchedOptions as ct } from "./hooks/useFieldsWithFetchedOptions/useFieldsWithFetchedOptions.js";
14
14
  import { filterUnknownFieldsFromSubmit as ft } from "./helpers/filterUnknownFieldsFromSubmit/filterUnknownFieldsFromSubmit.js";
15
- import { mapOptionFieldValuesForSubmit as pt } from "./helpers/mapOptionFieldValuesForSubmit/mapOptionFieldValuesForSubmit.js";
16
- import { normalizeDynamicFormFields as St } from "./helpers/resolveFormSections/resolveFormSections.js";
17
- const Ft = $((C, k) => {
15
+ import { normalizeDynamicFormFields as pt } from "./helpers/resolveFormSections/resolveFormSections.js";
16
+ import { mapOptionFieldValuesForSubmit as St } from "./helpers/mapOptionFieldValuesForSubmit/mapOptionFieldValuesForSubmit.js";
17
+ const Ft = $((k, z) => {
18
18
  const {
19
- formId: z,
20
- formInstanceId: _,
21
- inputEndpoint: A,
22
- outputEndpoint: i,
23
- submitMode: s,
19
+ formId: _,
20
+ formInstanceId: A,
21
+ inputEndpoint: H,
22
+ outputEndpoint: s,
23
+ submitMode: t,
24
24
  initialData: D,
25
- formatInputData: H,
26
- formatOutputData: L,
25
+ formatInputData: L,
26
+ formatOutputData: g,
27
27
  onSubmit: n,
28
28
  onSubmitError: y,
29
- size: g,
29
+ size: x,
30
30
  readOnly: a = !1,
31
31
  suppressFormHeader: h = !0,
32
32
  className: v,
@@ -35,39 +35,39 @@ const Ft = $((C, k) => {
35
35
  fieldWrapperClassName: E,
36
36
  fieldFlow: u = "responsiveWrap",
37
37
  coupled: p = !1,
38
- coupledStatusLoad: x,
39
- actionFormIntroProps: W,
40
- renderActions: V
41
- } = C, { currentSize: d } = it(g), U = rt(), {
42
- formData: Y,
38
+ coupledStatusLoad: W,
39
+ actionFormIntroProps: V,
40
+ renderActions: U
41
+ } = k, { currentSize: d } = it(x), Y = rt(), {
42
+ formData: j,
43
43
  statusLoad: I,
44
44
  handleSubmit: w
45
45
  } = lt({
46
- formId: z,
47
- formInstanceId: _,
48
- inputEndpoint: A,
49
- outputEndpoint: i,
50
- submitMode: s,
46
+ formId: _,
47
+ formInstanceId: A,
48
+ inputEndpoint: H,
49
+ outputEndpoint: s,
50
+ submitMode: t,
51
51
  initialData: D,
52
- formatInputData: H,
53
- formatOutputData: L,
52
+ formatInputData: L,
53
+ formatOutputData: g,
54
54
  onSubmit: n
55
- }), e = Y || D, S = c(
56
- () => St(e?.fields),
57
- [e?.fields]
55
+ }), o = j || D, S = c(
56
+ () => pt(o?.fields),
57
+ [o?.fields]
58
58
  ), { fields: O } = ct({
59
59
  fields: S.fields
60
- }), t = c(() => e && {
61
- ...e,
60
+ }), e = c(() => o && {
61
+ ...o,
62
62
  fields: O
63
- }, [O, e]), { initialValues: j, validationSchema: B } = dt(t || ut), [F, l] = tt(null);
63
+ }, [O, o]), { initialValues: B, validationSchema: q } = dt(e || ut), [F, l] = tt(null);
64
64
  et(() => {
65
65
  if (!F)
66
66
  return;
67
- const o = setTimeout(() => l(null), 5e3);
68
- return () => clearTimeout(o);
67
+ const r = setTimeout(() => l(null), 5e3);
68
+ return () => clearTimeout(r);
69
69
  }, [F]);
70
- const q = c(() => ({
70
+ const G = c(() => ({
71
71
  size: d,
72
72
  readOnly: a,
73
73
  fieldFlow: u
@@ -80,43 +80,43 @@ const Ft = $((C, k) => {
80
80
  onSubmit: () => {
81
81
  }
82
82
  }), []);
83
- ot(k, () => R.current ?? M, [M]);
84
- const G = N(
85
- async (o) => {
86
- if (!!!(i || s === "perField" || n))
83
+ ot(z, () => R.current ?? M, [M]);
84
+ const J = P(
85
+ async (r) => {
86
+ if (!!!(s || t === "batch" || t === "perField" || n))
87
87
  return;
88
- const K = i || s === "perField" ? w : n ?? (() => {
89
- }), Q = ft(
90
- o,
91
- t?.fields ?? []
92
- ), X = pt(Q, t?.fields ?? []);
88
+ const Q = s || t === "batch" || t === "perField" ? w : n ?? (() => {
89
+ }), N = ft(
90
+ r,
91
+ e?.fields ?? []
92
+ ), X = t === "batch" ? N : St(N, e?.fields ?? []);
93
93
  try {
94
- await K(X), l("success");
94
+ await Q(X), l("success");
95
95
  } catch {
96
96
  l("error");
97
97
  }
98
98
  },
99
- [w, n, i, t?.fields, s]
100
- ), J = N(
101
- (o) => {
102
- l("error"), y?.(o);
99
+ [w, n, s, e?.fields, t]
100
+ ), K = P(
101
+ (r) => {
102
+ l("error"), y?.(r);
103
103
  },
104
104
  [y]
105
105
  );
106
- return U ? /* @__PURE__ */ r(
106
+ return Y ? /* @__PURE__ */ i(
107
107
  at,
108
108
  {
109
- ownerState: q,
110
- className: P(v, b.contentRoot),
109
+ ownerState: G,
110
+ className: T(v, b.contentRoot),
111
111
  ...typeof m == "string" ? { "data-meta": m } : {},
112
112
  ...process.env.NODE_ENV !== "production" ? { [st]: f } : {},
113
- children: /* @__PURE__ */ r(nt, {})
113
+ children: /* @__PURE__ */ i(nt, {})
114
114
  }
115
- ) : t ? p ? /* @__PURE__ */ r(
116
- T,
115
+ ) : e ? p ? /* @__PURE__ */ i(
116
+ C,
117
117
  {
118
- data: t,
119
- statusLoad: x,
118
+ data: e,
119
+ statusLoad: W,
120
120
  currentSize: d,
121
121
  fieldWrapperClassName: E,
122
122
  dataTestId: f,
@@ -127,21 +127,21 @@ const Ft = $((C, k) => {
127
127
  fieldFlow: u,
128
128
  contractIssues: S.issues
129
129
  }
130
- ) : /* @__PURE__ */ r(
130
+ ) : /* @__PURE__ */ i(
131
131
  mt,
132
132
  {
133
133
  ref: R,
134
- values: j,
135
- validationSchema: B,
136
- onSubmit: G,
137
- onSubmitError: J,
134
+ values: B,
135
+ validationSchema: q,
136
+ onSubmit: J,
137
+ onSubmitError: K,
138
138
  statusLoad: I,
139
139
  mode: "onSubmit",
140
- className: P(v, b.contentRoot, b.formProvider),
141
- children: /* @__PURE__ */ r(
142
- T,
140
+ className: T(v, b.contentRoot, b.formProvider),
141
+ children: /* @__PURE__ */ i(
142
+ C,
143
143
  {
144
- data: t,
144
+ data: e,
145
145
  statusLoad: I,
146
146
  currentSize: d,
147
147
  fieldWrapperClassName: E,
@@ -152,8 +152,8 @@ const Ft = $((C, k) => {
152
152
  suppressFormHeader: h,
153
153
  fieldFlow: u,
154
154
  contractIssues: S.issues,
155
- actionFormIntroProps: W,
156
- renderActions: V,
155
+ actionFormIntroProps: V,
156
+ renderActions: U,
157
157
  submitFeedbackStatus: F
158
158
  }
159
159
  )
@@ -0,0 +1,11 @@
1
+ import { Field } from '../../types';
2
+ import { BuildDynamicFormBatchPayloadOptions, DynamicFormBatchPayload } from './types';
3
+ /**
4
+ * Reject a draft that tries to clear a persisted answer because the batch API treats null or an
5
+ * absent typed value as no change. This check intentionally runs before option mapping can turn a
6
+ * null single selection into an empty array.
7
+ */
8
+ export declare function assertNoUnsupportedBatchClear(data: Record<string, unknown>, fields: Field[]): void;
9
+ /** Build the native typed body accepted by the atomic form-instance values endpoint. */
10
+ export declare function buildDynamicFormBatchPayload(options: BuildDynamicFormBatchPayloadOptions): DynamicFormBatchPayload;
11
+ //# sourceMappingURL=buildDynamicFormBatchPayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildDynamicFormBatchPayload.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/buildDynamicFormBatchPayload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,KAAK,EACV,mCAAmC,EAEnC,uBAAuB,EAExB,MAAM,SAAS,CAAC;AAYjB;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,KAAK,EAAE,GACd,IAAI,CAyBN;AAqED,wFAAwF;AACxF,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mCAAmC,GAC3C,uBAAuB,CAiDzB"}
@@ -0,0 +1,64 @@
1
+ import { DYNAMIC_FORM_BATCH_VALUE_KEYS as b } from "./constants.js";
2
+ import { isKnownFieldComponent as d, isFieldExcludedFromSubmit as m } from "../filterUnknownFieldsFromSubmit/filterUnknownFieldsFromSubmit.js";
3
+ import { getFieldTypeApiKey as u } from "../getFieldTypeApiKey/getFieldTypeApiKey.js";
4
+ import { mapOptionFieldValuesForSubmit as p } from "../mapOptionFieldValuesForSubmit/mapOptionFieldValuesForSubmit.js";
5
+ function y(e) {
6
+ return Array.isArray(e) ? e.length > 0 : e != null;
7
+ }
8
+ function h(e, i) {
9
+ for (const t of i) {
10
+ if (!d(t) || m(t) || typeof t.name != "string" || !(t.name in e))
11
+ continue;
12
+ const n = e[t.name], a = n === null && t.currentValue !== null, o = u(t) === "value_jsonb" && Array.isArray(n) && n.length === 0 && y(t.currentValue);
13
+ if (a || o)
14
+ throw new Error(
15
+ `DynamicForm batch cannot clear field ${t.id}; the endpoint treats empty values as no change.`
16
+ );
17
+ }
18
+ }
19
+ function F(e) {
20
+ return e !== null && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
21
+ }
22
+ function f(e) {
23
+ return e === null || typeof e == "string" || typeof e == "boolean" ? !0 : typeof e == "number" ? Number.isFinite(e) : Array.isArray(e) ? e.every(f) : F(e) && Object.values(e).every(f);
24
+ }
25
+ function g(e, i, t) {
26
+ if (i === null)
27
+ return;
28
+ const n = () => {
29
+ throw new Error(`DynamicForm batch value is incompatible with ${e} for field ${t.id}.`);
30
+ };
31
+ e === "value_boolean" && typeof i != "boolean" && n(), e === "value_double" && (typeof i != "number" || !Number.isFinite(i)) && n(), e === "value_integer" && (typeof i != "number" || !Number.isSafeInteger(i)) && n(), e === "value_jsonb" && !f(i) && n(), e === "value_string" && typeof i != "string" && n();
32
+ }
33
+ function E(e) {
34
+ const { data: i, fields: t } = e;
35
+ h(i, t);
36
+ const n = p(i, t), a = /* @__PURE__ */ new Set(), o = [];
37
+ for (const r of t) {
38
+ if (!d(r) || m(r) || typeof r.name != "string" || !(r.name in n))
39
+ continue;
40
+ if (!Number.isSafeInteger(r.id))
41
+ throw new Error(`DynamicForm batch field id must be a safe integer: ${r.id}.`);
42
+ if (a.has(r.id))
43
+ throw new Error(`DynamicForm batch field id is duplicated: ${r.id}.`);
44
+ a.add(r.id);
45
+ const s = n[r.name];
46
+ if (s === void 0)
47
+ continue;
48
+ const c = u(r);
49
+ if (!b.has(c))
50
+ throw new Error(`DynamicForm field ${r.id} does not have a supported batch value key.`);
51
+ const l = c;
52
+ g(l, s, r), o.push({
53
+ form_field_id: r.id,
54
+ [l]: s
55
+ });
56
+ }
57
+ if (o.length === 0)
58
+ throw new Error("DynamicForm batch submit requires at least one eligible field value.");
59
+ return { fields: o };
60
+ }
61
+ export {
62
+ h as assertNoUnsupportedBatchClear,
63
+ E as buildDynamicFormBatchPayload
64
+ };
@@ -0,0 +1,3 @@
1
+ import { DynamicFormBatchValueKey } from './types';
2
+ export declare const DYNAMIC_FORM_BATCH_VALUE_KEYS: Set<DynamicFormBatchValueKey>;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,eAAO,MAAM,6BAA6B,+BAMxC,CAAC"}
@@ -0,0 +1,10 @@
1
+ const e = /* @__PURE__ */ new Set([
2
+ "value_boolean",
3
+ "value_double",
4
+ "value_integer",
5
+ "value_jsonb",
6
+ "value_string"
7
+ ]);
8
+ export {
9
+ e as DYNAMIC_FORM_BATCH_VALUE_KEYS
10
+ };
@@ -0,0 +1,3 @@
1
+ export * from './buildDynamicFormBatchPayload';
2
+ export type * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,mBAAmB,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Field } from '../../types';
2
+ export type DynamicFormBatchValueKey = 'value_boolean' | 'value_double' | 'value_integer' | 'value_jsonb' | 'value_string';
3
+ export type DynamicFormBatchField = {
4
+ form_field_id: number;
5
+ } & Partial<Record<DynamicFormBatchValueKey, unknown>>;
6
+ export interface DynamicFormBatchPayload {
7
+ fields: DynamicFormBatchField[];
8
+ }
9
+ export interface BuildDynamicFormBatchPayloadOptions {
10
+ data: Record<string, unknown>;
11
+ fields: Field[];
12
+ }
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/buildDynamicFormBatchPayload/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf,cAAc,GACd,eAAe,GACf,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,qBAAqB,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,mCAAmC;IAClD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"createFieldValidationSchema.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,KAAK,EAEV,+BAA+B,EAChC,MAAM,0BAA0B,CAAC;AA2DlC;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,GACrB,+BAA+B,CA4DjC"}
1
+ {"version":3,"file":"createFieldValidationSchema.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/createFieldValidationSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,KAAK,EAEV,+BAA+B,EAChC,MAAM,0BAA0B,CAAC;AA2ElC;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,GACrB,+BAA+B,CA8EjC"}
@@ -1,65 +1,84 @@
1
- import * as f from "yup";
2
- import { DYNAMIC_FORM_DICTIONARY as l } from "../../dictionary.js";
3
- import { createBaseSchema as p } from "./strategies/baseSchema/createBaseSchema.js";
4
- import { VALIDATION_STRATEGY_REGISTRY as y } from "./strategies/validation/validationStrategies.js";
5
- import { isSupportedDynamicFormField as V } from "../fieldContractAllowlist/fieldContractAllowlist.js";
6
- import { resolveFieldMandatory as v } from "../resolveFieldContractAliases/resolveFieldContractAliases.js";
7
- import { applyRequiredValidation as A } from "../applyRequiredValidation/applyRequiredValidation.js";
8
- import { isRecord as u } from "../isRecord/isRecord.js";
9
- import { normalizeValidation as S } from "../normalizeValidation/normalizeValidation.js";
10
- function g(r, i) {
11
- if (!(!u(r) || typeof r.id != "string" || r.id === ""))
1
+ import * as y from "yup";
2
+ import { DYNAMIC_FORM_DICTIONARY as c } from "../../dictionary.js";
3
+ import { createBaseSchema as v } from "./strategies/baseSchema/createBaseSchema.js";
4
+ import { VALIDATION_STRATEGY_REGISTRY as S } from "./strategies/validation/validationStrategies.js";
5
+ import { isSupportedDynamicFormField as A } from "../fieldContractAllowlist/fieldContractAllowlist.js";
6
+ import { resolveFieldMandatory as E } from "../resolveFieldContractAliases/resolveFieldContractAliases.js";
7
+ import { applyRequiredValidation as R } from "../applyRequiredValidation/applyRequiredValidation.js";
8
+ import { isRecord as p } from "../isRecord/isRecord.js";
9
+ import { normalizeValidation as F } from "../normalizeValidation/normalizeValidation.js";
10
+ import { resolveValidationErrorMessage as I } from "../resolveValidationErrorMessage/resolveValidationErrorMessage.js";
11
+ function M(e, r) {
12
+ if (!(!p(e) || typeof e.id != "string" || e.id === ""))
12
13
  return {
13
- id: r.id,
14
- name: typeof r.name == "string" ? r.name : r.id,
15
- requiresValue: typeof r.requiresValue == "boolean" ? r.requiresValue : i !== void 0,
16
- errorMessageForm: typeof r.errorMessageForm == "string" ? r.errorMessageForm : ""
14
+ id: e.id,
15
+ name: typeof e.name == "string" ? e.name : e.id,
16
+ requiresValue: typeof e.requiresValue == "boolean" ? e.requiresValue : r !== void 0,
17
+ errorMessageForm: typeof e.errorMessageForm == "string" ? e.errorMessageForm : ""
17
18
  };
18
19
  }
19
- function F(r) {
20
- if (!u(r) || r.isActive !== !0)
20
+ function _(e) {
21
+ if (!p(e) || e.isActive !== !0)
21
22
  return;
22
- const i = r.displayOrder;
23
- if (typeof i != "number" || !Number.isFinite(i))
23
+ const r = e.displayOrder;
24
+ if (typeof r != "number" || !Number.isFinite(r))
24
25
  return;
25
- const t = typeof r.validationValue == "string" ? r.validationValue : typeof r.validationValue == "number" ? String(r.validationValue) : void 0;
26
- return S({
27
- id: typeof r.id == "string" ? r.id : "",
26
+ const o = typeof e.validationValue == "string" ? e.validationValue : typeof e.validationValue == "number" ? String(e.validationValue) : void 0;
27
+ return F({
28
+ id: typeof e.id == "string" ? e.id : "",
28
29
  isActive: !0,
29
- displayOrder: i,
30
- validationType: g(r.validationType, t),
31
- validationValue: t
30
+ displayOrder: r,
31
+ validationType: M(e.validationType, o),
32
+ validationValue: o
32
33
  });
33
34
  }
34
- function b(r, i) {
35
- if (!V(r))
35
+ function g(e, r) {
36
+ return e.nullable().defined(r).test(
37
+ "active-validation-value-present",
38
+ r,
39
+ (o) => o != null
40
+ );
41
+ }
42
+ function U(e, r) {
43
+ if (!A(e))
36
44
  return;
37
- const t = v(r), n = Array.isArray(r.validations) ? r.validations : [];
38
- if (n.length === 0 && !t)
45
+ const o = E(e), l = Array.isArray(e.validations) ? e.validations : [];
46
+ if (l.length === 0 && !o)
39
47
  return;
40
- const s = p(r), d = n.map(F).filter((o) => o !== void 0).sort((o, a) => o.displayOrder - a.displayOrder);
41
- let e = s;
42
- for (const o of d) {
43
- const a = o.validationType;
44
- if (!a)
48
+ const a = v(e), u = l.map(_).filter((t) => t !== void 0).sort((t, n) => t.displayOrder - n.displayOrder);
49
+ let i = a, s = !1, d = r(c.IS_REQUIRED_MESSAGE);
50
+ for (const t of u) {
51
+ const n = t.validationType;
52
+ if (!n)
45
53
  continue;
46
- const m = y[a.id];
47
- m !== void 0 ? e = m.apply({
48
- field: r,
49
- getLabel: i,
50
- baseSchema: s,
51
- schema: e,
52
- validation: o
53
- }) : console.warn(`Unsupported validation type: ${a.id}`);
54
+ const f = S[n.id];
55
+ if (f !== void 0) {
56
+ const m = f.apply({
57
+ field: e,
58
+ getLabel: r,
59
+ baseSchema: a,
60
+ schema: i,
61
+ validation: t
62
+ });
63
+ n.id !== "fvl_required" && m !== i && (s || (d = I(
64
+ t,
65
+ r,
66
+ d
67
+ )), s = !0), i = m;
68
+ } else
69
+ console.warn(`Unsupported validation type: ${n.id}`);
54
70
  }
55
- const c = d.some((o) => o.validationType?.id === "fvl_required");
56
- return t && !c && (e = A(
57
- r,
71
+ const V = u.some((t) => t.validationType?.id === "fvl_required");
72
+ return o && !V && (i = R(
58
73
  e,
59
- s,
60
- i(l.IS_REQUIRED_MESSAGE)
61
- )), t || (s instanceof f.ArraySchema ? e = e.default([]) : e = e.nullable()), e;
74
+ i,
75
+ a,
76
+ r(c.IS_REQUIRED_MESSAGE)
77
+ )), o || (a instanceof y.ArraySchema ? i = i.default([]) : s ? i = g(
78
+ i,
79
+ d
80
+ ) : i = i.nullable()), i;
62
81
  }
63
82
  export {
64
- b as createFieldValidationSchema
83
+ U as createFieldValidationSchema
65
84
  };
@@ -1 +1 @@
1
- {"version":3,"file":"validationStrategies.d.ts","sourceRoot":"","sources":["../../../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIlD,oGAAoG;AACpG,eAAO,MAAM,0BAA0B,EAAE,kBAwBxC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,2BAA2B,EAAE,kBAyBzC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,2BAA2B,EAAE,kBAyBzC,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,EAAE,kBAyBnC,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,EAAE,kBAyBnC,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,uBAAuB,EAAE,kBAmBrC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,qBAAqB,EAAE,kBAmBnC,CAAC;AAEF,8BAA8B;AAC9B,eAAO,MAAM,yBAAyB,EAAE,kBA4BvC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAoEtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAU3E,CAAC"}
1
+ {"version":3,"file":"validationStrategies.d.ts","sourceRoot":"","sources":["../../../../../../../../../../packages/components/src/components/DynamicForm/helpers/createFieldValidationSchema/strategies/validation/validationStrategies.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAkBlD,oGAAoG;AACpG,eAAO,MAAM,0BAA0B,EAAE,kBAwBxC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,2BAA2B,EAAE,kBAyBzC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,2BAA2B,EAAE,kBAyBzC,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,EAAE,kBAyBnC,CAAC;AAEF,0BAA0B;AAC1B,eAAO,MAAM,qBAAqB,EAAE,kBAyBnC,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,uBAAuB,EAAE,kBAmBrC,CAAC;AAEF,2BAA2B;AAC3B,eAAO,MAAM,qBAAqB,EAAE,kBAmBnC,CAAC;AAEF,8BAA8B;AAC9B,eAAO,MAAM,yBAAyB,EAAE,kBA4BvC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,wBAAwB,EAAE,kBAkEtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAU3E,CAAC"}