@ram_28/kf-ai-sdk 2.0.14 → 2.0.16

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 (157) hide show
  1. package/README.md +10 -9
  2. package/dist/FileField-BWrSHNRq.js +296 -0
  3. package/dist/FileField-eDeuzln8.cjs +1 -0
  4. package/dist/api.cjs +1 -1
  5. package/dist/api.mjs +2 -2
  6. package/dist/auth.cjs +1 -1
  7. package/dist/auth.mjs +1 -1
  8. package/dist/bdo/core/BaseBdo.d.ts +1 -1
  9. package/dist/bdo.cjs +1 -1
  10. package/dist/bdo.mjs +230 -474
  11. package/dist/{client-DnO2KKrw.cjs → client-D5k4SYuw.cjs} +1 -1
  12. package/dist/{client-iQTqFDNI.js → client-_ayziI1d.js} +33 -32
  13. package/dist/components/hooks/index.d.ts +9 -3
  14. package/dist/components/hooks/index.d.ts.map +1 -1
  15. package/dist/{workflow/components → components/hooks}/useActivityForm/createActivityItemProxy.d.ts +9 -5
  16. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -0
  17. package/dist/components/hooks/useActivityForm/createActivityResolver.d.ts +23 -0
  18. package/dist/components/hooks/useActivityForm/createActivityResolver.d.ts.map +1 -0
  19. package/dist/components/hooks/useActivityForm/index.d.ts.map +1 -0
  20. package/dist/{workflow/components → components/hooks}/useActivityForm/types.d.ts +12 -8
  21. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -0
  22. package/dist/{workflow/components → components/hooks}/useActivityForm/useActivityForm.d.ts +2 -2
  23. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -0
  24. package/dist/components/hooks/useActivityTable/index.d.ts +4 -0
  25. package/dist/components/hooks/useActivityTable/index.d.ts.map +1 -0
  26. package/dist/components/hooks/useActivityTable/types.d.ts +36 -0
  27. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -0
  28. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +4 -0
  29. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -0
  30. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
  31. package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
  32. package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
  33. package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
  34. package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
  35. package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
  36. package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
  37. package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
  38. package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
  39. package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
  40. package/dist/components/hooks/useBDOTable/index.d.ts +3 -0
  41. package/dist/components/hooks/useBDOTable/index.d.ts.map +1 -0
  42. package/dist/components/hooks/useBDOTable/types.d.ts +24 -0
  43. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -0
  44. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +3 -0
  45. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -0
  46. package/dist/components/hooks/useTable/index.d.ts +2 -2
  47. package/dist/components/hooks/useTable/index.d.ts.map +1 -1
  48. package/dist/components/hooks/useTable/types.d.ts +11 -10
  49. package/dist/components/hooks/useTable/types.d.ts.map +1 -1
  50. package/dist/components/hooks/useTable/useTable.d.ts +1 -1
  51. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  52. package/dist/form.cjs +1 -1
  53. package/dist/form.d.ts +1 -1
  54. package/dist/form.d.ts.map +1 -1
  55. package/dist/form.mjs +279 -344
  56. package/dist/form.types.d.ts +1 -1
  57. package/dist/form.types.d.ts.map +1 -1
  58. package/dist/{metadata-DpfI3zRN.js → metadata-Cc1mBcLS.js} +1 -1
  59. package/dist/{metadata-DgLSJkF5.cjs → metadata-DWXQPDav.cjs} +1 -1
  60. package/dist/shared-5a7UkED1.js +1180 -0
  61. package/dist/shared-nnmlRVs7.cjs +1 -0
  62. package/dist/table.cjs +1 -1
  63. package/dist/table.d.ts +1 -0
  64. package/dist/table.d.ts.map +1 -1
  65. package/dist/table.mjs +17 -192
  66. package/dist/table.types.d.ts +2 -1
  67. package/dist/table.types.d.ts.map +1 -1
  68. package/dist/types/base-fields.d.ts +4 -4
  69. package/dist/types/base-fields.d.ts.map +1 -1
  70. package/dist/types/constants.d.ts +3 -3
  71. package/dist/useTable-CeRklbdT.cjs +1 -0
  72. package/dist/useTable-DS0-WInw.js +203 -0
  73. package/dist/workflow/Activity.d.ts +19 -7
  74. package/dist/workflow/Activity.d.ts.map +1 -1
  75. package/dist/workflow/client.d.ts +2 -2
  76. package/dist/workflow/client.d.ts.map +1 -1
  77. package/dist/workflow/createFieldFromMeta.d.ts +29 -0
  78. package/dist/workflow/createFieldFromMeta.d.ts.map +1 -0
  79. package/dist/workflow/index.d.ts +1 -2
  80. package/dist/workflow/index.d.ts.map +1 -1
  81. package/dist/workflow/types.d.ts +16 -12
  82. package/dist/workflow/types.d.ts.map +1 -1
  83. package/dist/workflow.cjs +1 -1
  84. package/dist/workflow.d.ts +5 -2
  85. package/dist/workflow.d.ts.map +1 -1
  86. package/dist/workflow.mjs +687 -352
  87. package/dist/workflow.types.d.ts +1 -0
  88. package/dist/workflow.types.d.ts.map +1 -1
  89. package/docs/bdo.md +1 -1
  90. package/docs/gaps.md +360 -0
  91. package/docs/useActivityForm.md +393 -0
  92. package/docs/useActivityTable.md +418 -0
  93. package/docs/{useForm.md → useBDOForm.md} +24 -24
  94. package/docs/useBDOTable.md +284 -0
  95. package/docs/workflow.md +148 -297
  96. package/package.json +2 -2
  97. package/sdk/bdo/core/BaseBdo.ts +2 -2
  98. package/sdk/bdo/fields/UserField.ts +1 -1
  99. package/sdk/components/hooks/index.ts +28 -5
  100. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +400 -0
  101. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +87 -0
  102. package/sdk/{workflow/components → components/hooks}/useActivityForm/types.ts +24 -11
  103. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +478 -0
  104. package/sdk/components/hooks/useActivityTable/index.ts +8 -0
  105. package/sdk/components/hooks/useActivityTable/types.ts +47 -0
  106. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +40 -0
  107. package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
  108. package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
  109. package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
  110. package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
  111. package/sdk/components/hooks/useBDOTable/index.ts +2 -0
  112. package/sdk/components/hooks/useBDOTable/types.ts +22 -0
  113. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +16 -0
  114. package/sdk/components/hooks/useTable/index.ts +3 -3
  115. package/sdk/components/hooks/useTable/types.ts +16 -12
  116. package/sdk/components/hooks/useTable/useTable.ts +56 -49
  117. package/sdk/form.ts +2 -2
  118. package/sdk/form.types.ts +4 -4
  119. package/sdk/table.ts +4 -1
  120. package/sdk/table.types.ts +7 -4
  121. package/sdk/types/base-fields.ts +4 -4
  122. package/sdk/types/constants.ts +3 -3
  123. package/sdk/workflow/Activity.ts +36 -12
  124. package/sdk/workflow/client.ts +65 -12
  125. package/sdk/workflow/createFieldFromMeta.ts +110 -0
  126. package/sdk/workflow/index.ts +1 -6
  127. package/sdk/workflow/types.ts +20 -11
  128. package/sdk/workflow.ts +11 -2
  129. package/sdk/workflow.types.ts +7 -0
  130. package/dist/BaseField-B6da88U7.js +0 -40
  131. package/dist/BaseField-Drp0-OxL.cjs +0 -1
  132. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
  133. package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
  134. package/dist/components/hooks/useForm/index.d.ts +0 -5
  135. package/dist/components/hooks/useForm/index.d.ts.map +0 -1
  136. package/dist/components/hooks/useForm/types.d.ts.map +0 -1
  137. package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
  138. package/dist/error-handling-CAoD0Kwb.cjs +0 -1
  139. package/dist/error-handling-CrhTtD88.js +0 -14
  140. package/dist/index.esm-Cj63v5ny.js +0 -1014
  141. package/dist/index.esm-DuwT11sx.cjs +0 -1
  142. package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts.map +0 -1
  143. package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts +0 -22
  144. package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts.map +0 -1
  145. package/dist/workflow/components/useActivityForm/index.d.ts.map +0 -1
  146. package/dist/workflow/components/useActivityForm/types.d.ts.map +0 -1
  147. package/dist/workflow/components/useActivityForm/useActivityForm.d.ts.map +0 -1
  148. package/docs/useTable.md +0 -369
  149. package/sdk/workflow/components/useActivityForm/createActivityItemProxy.ts +0 -130
  150. package/sdk/workflow/components/useActivityForm/createActivityResolver.ts +0 -61
  151. package/sdk/workflow/components/useActivityForm/useActivityForm.ts +0 -386
  152. /package/dist/{workflow/components → components/hooks}/useActivityForm/index.d.ts +0 -0
  153. /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
  154. /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
  155. /package/sdk/{workflow/components → components/hooks}/useActivityForm/index.ts +0 -0
  156. /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
  157. /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
package/dist/form.mjs CHANGED
@@ -1,258 +1,196 @@
1
- import { F as le, I as oe, V as ce } from "./constants-ConHc1oS.js";
2
- import { useMemo as z, useEffect as E, useRef as B, useCallback as j } from "react";
3
- import { u as G } from "./index.esm-Cj63v5ny.js";
4
- import { useQuery as A } from "@tanstack/react-query";
5
- import { a as T } from "./client-iQTqFDNI.js";
6
- import { v as L, e as J } from "./attachment-constants-C2UHWxmp.js";
7
- import { g as W } from "./metadata-DpfI3zRN.js";
8
- function K(o, t) {
9
- const i = [];
10
- if (o.required && (t == null || t === "" || Array.isArray(t) && t.length === 0))
11
- return i.push(`${o.label} is required`), { valid: !1, errors: i };
12
- if (t == null || t === "")
13
- return { valid: !0, errors: [] };
14
- if ("length" in o && typeof o.length == "number" && typeof t == "string" && t.length > o.length && i.push(`${o.label} must be at most ${o.length} characters`), "integerPart" in o && typeof t == "number") {
15
- const g = Math.floor(Math.abs(t)), w = o.integerPart ?? 9;
16
- g.toString().length > w && i.push(`${o.label} integer part must be at most ${w} digits`);
17
- const f = o.fractionPart;
18
- f !== void 0 && (t.toString().split(".")[1] ?? "").length > f && i.push(`${o.label} can have at most ${f} decimal places`);
19
- }
20
- return i.length > 0 ? { valid: !1, errors: i } : { valid: !0, errors: [] };
21
- }
22
- function Q(o, t) {
23
- return async (i, g, w) => {
24
- var I;
25
- const f = {}, S = o.getFields(), q = (w == null ? void 0 : w.names) ?? Object.keys(S);
26
- for (const e of q) {
27
- if (e === "_id" || (I = S[e]) != null && I.readOnly) continue;
28
- const r = S[e];
29
- if (!r) continue;
30
- let l = i[e];
31
- if ("integerPart" in r && typeof l == "string" && l !== "") {
32
- const b = Number(l);
33
- isNaN(b) || (l = b, i[e] = b);
34
- }
35
- if (!r.required && (l == null || l === "" || Array.isArray(l) && l.length === 0))
36
- continue;
37
- const P = r.validate(l);
38
- if (!P.valid && P.errors.length > 0) {
39
- f[e] = {
40
- type: "validate",
41
- message: P.errors[0] || `${e} is invalid`
42
- };
43
- continue;
44
- }
45
- if ((t == null ? void 0 : t.enableConstraintValidation) !== !1) {
46
- const b = K(r, l);
47
- if (!b.valid && b.errors.length > 0) {
48
- f[e] = {
49
- type: "constraint",
50
- message: b.errors[0]
51
- };
52
- continue;
53
- }
54
- }
55
- if (o.hasMetadata()) {
56
- const b = o.validateFieldExpression(
57
- e,
58
- l,
59
- i
60
- );
61
- !b.valid && b.errors.length > 0 && (f[e] = {
62
- type: "validate",
63
- message: b.errors[0]
64
- });
65
- }
66
- }
67
- return Object.keys(f).length === 0 ? { values: i, errors: {} } : { values: {}, errors: f };
68
- };
69
- }
70
- function H(o, t) {
71
- const i = o.getFields(), g = /* @__PURE__ */ new Map(), w = o.getBoId();
72
- let f = null, S = null;
73
- async function q() {
74
- const I = t.getValues("_id");
75
- return I || f || (S || (S = T(w).draftInteraction({}).then((e) => (f = e._id, t.setValue("_id", f, { shouldDirty: !1 }), f)).catch((e) => {
76
- throw S = null, e;
77
- })), S);
1
+ import { F as he, I as _e, V as we } from "./constants-ConHc1oS.js";
2
+ import { useMemo as b, useEffect as k, useRef as j, useCallback as K } from "react";
3
+ import { v as Z, c as p, a as ee, u as te, b as ae, d as ne, e as se, f as $ } from "./shared-5a7UkED1.js";
4
+ import { useQuery as J } from "@tanstack/react-query";
5
+ import { a as y } from "./client-_ayziI1d.js";
6
+ import { v as G, e as Q } from "./attachment-constants-C2UHWxmp.js";
7
+ import { g as ie } from "./metadata-Cc1mBcLS.js";
8
+ function re(D, a) {
9
+ const g = D.getFields(), T = /* @__PURE__ */ new Map(), C = D.getBoId();
10
+ let m = null, x = null;
11
+ async function R() {
12
+ const F = a.getValues("_id");
13
+ return F || m || (x || (x = y(C).draftInteraction({}).then((e) => (m = e._id, a.setValue("_id", m, { shouldDirty: !1 }), m)).catch((e) => {
14
+ throw x = null, e;
15
+ })), x);
78
16
  }
79
17
  return new Proxy({}, {
80
- get(I, e) {
18
+ get(F, e) {
81
19
  if (typeof e == "symbol")
82
20
  return;
83
21
  if (e === "_id")
84
- return t.getValues("_id");
22
+ return a.getValues("_id");
85
23
  if (e === "toJSON")
86
- return () => t.getValues();
24
+ return () => a.getValues();
87
25
  if (e === "validate")
88
- return () => t.trigger();
26
+ return () => a.trigger();
89
27
  if (e === "_hasDraft")
90
- return () => !!f;
91
- if (g.has(e))
92
- return g.get(e);
93
- const r = i[e], l = (r == null ? void 0 : r.meta) ?? {
28
+ return () => !!m;
29
+ if (T.has(e))
30
+ return T.get(e);
31
+ const s = g[e], c = (s == null ? void 0 : s.meta) ?? {
94
32
  _id: e,
95
33
  Name: e,
96
34
  Type: "String"
97
- }, P = (r == null ? void 0 : r.readOnly) ?? !1, b = () => {
98
- if (!r) return { valid: !0, errors: [] };
99
- let u = t.getValues(e);
100
- if ("integerPart" in r && typeof u == "string" && u !== "") {
101
- const d = Number(u);
102
- isNaN(d) || (u = d, t.setValue(e, d, { shouldDirty: !1 }));
35
+ }, A = (s == null ? void 0 : s.readOnly) ?? !1, B = () => {
36
+ if (!s) return { valid: !0, errors: [] };
37
+ let l = a.getValues(e);
38
+ if ("integerPart" in s && typeof l == "string" && l !== "") {
39
+ const o = Number(l);
40
+ isNaN(o) || (l = o, a.setValue(e, o, { shouldDirty: !1 }));
103
41
  }
104
- if (!r.required && (u == null || u === "" || Array.isArray(u) && u.length === 0))
42
+ if (!s.required && (l == null || l === "" || Array.isArray(l) && l.length === 0))
105
43
  return { valid: !0, errors: [] };
106
- const s = r.validate(u);
107
- if (!s.valid) return s;
108
- const n = K(r, u);
109
- if (!n.valid) return n;
110
- if (o.hasMetadata()) {
111
- const d = o.validateFieldExpression(
44
+ const i = s.validate(l);
45
+ if (!i.valid) return i;
46
+ const t = Z(s, l);
47
+ if (!t.valid) return t;
48
+ if (D.hasMetadata()) {
49
+ const o = D.validateFieldExpression(
112
50
  e,
113
- u,
114
- t.getValues()
51
+ l,
52
+ a.getValues()
115
53
  );
116
- if (!d.valid) return d;
54
+ if (!o.valid) return o;
117
55
  }
118
56
  return { valid: !0, errors: [] };
119
- }, M = (u) => {
120
- const s = t.getValues(e);
121
- return s ?? u;
57
+ }, E = (l) => {
58
+ const i = a.getValues(e);
59
+ return i ?? l;
122
60
  };
123
- if (!P) {
124
- const u = () => {
125
- const n = t.getValues(e);
126
- return l.Type === "File" ? n ?? [] : n;
127
- }, s = {
128
- label: (r == null ? void 0 : r.label) ?? e,
129
- required: (r == null ? void 0 : r.required) ?? !1,
61
+ if (!A) {
62
+ const l = () => {
63
+ const t = a.getValues(e);
64
+ return c.Type === "File" ? t ?? [] : t;
65
+ }, i = {
66
+ label: (s == null ? void 0 : s.label) ?? e,
67
+ required: (s == null ? void 0 : s.required) ?? !1,
130
68
  readOnly: !1,
131
- defaultValue: r == null ? void 0 : r.defaultValue,
132
- meta: l,
133
- get: u,
134
- getOrDefault: M,
135
- set: (n) => {
136
- t.setValue(e, n, {
69
+ defaultValue: s == null ? void 0 : s.defaultValue,
70
+ meta: c,
71
+ get: l,
72
+ getOrDefault: E,
73
+ set: (t) => {
74
+ a.setValue(e, t, {
137
75
  shouldDirty: !0,
138
76
  shouldTouch: !0,
139
77
  shouldValidate: !1
140
78
  // Let mode control validation timing
141
79
  });
142
80
  },
143
- validate: b
81
+ validate: B
144
82
  };
145
- if (l.Type === "Image" || l.Type === "File") {
146
- const n = w, d = () => {
147
- const a = t.getValues("_id");
148
- if (!a) throw new Error("Save the record before attachment operations");
149
- return a;
83
+ if (c.Type === "Image" || c.Type === "File") {
84
+ const t = C, o = () => {
85
+ const n = a.getValues("_id");
86
+ if (!n) throw new Error("Save the record before attachment operations");
87
+ return n;
150
88
  };
151
- l.Type === "Image" ? (s.upload = async (a) => {
152
- L(a.name, "Image");
153
- const c = await q(), [h] = await T(n).getUploadUrl(c, e, [
154
- { FileName: a.name, Size: a.size, FileExtension: J(a.name) }
89
+ c.Type === "Image" ? (i.upload = async (n) => {
90
+ G(n.name, "Image");
91
+ const r = await R(), [u] = await y(t).getUploadUrl(r, e, [
92
+ { FileName: n.name, Size: n.size, FileExtension: Q(n.name) }
155
93
  ]);
156
- await fetch(h.UploadUrl.URL, {
94
+ await fetch(u.UploadUrl.URL, {
157
95
  method: "PUT",
158
- headers: { "Content-Type": h.ContentType },
159
- body: a
96
+ headers: { "Content-Type": u.ContentType },
97
+ body: n
160
98
  });
161
- const m = {
162
- _id: h._id,
163
- _name: h._name,
164
- FileName: h.FileName,
165
- FileExtension: h.FileExtension,
166
- Size: h.Size,
167
- ContentType: h.ContentType
99
+ const f = {
100
+ _id: u._id,
101
+ _name: u._name,
102
+ FileName: u.FileName,
103
+ FileExtension: u.FileExtension,
104
+ Size: u.Size,
105
+ ContentType: u.ContentType
168
106
  };
169
- return t.setValue(e, m, { shouldDirty: !0 }), m;
170
- }, s.deleteAttachment = async () => {
171
- const a = t.getValues(e), c = d();
172
- if (!(a != null && a._id)) throw new Error(`${e} has no image to delete`);
173
- await T(n).deleteAttachment(c, e, a._id), t.setValue(e, null, { shouldDirty: !0 });
174
- }, s.getDownloadUrl = async (a) => {
175
- const c = t.getValues(e), h = d();
176
- if (!(c != null && c._id)) throw new Error(`${e} has no image`);
177
- return T(n).getDownloadUrl(h, e, c._id, a);
178
- }) : (s.upload = async (a) => {
179
- for (const V of a) L(V.name, "File");
180
- const c = await q(), h = a.map((V) => ({
181
- FileName: V.name,
182
- Size: V.size,
183
- FileExtension: J(V.name)
184
- })), m = await T(n).getUploadUrl(c, e, h), $ = await Promise.all(
185
- a.map(async (V, _) => (await fetch(m[_].UploadUrl.URL, {
107
+ return a.setValue(e, f, { shouldDirty: !0 }), f;
108
+ }, i.deleteAttachment = async () => {
109
+ const n = a.getValues(e), r = o();
110
+ if (!(n != null && n._id)) throw new Error(`${e} has no image to delete`);
111
+ await y(t).deleteAttachment(r, e, n._id), a.setValue(e, null, { shouldDirty: !0 });
112
+ }, i.getDownloadUrl = async (n) => {
113
+ const r = a.getValues(e), u = o();
114
+ if (!(r != null && r._id)) throw new Error(`${e} has no image`);
115
+ return y(t).getDownloadUrl(u, e, r._id, n);
116
+ }) : (i.upload = async (n) => {
117
+ for (const _ of n) G(_.name, "File");
118
+ const r = await R(), u = n.map((_) => ({
119
+ FileName: _.name,
120
+ Size: _.size,
121
+ FileExtension: Q(_.name)
122
+ })), f = await y(t).getUploadUrl(r, e, u), N = await Promise.all(
123
+ n.map(async (_, h) => (await fetch(f[h].UploadUrl.URL, {
186
124
  method: "PUT",
187
- headers: { "Content-Type": m[_].ContentType },
188
- body: V
125
+ headers: { "Content-Type": f[h].ContentType },
126
+ body: _
189
127
  }), {
190
- _id: m[_]._id,
191
- _name: m[_]._name,
192
- FileName: m[_].FileName,
193
- FileExtension: m[_].FileExtension,
194
- Size: m[_].Size,
195
- ContentType: m[_].ContentType
128
+ _id: f[h]._id,
129
+ _name: f[h]._name,
130
+ FileName: f[h].FileName,
131
+ FileExtension: f[h].FileExtension,
132
+ Size: f[h].Size,
133
+ ContentType: f[h].ContentType
196
134
  }))
197
- ), D = t.getValues(e) ?? [];
198
- return t.setValue(e, [...D, ...$], { shouldDirty: !0 }), $;
199
- }, s.deleteAttachment = async (a) => {
200
- const c = t.getValues(e) ?? [], h = d();
201
- await T(n).deleteAttachment(h, e, a), t.setValue(
135
+ ), O = a.getValues(e) ?? [];
136
+ return a.setValue(e, [...O, ...N], { shouldDirty: !0 }), N;
137
+ }, i.deleteAttachment = async (n) => {
138
+ const r = a.getValues(e) ?? [], u = o();
139
+ await y(t).deleteAttachment(u, e, n), a.setValue(
202
140
  e,
203
- c.filter((m) => m._id !== a),
141
+ r.filter((f) => f._id !== n),
204
142
  { shouldDirty: !0 }
205
143
  );
206
- }, s.getDownloadUrl = async (a, c) => {
207
- const h = d();
208
- return T(n).getDownloadUrl(h, e, a, c);
209
- }, s.getDownloadUrls = async (a) => {
210
- const c = d();
211
- return T(n).getDownloadUrls(c, e, a);
144
+ }, i.getDownloadUrl = async (n, r) => {
145
+ const u = o();
146
+ return y(t).getDownloadUrl(u, e, n, r);
147
+ }, i.getDownloadUrls = async (n) => {
148
+ const r = o();
149
+ return y(t).getDownloadUrls(r, e, n);
212
150
  });
213
151
  }
214
- return g.set(e, s), s;
152
+ return T.set(e, i), i;
215
153
  }
216
- const y = () => {
217
- const u = t.getValues(e);
218
- return l.Type === "File" ? u ?? [] : u;
219
- }, U = {
220
- label: (r == null ? void 0 : r.label) ?? e,
221
- required: (r == null ? void 0 : r.required) ?? !1,
154
+ const d = () => {
155
+ const l = a.getValues(e);
156
+ return c.Type === "File" ? l ?? [] : l;
157
+ }, I = {
158
+ label: (s == null ? void 0 : s.label) ?? e,
159
+ required: (s == null ? void 0 : s.required) ?? !1,
222
160
  readOnly: !0,
223
- defaultValue: r == null ? void 0 : r.defaultValue,
224
- meta: l,
225
- get: y,
226
- getOrDefault: M,
227
- validate: b
161
+ defaultValue: s == null ? void 0 : s.defaultValue,
162
+ meta: c,
163
+ get: d,
164
+ getOrDefault: E,
165
+ validate: B
228
166
  };
229
- if (l.Type === "Image" || l.Type === "File") {
230
- const u = w, s = () => {
231
- const n = t.getValues("_id");
232
- if (!n) throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");
233
- return n;
167
+ if (c.Type === "Image" || c.Type === "File") {
168
+ const l = C, i = () => {
169
+ const t = a.getValues("_id");
170
+ if (!t) throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");
171
+ return t;
234
172
  };
235
- l.Type === "Image" ? U.getDownloadUrl = async (n) => {
236
- const d = t.getValues(e), a = s();
237
- if (!(d != null && d._id)) throw new Error(`${e} has no image to download`);
238
- return T(u).getDownloadUrl(a, e, d._id, n);
239
- } : (U.getDownloadUrl = async (n, d) => {
240
- const a = s();
241
- return T(u).getDownloadUrl(a, e, n, d);
242
- }, U.getDownloadUrls = async (n) => {
243
- const d = s();
244
- return T(u).getDownloadUrls(d, e, n);
173
+ c.Type === "Image" ? I.getDownloadUrl = async (t) => {
174
+ const o = a.getValues(e), n = i();
175
+ if (!(o != null && o._id)) throw new Error(`${e} has no image to download`);
176
+ return y(l).getDownloadUrl(n, e, o._id, t);
177
+ } : (I.getDownloadUrl = async (t, o) => {
178
+ const n = i();
179
+ return y(l).getDownloadUrl(n, e, t, o);
180
+ }, I.getDownloadUrls = async (t) => {
181
+ const o = i();
182
+ return y(l).getDownloadUrls(o, e, t);
245
183
  });
246
184
  }
247
- return g.set(e, U), U;
185
+ return T.set(e, I), I;
248
186
  },
249
- has(I, e) {
250
- return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in i;
187
+ has(F, e) {
188
+ return typeof e == "symbol" ? !1 : e === "_id" || e === "toJSON" || e === "validate" || e === "_hasDraft" ? !0 : e in g;
251
189
  },
252
- ownKeys(I) {
253
- return [...Object.keys(i), "_id", "toJSON", "validate"];
190
+ ownKeys(F) {
191
+ return [...Object.keys(g), "_id", "toJSON", "validate"];
254
192
  },
255
- getOwnPropertyDescriptor(I, e) {
193
+ getOwnPropertyDescriptor(F, e) {
256
194
  if (typeof e != "symbol")
257
195
  return {
258
196
  configurable: !0,
@@ -261,175 +199,172 @@ function H(o, t) {
261
199
  }
262
200
  });
263
201
  }
264
- function k(o, t) {
265
- const i = o.meta.Type;
266
- if (typeof t == "string" && i === "Number")
267
- return t === "" ? void 0 : Number(t);
268
- if (!(typeof t == "string" && t === "" && (i === "Date" || i === "DateTime"))) {
269
- if (typeof t == "string" && t !== "" && i === "DateTime") {
270
- let g = t;
271
- return g.endsWith("Z") && (g = g.slice(0, -1)), ((g.split("T")[1] || "").match(/:/g) || []).length === 1 && (g += ":00"), g + "Z";
272
- }
273
- return t;
274
- }
275
- }
276
- function X(o, t) {
277
- var w;
278
- const i = o.getFields(), g = { ...t };
279
- for (const [f, S] of Object.entries(g))
280
- typeof S == "string" && ((w = i[f]) == null ? void 0 : w.meta.Type) === "DateTime" && S.endsWith("Z") && (g[f] = S.slice(0, -1));
281
- return g;
282
- }
283
- function ae(o) {
202
+ function ye(D) {
284
203
  const {
285
- bdo: t,
286
- recordId: i,
287
- operation: g,
288
- defaultValues: w,
289
- mode: f = "onBlur",
290
- enableDraft: S = !1,
291
- enableConstraintValidation: q,
292
- enableExpressionValidation: I
293
- } = o, e = g ?? (i ? "update" : "create"), r = z(
294
- () => Q(t, { enableConstraintValidation: q }),
295
- [t, q]
204
+ bdo: a,
205
+ recordId: g,
206
+ operation: T,
207
+ defaultValues: C,
208
+ mode: m = "onBlur",
209
+ enableDraft: x = !1,
210
+ enableConstraintValidation: R,
211
+ enableExpressionValidation: F
212
+ } = D, e = T ?? (g ? "update" : "create"), s = b(
213
+ () => p(a, { enableConstraintValidation: R }),
214
+ [a, R]
296
215
  ), {
297
- data: l,
298
- isLoading: P,
299
- isFetching: b,
300
- error: M
301
- } = A({
302
- queryKey: ["form-record", t.meta._id, i],
216
+ data: c,
217
+ isLoading: A,
218
+ isFetching: B,
219
+ error: E
220
+ } = J({
221
+ queryKey: ["form-record", a.meta._id, g],
303
222
  queryFn: async () => {
304
- const D = await t.get(i);
305
- return X(t, D.toJSON());
223
+ const w = await a.get(g);
224
+ return ee(a.getFields(), w.toJSON());
306
225
  },
307
- enabled: e === "update" && !!i,
226
+ enabled: e === "update" && !!g,
308
227
  staleTime: 0
309
228
  }), {
310
- data: y,
311
- isLoading: U,
312
- error: u
313
- } = A({
314
- queryKey: ["form-draft", t.meta._id],
315
- queryFn: async () => T(t.meta._id).draftInteraction({}),
229
+ data: d,
230
+ isLoading: I,
231
+ error: l
232
+ } = J({
233
+ queryKey: ["form-draft", a.meta._id],
234
+ queryFn: async () => y(a.meta._id).draftInteraction({}),
316
235
  enabled: e === "create",
317
236
  staleTime: 1 / 0,
318
237
  gcTime: 0,
319
238
  retry: 1
320
- }), { data: s } = A({
321
- queryKey: ["form-schema", t.meta._id],
322
- queryFn: () => W(t.meta._id),
239
+ }), { data: i } = J({
240
+ queryKey: ["form-schema", a.meta._id],
241
+ queryFn: () => ie(a.meta._id),
323
242
  staleTime: 30 * 60 * 1e3,
324
243
  gcTime: 60 * 60 * 1e3,
325
- enabled: I !== !1
244
+ enabled: F !== !1
326
245
  });
327
- E(() => {
328
- s != null && s.BDOBlob ? t.loadMetadata(s.BDOBlob) : s != null && s.MetaBlob && t.loadMetadata(s.MetaBlob);
329
- }, [s, t]);
330
- const n = G({
331
- mode: f,
332
- resolver: r,
333
- defaultValues: w
246
+ k(() => {
247
+ i != null && i.BDOBlob ? a.loadMetadata(i.BDOBlob) : i != null && i.MetaBlob && a.loadMetadata(i.MetaBlob);
248
+ }, [i, a]);
249
+ const t = te({
250
+ mode: m,
251
+ resolver: s,
252
+ defaultValues: C
334
253
  // NOTE: Don't use `values` prop — it continuously syncs and overrides
335
254
  // setValue() calls for unregistered fields (Image/File attachments).
336
255
  // Instead, we reset once when record arrives (see useEffect below).
337
- }), d = B(null);
338
- E(() => {
339
- e === "update" && l && l !== d.current && (n.reset(l), d.current = l);
340
- }, [l, e, n]), E(() => {
341
- y != null && y._id && n.setValue("_id", y._id);
342
- }, [y, n]);
343
- const a = z(
344
- () => H(t, n),
345
- [t, n]
346
- ), c = t.getFields(), h = j(
347
- (D, V) => {
348
- var F;
349
- const _ = n.register(D, V);
350
- return (F = c[D]) != null && F.readOnly ? { ..._, disabled: !0 } : _;
256
+ }), o = j(null);
257
+ k(() => {
258
+ e === "update" && c && c !== o.current && (t.reset(c), o.current = c);
259
+ }, [c, e, t]), k(() => {
260
+ d != null && d._id && t.setValue("_id", d._id);
261
+ }, [d, t]);
262
+ const n = b(
263
+ () => re(a, t),
264
+ [a, t]
265
+ ), r = a.getFields(), u = j(!1), f = b(
266
+ () => Object.keys(r).filter((w) => r[w].readOnly),
267
+ [r]
268
+ ), N = K(
269
+ async (w, V) => {
270
+ if (e === "create" && (d != null && d._id))
271
+ return y(a.meta._id).draftInteraction({
272
+ _id: d._id,
273
+ [w]: V
274
+ });
275
+ if (e === "update" && g)
276
+ return y(a.meta._id).update(g, {
277
+ [w]: V
278
+ });
351
279
  },
352
- [n, c]
353
- ), m = B(null);
354
- E(() => {
355
- if (e !== "create" || !(y != null && y._id)) return;
356
- const D = n.watch((V, { type: _ }) => {
357
- _ === "change" && (m.current && clearTimeout(m.current), m.current = setTimeout(async () => {
358
- const F = n.getValues(), v = n.formState.dirtyFields, x = {};
359
- for (const [O, N] of Object.entries(F))
360
- c[O] && !c[O].readOnly && v[O] && (x[O] = k(c[O], N));
361
- if (Object.keys(x).length > 0)
362
- try {
363
- await T(t.meta._id).draftInteraction({ _id: y._id, ...x });
364
- } catch {
365
- }
366
- }, 800));
367
- });
368
- return () => {
369
- D.unsubscribe(), m.current && clearTimeout(m.current);
370
- };
371
- }, [n, e, y, c, t]);
372
- const $ = j(
373
- (D, V) => n.handleSubmit(
374
- async (_, F) => {
280
+ [e, d, g, a]
281
+ ), O = b(
282
+ () => ae({
283
+ apiFn: N,
284
+ allFields: r,
285
+ readonlyFieldNames: f,
286
+ rhf: t,
287
+ isComputingRef: u
288
+ }),
289
+ [N, r, f, t]
290
+ ), _ = m === "onChange" || m === "all", h = m === "onBlur" || m === "onTouched" || m === "all", H = b(
291
+ () => ne({
292
+ rhf: t,
293
+ allFields: r,
294
+ syncField: O,
295
+ syncOnBlur: h,
296
+ syncOnChange: _
297
+ }),
298
+ [t, r, O, h, _]
299
+ ), W = b(
300
+ () => se({
301
+ control: t.control,
302
+ syncField: O,
303
+ syncOnBlur: h,
304
+ syncOnChange: _
305
+ }),
306
+ [t.control, O, h, _]
307
+ ), X = K(
308
+ (w, V) => t.handleSubmit(
309
+ async (M, z) => {
375
310
  try {
376
- const v = {}, x = n.getValues();
311
+ const v = {}, P = t.getValues();
377
312
  if (e === "create")
378
- for (const [N, R] of Object.entries(c)) {
379
- if (R.readOnly) continue;
380
- const C = x[N] !== void 0 ? x[N] : _[N];
381
- C !== void 0 && (v[N] = k(R, C));
313
+ for (const [U, S] of Object.entries(r)) {
314
+ if (S.readOnly) continue;
315
+ const q = P[U] !== void 0 ? P[U] : M[U];
316
+ q !== void 0 && (v[U] = $(S, q));
382
317
  }
383
318
  else {
384
- const N = n.formState.dirtyFields;
385
- for (const [R, C] of Object.entries(c)) {
386
- if (C.readOnly || !N[R]) continue;
387
- const Z = x[R] !== void 0 ? x[R] : _[R];
388
- v[R] = k(C, Z);
319
+ const U = t.formState.dirtyFields;
320
+ for (const [S, q] of Object.entries(r)) {
321
+ if (q.readOnly || !U[S]) continue;
322
+ const Y = P[S] !== void 0 ? P[S] : M[S];
323
+ v[S] = $(q, Y);
389
324
  }
390
325
  }
391
- let O;
392
- e === "create" ? (v._id = y == null ? void 0 : y._id, O = await T(t.meta._id).draft(v)) : O = await T(t.meta._id).update(i, v), D == null || D(O, F);
326
+ let L;
327
+ e === "create" ? (v._id = d == null ? void 0 : d._id, L = await y(a.meta._id).draft(v)) : L = await y(a.meta._id).update(g, v), w == null || w(L, z);
393
328
  } catch (v) {
394
- V == null || V(v, F);
329
+ V == null || V(v, z);
395
330
  }
396
331
  },
397
- (_, F) => {
398
- V == null || V(_, F);
332
+ (M, z) => {
333
+ V == null || V(M, z);
399
334
  }
400
335
  ),
401
- [n, t, e, i, c, y]
336
+ [t, a, e, g, r, d]
402
337
  );
403
338
  return {
404
- item: a,
405
- bdo: t,
339
+ item: n,
340
+ bdo: a,
406
341
  operation: e,
407
- recordId: i,
408
- register: h,
409
- handleSubmit: $,
410
- watch: n.watch,
411
- setValue: n.setValue,
412
- getValues: n.getValues,
413
- reset: n.reset,
414
- trigger: n.trigger,
415
- control: n.control,
416
- formState: n.formState,
417
- errors: n.formState.errors,
418
- isDirty: n.formState.isDirty,
419
- isValid: n.formState.isValid,
420
- isSubmitting: n.formState.isSubmitting,
421
- isSubmitSuccessful: n.formState.isSubmitSuccessful,
422
- dirtyFields: n.formState.dirtyFields,
423
- isLoading: P || U,
424
- isFetching: b,
425
- loadError: M ?? u,
426
- draftId: y == null ? void 0 : y._id,
427
- isCreatingDraft: U
342
+ recordId: g,
343
+ register: H,
344
+ handleSubmit: X,
345
+ watch: t.watch,
346
+ setValue: t.setValue,
347
+ getValues: t.getValues,
348
+ reset: t.reset,
349
+ trigger: t.trigger,
350
+ control: W,
351
+ formState: t.formState,
352
+ errors: t.formState.errors,
353
+ isDirty: t.formState.isDirty,
354
+ isValid: t.formState.isValid,
355
+ isSubmitting: t.formState.isSubmitting,
356
+ isSubmitSuccessful: t.formState.isSubmitSuccessful,
357
+ dirtyFields: t.formState.dirtyFields,
358
+ isLoading: A || I,
359
+ isFetching: B,
360
+ loadError: E ?? l,
361
+ draftId: d == null ? void 0 : d._id,
362
+ isCreatingDraft: I
428
363
  };
429
364
  }
430
365
  export {
431
- le as FormOperation,
432
- oe as InteractionMode,
433
- ce as ValidationMode,
434
- ae as useForm
366
+ he as FormOperation,
367
+ _e as InteractionMode,
368
+ we as ValidationMode,
369
+ ye as useBDOForm
435
370
  };