@ram_28/kf-ai-sdk 2.0.11 → 2.0.12
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useForm/useForm.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAKlB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACtD,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B,iBAAiB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useForm/useForm.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAKlB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACtD,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B,iBAAiB,CAAC,CAAC,CAAC,CAoNtB"}
|
package/dist/form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("./constants-QX2RX-wu.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("./constants-QX2RX-wu.cjs"),q=require("react"),T=require("./index.esm-DuwT11sx.cjs"),w=require("@tanstack/react-query"),j=require("./metadata-BfJtHz84.cjs");function P(s,e){const r=[];if(s.required&&(e==null||e===""||Array.isArray(e)&&e.length===0))return r.push(`${s.label} is required`),{valid:!1,errors:r};if(e==null||e==="")return{valid:!0,errors:[]};if("length"in s&&typeof s.length=="number"&&typeof e=="string"&&e.length>s.length&&r.push(`${s.label} must be at most ${s.length} characters`),"integerPart"in s&&typeof e=="number"){const d=Math.floor(Math.abs(e)),c=s.integerPart??9;d.toString().length>c&&r.push(`${s.label} integer part must be at most ${c} digits`);const t=s.fractionPart;t!==void 0&&(e.toString().split(".")[1]??"").length>t&&r.push(`${s.label} can have at most ${t} decimal places`)}return r.length>0?{valid:!1,errors:r}:{valid:!0,errors:[]}}function C(s,e){return async(r,d,c)=>{var v;const t={},a=s.getFields(),m=(c==null?void 0:c.names)??Object.keys(a);for(const n of m){if(n==="_id"||(v=a[n])!=null&&v.readOnly)continue;const g=a[n];if(!g)continue;const f=r[n],u=g.validate(f);if(!u.valid&&u.errors.length>0){t[n]={type:"validate",message:u.errors[0]||`${n} is invalid`};continue}if((e==null?void 0:e.enableConstraintValidation)!==!1){const l=P(g,f);if(!l.valid&&l.errors.length>0){t[n]={type:"constraint",message:l.errors[0]};continue}}if(s.hasMetadata()){const l=s.validateFieldExpression(n,f,r);!l.valid&&l.errors.length>0&&(t[n]={type:"validate",message:l.errors[0]})}}return Object.keys(t).length===0?{values:r,errors:{}}:{values:{},errors:t}}}function J(s,e){const r=s.getFields(),d=new Map;return new Proxy({},{get(c,t){if(typeof t=="symbol")return;if(t==="_id")return e.getValues("_id");if(t==="toJSON")return()=>e.getValues();if(t==="validate")return()=>e.trigger();if(d.has(t))return d.get(t);const a=r[t],m=(a==null?void 0:a.meta)??{_id:t,Name:t,Type:"String"},v=(a==null?void 0:a.readOnly)??!1,n=()=>{if(!a)return{valid:!0,errors:[]};const u=e.getValues(t),l=a.validate(u);if(!l.valid)return l;const R=P(a,u);if(!R.valid)return R;if(s.hasMetadata()){const o=s.validateFieldExpression(t,u,e.getValues());if(!o.valid)return o}return{valid:!0,errors:[]}},g=u=>{const l=e.getValues(t);return l??u};if(!v){const u={label:(a==null?void 0:a.label)??t,required:(a==null?void 0:a.required)??!1,readOnly:!1,defaultValue:a==null?void 0:a.defaultValue,meta:m,get:()=>e.getValues(t),getOrDefault:g,set:l=>{e.setValue(t,l,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:n};return d.set(t,u),u}const f={label:(a==null?void 0:a.label)??t,required:(a==null?void 0:a.required)??!1,readOnly:!0,defaultValue:a==null?void 0:a.defaultValue,meta:m,get:()=>e.getValues(t),getOrDefault:g,validate:n};return d.set(t,f),f},has(c,t){return typeof t=="symbol"?!1:t==="_id"||t==="toJSON"||t==="validate"?!0:t in r},ownKeys(c){return[...Object.keys(r),"_id","toJSON","validate"]},getOwnPropertyDescriptor(c,t){if(typeof t!="symbol")return{configurable:!0,enumerable:t!=="toJSON"&&t!=="validate"}}})}function F(s){const{bdo:e,recordId:r,operation:d,defaultValues:c,mode:t="onBlur",enableDraft:a=!1,enableConstraintValidation:m,enableExpressionValidation:v}=s,n=d??(r?"update":"create"),g=q.useMemo(()=>C(e,{enableConstraintValidation:m}),[e,m]),{data:f,isLoading:u,isFetching:l,error:R}=w.useQuery({queryKey:["form-record",e.meta._id,r],queryFn:async()=>(await e.get(r)).toJSON(),enabled:n==="update"&&!!r,staleTime:0}),{data:o}=w.useQuery({queryKey:["form-schema",e.meta._id],queryFn:()=>j.getBdoSchema(e.meta._id),staleTime:30*60*1e3,gcTime:60*60*1e3,enabled:v!==!1});q.useEffect(()=>{o!=null&&o.BDOBlob?e.loadMetadata(o.BDOBlob):o!=null&&o.MetaBlob&&e.loadMetadata(o.MetaBlob)},[o,e]);const i=T.useForm({mode:t,resolver:g,defaultValues:c,values:n==="update"&&f?f:void 0}),B=q.useMemo(()=>J(e,i),[e,i]),h=e.getFields(),$=q.useCallback((b,y)=>{var V;const S=i.register(b,y);return(V=h[b])!=null&&V.readOnly?{...S,disabled:!0}:S},[i,h]),k=q.useCallback((b,y)=>i.handleSubmit(async(S,V)=>{try{const O={};if(n==="create")for(const[_,M]of Object.entries(S))h[_]&&!h[_].readOnly&&(O[_]=M);else{const _=i.formState.dirtyFields;for(const[M,N]of Object.entries(S))h[M]&&!h[M].readOnly&&_[M]&&(O[M]=N)}let x;n==="create"?x=await e.create(O):x=await e.update(r,O),b==null||b(x,V)}catch(O){y==null||y(O,V)}},(S,V)=>{y==null||y(S,V)}),[i,e,n,r,h]);return{item:B,bdo:e,operation:n,recordId:r,register:$,handleSubmit:k,watch:i.watch,setValue:i.setValue,getValues:i.getValues,reset:i.reset,trigger:i.trigger,control:i.control,formState:i.formState,errors:i.formState.errors,isDirty:i.formState.isDirty,isValid:i.formState.isValid,isSubmitting:i.formState.isSubmitting,isSubmitSuccessful:i.formState.isSubmitSuccessful,dirtyFields:i.formState.dirtyFields,isLoading:u,isFetching:l,loadError:R}}exports.FormOperation=D.FormOperation;exports.InteractionMode=D.InteractionMode;exports.ValidationMode=D.ValidationMode;exports.useForm=F;
|
package/dist/form.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { F as H, I as U, V as W } from "./constants-ConHc1oS.js";
|
|
2
|
-
import { useMemo as
|
|
2
|
+
import { useMemo as D, useEffect as T, useCallback as q } from "react";
|
|
3
3
|
import { u as j } from "./index.esm-Cj63v5ny.js";
|
|
4
4
|
import { useQuery as w } from "@tanstack/react-query";
|
|
5
5
|
import { g as C } from "./metadata-CwAo6a8e.js";
|
|
@@ -10,22 +10,22 @@ function $(s, e) {
|
|
|
10
10
|
if (e == null || e === "")
|
|
11
11
|
return { valid: !0, errors: [] };
|
|
12
12
|
if ("length" in s && typeof s.length == "number" && typeof e == "string" && e.length > s.length && r.push(`${s.label} must be at most ${s.length} characters`), "integerPart" in s && typeof e == "number") {
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const f = Math.floor(Math.abs(e)), o = s.integerPart ?? 9;
|
|
14
|
+
f.toString().length > o && r.push(`${s.label} integer part must be at most ${o} digits`);
|
|
15
15
|
const t = s.fractionPart;
|
|
16
16
|
t !== void 0 && (e.toString().split(".")[1] ?? "").length > t && r.push(`${s.label} can have at most ${t} decimal places`);
|
|
17
17
|
}
|
|
18
18
|
return r.length > 0 ? { valid: !1, errors: r } : { valid: !0, errors: [] };
|
|
19
19
|
}
|
|
20
20
|
function J(s, e) {
|
|
21
|
-
return async (r,
|
|
22
|
-
var
|
|
23
|
-
const t = {}, a = s.getFields(), y = (
|
|
21
|
+
return async (r, f, o) => {
|
|
22
|
+
var S;
|
|
23
|
+
const t = {}, a = s.getFields(), y = (o == null ? void 0 : o.names) ?? Object.keys(a);
|
|
24
24
|
for (const n of y) {
|
|
25
|
-
if (n === "_id" || (
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
const
|
|
25
|
+
if (n === "_id" || (S = a[n]) != null && S.readOnly) continue;
|
|
26
|
+
const g = a[n];
|
|
27
|
+
if (!g) continue;
|
|
28
|
+
const d = r[n], u = g.validate(d);
|
|
29
29
|
if (!u.valid && u.errors.length > 0) {
|
|
30
30
|
t[n] = {
|
|
31
31
|
type: "validate",
|
|
@@ -34,7 +34,7 @@ function J(s, e) {
|
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
if ((e == null ? void 0 : e.enableConstraintValidation) !== !1) {
|
|
37
|
-
const l = $(
|
|
37
|
+
const l = $(g, d);
|
|
38
38
|
if (!l.valid && l.errors.length > 0) {
|
|
39
39
|
t[n] = {
|
|
40
40
|
type: "constraint",
|
|
@@ -46,7 +46,7 @@ function J(s, e) {
|
|
|
46
46
|
if (s.hasMetadata()) {
|
|
47
47
|
const l = s.validateFieldExpression(
|
|
48
48
|
n,
|
|
49
|
-
|
|
49
|
+
d,
|
|
50
50
|
r
|
|
51
51
|
);
|
|
52
52
|
!l.valid && l.errors.length > 0 && (t[n] = {
|
|
@@ -59,9 +59,9 @@ function J(s, e) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function I(s, e) {
|
|
62
|
-
const r = s.getFields(),
|
|
62
|
+
const r = s.getFields(), f = /* @__PURE__ */ new Map();
|
|
63
63
|
return new Proxy({}, {
|
|
64
|
-
get(
|
|
64
|
+
get(o, t) {
|
|
65
65
|
if (typeof t == "symbol")
|
|
66
66
|
return;
|
|
67
67
|
if (t === "_id")
|
|
@@ -70,32 +70,32 @@ function I(s, e) {
|
|
|
70
70
|
return () => e.getValues();
|
|
71
71
|
if (t === "validate")
|
|
72
72
|
return () => e.trigger();
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
73
|
+
if (f.has(t))
|
|
74
|
+
return f.get(t);
|
|
75
75
|
const a = r[t], y = (a == null ? void 0 : a.meta) ?? {
|
|
76
76
|
_id: t,
|
|
77
77
|
Name: t,
|
|
78
78
|
Type: "String"
|
|
79
|
-
},
|
|
79
|
+
}, S = (a == null ? void 0 : a.readOnly) ?? !1, n = () => {
|
|
80
80
|
if (!a) return { valid: !0, errors: [] };
|
|
81
81
|
const u = e.getValues(t), l = a.validate(u);
|
|
82
82
|
if (!l.valid) return l;
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
83
|
+
const x = $(a, u);
|
|
84
|
+
if (!x.valid) return x;
|
|
85
85
|
if (s.hasMetadata()) {
|
|
86
|
-
const
|
|
86
|
+
const c = s.validateFieldExpression(
|
|
87
87
|
t,
|
|
88
88
|
u,
|
|
89
89
|
e.getValues()
|
|
90
90
|
);
|
|
91
|
-
if (!
|
|
91
|
+
if (!c.valid) return c;
|
|
92
92
|
}
|
|
93
93
|
return { valid: !0, errors: [] };
|
|
94
|
-
},
|
|
94
|
+
}, g = (u) => {
|
|
95
95
|
const l = e.getValues(t);
|
|
96
96
|
return l ?? u;
|
|
97
97
|
};
|
|
98
|
-
if (!
|
|
98
|
+
if (!S) {
|
|
99
99
|
const u = {
|
|
100
100
|
label: (a == null ? void 0 : a.label) ?? t,
|
|
101
101
|
required: (a == null ? void 0 : a.required) ?? !1,
|
|
@@ -103,7 +103,7 @@ function I(s, e) {
|
|
|
103
103
|
defaultValue: a == null ? void 0 : a.defaultValue,
|
|
104
104
|
meta: y,
|
|
105
105
|
get: () => e.getValues(t),
|
|
106
|
-
getOrDefault:
|
|
106
|
+
getOrDefault: g,
|
|
107
107
|
set: (l) => {
|
|
108
108
|
e.setValue(t, l, {
|
|
109
109
|
shouldDirty: !0,
|
|
@@ -114,27 +114,27 @@ function I(s, e) {
|
|
|
114
114
|
},
|
|
115
115
|
validate: n
|
|
116
116
|
};
|
|
117
|
-
return
|
|
117
|
+
return f.set(t, u), u;
|
|
118
118
|
}
|
|
119
|
-
const
|
|
119
|
+
const d = {
|
|
120
120
|
label: (a == null ? void 0 : a.label) ?? t,
|
|
121
121
|
required: (a == null ? void 0 : a.required) ?? !1,
|
|
122
122
|
readOnly: !0,
|
|
123
123
|
defaultValue: a == null ? void 0 : a.defaultValue,
|
|
124
124
|
meta: y,
|
|
125
125
|
get: () => e.getValues(t),
|
|
126
|
-
getOrDefault:
|
|
126
|
+
getOrDefault: g,
|
|
127
127
|
validate: n
|
|
128
128
|
};
|
|
129
|
-
return
|
|
129
|
+
return f.set(t, d), d;
|
|
130
130
|
},
|
|
131
|
-
has(
|
|
131
|
+
has(o, t) {
|
|
132
132
|
return typeof t == "symbol" ? !1 : t === "_id" || t === "toJSON" || t === "validate" ? !0 : t in r;
|
|
133
133
|
},
|
|
134
|
-
ownKeys(
|
|
134
|
+
ownKeys(o) {
|
|
135
135
|
return [...Object.keys(r), "_id", "toJSON", "validate"];
|
|
136
136
|
},
|
|
137
|
-
getOwnPropertyDescriptor(
|
|
137
|
+
getOwnPropertyDescriptor(o, t) {
|
|
138
138
|
if (typeof t != "symbol")
|
|
139
139
|
return {
|
|
140
140
|
configurable: !0,
|
|
@@ -147,99 +147,99 @@ function Q(s) {
|
|
|
147
147
|
const {
|
|
148
148
|
bdo: e,
|
|
149
149
|
recordId: r,
|
|
150
|
-
operation:
|
|
151
|
-
defaultValues:
|
|
150
|
+
operation: f,
|
|
151
|
+
defaultValues: o,
|
|
152
152
|
mode: t = "onBlur",
|
|
153
153
|
enableDraft: a = !1,
|
|
154
154
|
enableConstraintValidation: y,
|
|
155
|
-
enableExpressionValidation:
|
|
156
|
-
} = s, n =
|
|
155
|
+
enableExpressionValidation: S
|
|
156
|
+
} = s, n = f ?? (r ? "update" : "create"), g = D(
|
|
157
157
|
() => J(e, { enableConstraintValidation: y }),
|
|
158
158
|
[e, y]
|
|
159
159
|
), {
|
|
160
|
-
data:
|
|
160
|
+
data: d,
|
|
161
161
|
isLoading: u,
|
|
162
162
|
isFetching: l,
|
|
163
|
-
error:
|
|
163
|
+
error: x
|
|
164
164
|
} = w({
|
|
165
165
|
queryKey: ["form-record", e.meta._id, r],
|
|
166
166
|
queryFn: async () => (await e.get(r)).toJSON(),
|
|
167
167
|
enabled: n === "update" && !!r,
|
|
168
168
|
staleTime: 0
|
|
169
169
|
// Always fetch fresh data for forms
|
|
170
|
-
}), { data:
|
|
170
|
+
}), { data: c } = w({
|
|
171
171
|
queryKey: ["form-schema", e.meta._id],
|
|
172
172
|
queryFn: () => C(e.meta._id),
|
|
173
173
|
staleTime: 30 * 60 * 1e3,
|
|
174
174
|
// Cache for 30 minutes
|
|
175
175
|
gcTime: 60 * 60 * 1e3,
|
|
176
176
|
// Keep in cache for 1 hour
|
|
177
|
-
enabled:
|
|
177
|
+
enabled: S !== !1
|
|
178
178
|
});
|
|
179
179
|
T(() => {
|
|
180
|
-
|
|
181
|
-
}, [
|
|
180
|
+
c != null && c.BDOBlob ? e.loadMetadata(c.BDOBlob) : c != null && c.MetaBlob && e.loadMetadata(c.MetaBlob);
|
|
181
|
+
}, [c, e]);
|
|
182
182
|
const i = j({
|
|
183
183
|
mode: t,
|
|
184
184
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
-
resolver:
|
|
185
|
+
resolver: g,
|
|
186
186
|
// Validation integrated here!
|
|
187
|
-
defaultValues:
|
|
187
|
+
defaultValues: o,
|
|
188
188
|
// `values` prop reactively updates form when record loads
|
|
189
|
-
values: n === "update" &&
|
|
190
|
-
}),
|
|
189
|
+
values: n === "update" && d ? d : void 0
|
|
190
|
+
}), B = D(
|
|
191
191
|
() => I(e, i),
|
|
192
192
|
[e, i]
|
|
193
|
-
), h = e.getFields(),
|
|
193
|
+
), h = e.getFields(), P = q(
|
|
194
194
|
(V, m) => {
|
|
195
|
-
var
|
|
196
|
-
const
|
|
197
|
-
return (
|
|
195
|
+
var v;
|
|
196
|
+
const b = i.register(V, m);
|
|
197
|
+
return (v = h[V]) != null && v.readOnly ? { ...b, disabled: !0 } : b;
|
|
198
198
|
},
|
|
199
199
|
[i, h]
|
|
200
|
-
),
|
|
200
|
+
), N = q(
|
|
201
201
|
(V, m) => i.handleSubmit(
|
|
202
202
|
// onValid - validation passed, make API call
|
|
203
|
-
async (
|
|
203
|
+
async (b, v) => {
|
|
204
204
|
try {
|
|
205
205
|
const O = {};
|
|
206
206
|
if (n === "create")
|
|
207
|
-
for (const [
|
|
208
|
-
h[
|
|
207
|
+
for (const [M, _] of Object.entries(b))
|
|
208
|
+
h[M] && !h[M].readOnly && (O[M] = _);
|
|
209
209
|
else {
|
|
210
|
-
const
|
|
211
|
-
for (const [_,
|
|
212
|
-
h[_] && !h[_].readOnly &&
|
|
210
|
+
const M = i.formState.dirtyFields;
|
|
211
|
+
for (const [_, k] of Object.entries(b))
|
|
212
|
+
h[_] && !h[_].readOnly && M[_] && (O[_] = k);
|
|
213
213
|
}
|
|
214
|
-
let
|
|
215
|
-
n === "create" ?
|
|
214
|
+
let R;
|
|
215
|
+
n === "create" ? R = await e.create(
|
|
216
216
|
O
|
|
217
|
-
) :
|
|
217
|
+
) : R = await e.update(
|
|
218
218
|
r,
|
|
219
219
|
O
|
|
220
|
-
), V == null || V(
|
|
220
|
+
), V == null || V(R, v);
|
|
221
221
|
} catch (O) {
|
|
222
|
-
m == null || m(O,
|
|
222
|
+
m == null || m(O, v);
|
|
223
223
|
}
|
|
224
224
|
},
|
|
225
225
|
// onInvalid - validation failed
|
|
226
|
-
(
|
|
227
|
-
m == null || m(
|
|
226
|
+
(b, v) => {
|
|
227
|
+
m == null || m(b, v);
|
|
228
228
|
}
|
|
229
229
|
),
|
|
230
230
|
[i, e, n, r, h]
|
|
231
231
|
);
|
|
232
232
|
return {
|
|
233
233
|
// Item - synced with form
|
|
234
|
-
item:
|
|
234
|
+
item: B,
|
|
235
235
|
// BDO reference
|
|
236
236
|
bdo: e,
|
|
237
237
|
operation: n,
|
|
238
238
|
recordId: r,
|
|
239
239
|
// Smart register (auto-disables readonly fields)
|
|
240
|
-
register:
|
|
240
|
+
register: P,
|
|
241
241
|
// Custom handleSubmit (handles API call + filters payload)
|
|
242
|
-
handleSubmit:
|
|
242
|
+
handleSubmit: N,
|
|
243
243
|
// RHF methods (spread, but handleSubmit is overridden above)
|
|
244
244
|
watch: i.watch,
|
|
245
245
|
setValue: i.setValue,
|
|
@@ -259,7 +259,7 @@ function Q(s) {
|
|
|
259
259
|
isLoading: u,
|
|
260
260
|
isFetching: l,
|
|
261
261
|
// Error
|
|
262
|
-
loadError:
|
|
262
|
+
loadError: x
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
265
|
export {
|
package/package.json
CHANGED