@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,CAkNtB"}
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"),M=require("react"),j=require("./index.esm-DuwT11sx.cjs"),w=require("@tanstack/react-query"),B=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 o=Math.floor(Math.abs(e)),c=s.integerPart??9;o.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,o,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 f=a[n];if(!f)continue;const d=r[n],u=f.validate(d);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(f,d);if(!l.valid&&l.errors.length>0){t[n]={type:"constraint",message:l.errors[0]};continue}}if(s.hasMetadata()){const l=s.validateFieldExpression(n,d,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(),o=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(o.has(t))return o.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 g=s.validateFieldExpression(t,u,e.getValues());if(!g.valid)return g}return{valid:!0,errors:[]}},f=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:f,set:l=>{e.setValue(t,l,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:n};return o.set(t,u),u}const d={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:f,validate:n};return o.set(t,d),d},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:o,defaultValues:c,mode:t="onBlur",enableDraft:a=!1,enableConstraintValidation:m,enableExpressionValidation:v}=s,n=o??(r?"update":"create"),f=M.useMemo(()=>C(e,{enableConstraintValidation:m}),[e,m]),{data:d,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:g}=w.useQuery({queryKey:["form-schema",e.meta._id],queryFn:()=>B.getBdoSchema(e.meta._id),staleTime:30*60*1e3,gcTime:60*60*1e3,enabled:v!==!1});M.useEffect(()=>{g!=null&&g.BDOBlob&&e.loadMetadata(g.BDOBlob)},[g,e]);const i=j.useForm({mode:t,resolver:f,defaultValues:c,values:n==="update"&&d?d:void 0}),$=M.useMemo(()=>J(e,i),[e,i]),h=e.getFields(),k=M.useCallback((S,y)=>{var b;const V=i.register(S,y);return(b=h[S])!=null&&b.readOnly?{...V,disabled:!0}:V},[i,h]),N=M.useCallback((S,y)=>i.handleSubmit(async(V,b)=>{try{const O={};if(n==="create")for(const[q,_]of Object.entries(V))h[q]&&!h[q].readOnly&&(O[q]=_);else{const q=i.formState.dirtyFields;for(const[_,T]of Object.entries(V))h[_]&&!h[_].readOnly&&q[_]&&(O[_]=T)}let x;n==="create"?x=await e.create(O):x=await e.update(r,O),S==null||S(x,b)}catch(O){y==null||y(O,b)}},(V,b)=>{y==null||y(V,b)}),[i,e,n,r,h]);return{item:$,bdo:e,operation:n,recordId:r,register:k,handleSubmit:N,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;
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 q, useEffect as T, useCallback as M } from "react";
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 o = Math.floor(Math.abs(e)), c = s.integerPart ?? 9;
14
- o.toString().length > c && r.push(`${s.label} integer part must be at most ${c} digits`);
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, o, c) => {
22
- var b;
23
- const t = {}, a = s.getFields(), y = (c == null ? void 0 : c.names) ?? Object.keys(a);
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" || (b = a[n]) != null && b.readOnly) continue;
26
- const d = a[n];
27
- if (!d) continue;
28
- const f = r[n], u = d.validate(f);
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 = $(d, f);
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
- f,
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(), o = /* @__PURE__ */ new Map();
62
+ const r = s.getFields(), f = /* @__PURE__ */ new Map();
63
63
  return new Proxy({}, {
64
- get(c, t) {
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 (o.has(t))
74
- return o.get(t);
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
- }, b = (a == null ? void 0 : a.readOnly) ?? !1, n = () => {
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 R = $(a, u);
84
- if (!R.valid) return R;
83
+ const x = $(a, u);
84
+ if (!x.valid) return x;
85
85
  if (s.hasMetadata()) {
86
- const g = s.validateFieldExpression(
86
+ const c = s.validateFieldExpression(
87
87
  t,
88
88
  u,
89
89
  e.getValues()
90
90
  );
91
- if (!g.valid) return g;
91
+ if (!c.valid) return c;
92
92
  }
93
93
  return { valid: !0, errors: [] };
94
- }, d = (u) => {
94
+ }, g = (u) => {
95
95
  const l = e.getValues(t);
96
96
  return l ?? u;
97
97
  };
98
- if (!b) {
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: d,
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 o.set(t, u), u;
117
+ return f.set(t, u), u;
118
118
  }
119
- const f = {
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: d,
126
+ getOrDefault: g,
127
127
  validate: n
128
128
  };
129
- return o.set(t, f), f;
129
+ return f.set(t, d), d;
130
130
  },
131
- has(c, t) {
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(c) {
134
+ ownKeys(o) {
135
135
  return [...Object.keys(r), "_id", "toJSON", "validate"];
136
136
  },
137
- getOwnPropertyDescriptor(c, t) {
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: o,
151
- defaultValues: c,
150
+ operation: f,
151
+ defaultValues: o,
152
152
  mode: t = "onBlur",
153
153
  enableDraft: a = !1,
154
154
  enableConstraintValidation: y,
155
- enableExpressionValidation: b
156
- } = s, n = o ?? (r ? "update" : "create"), d = q(
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: f,
160
+ data: d,
161
161
  isLoading: u,
162
162
  isFetching: l,
163
- error: R
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: g } = w({
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: b !== !1
177
+ enabled: S !== !1
178
178
  });
179
179
  T(() => {
180
- g != null && g.BDOBlob && e.loadMetadata(g.BDOBlob);
181
- }, [g, e]);
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: d,
185
+ resolver: g,
186
186
  // Validation integrated here!
187
- defaultValues: c,
187
+ defaultValues: o,
188
188
  // `values` prop reactively updates form when record loads
189
- values: n === "update" && f ? f : void 0
190
- }), P = q(
189
+ values: n === "update" && d ? d : void 0
190
+ }), B = D(
191
191
  () => I(e, i),
192
192
  [e, i]
193
- ), h = e.getFields(), N = M(
193
+ ), h = e.getFields(), P = q(
194
194
  (V, m) => {
195
- var S;
196
- const v = i.register(V, m);
197
- return (S = h[V]) != null && S.readOnly ? { ...v, disabled: !0 } : v;
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
- ), k = M(
200
+ ), N = q(
201
201
  (V, m) => i.handleSubmit(
202
202
  // onValid - validation passed, make API call
203
- async (v, S) => {
203
+ async (b, v) => {
204
204
  try {
205
205
  const O = {};
206
206
  if (n === "create")
207
- for (const [x, _] of Object.entries(v))
208
- h[x] && !h[x].readOnly && (O[x] = _);
207
+ for (const [M, _] of Object.entries(b))
208
+ h[M] && !h[M].readOnly && (O[M] = _);
209
209
  else {
210
- const x = i.formState.dirtyFields;
211
- for (const [_, B] of Object.entries(v))
212
- h[_] && !h[_].readOnly && x[_] && (O[_] = B);
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 D;
215
- n === "create" ? D = await e.create(
214
+ let R;
215
+ n === "create" ? R = await e.create(
216
216
  O
217
- ) : D = await e.update(
217
+ ) : R = await e.update(
218
218
  r,
219
219
  O
220
- ), V == null || V(D, S);
220
+ ), V == null || V(R, v);
221
221
  } catch (O) {
222
- m == null || m(O, S);
222
+ m == null || m(O, v);
223
223
  }
224
224
  },
225
225
  // onInvalid - validation failed
226
- (v, S) => {
227
- m == null || m(v, S);
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: P,
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: N,
240
+ register: P,
241
241
  // Custom handleSubmit (handles API call + filters payload)
242
- handleSubmit: k,
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: R
262
+ loadError: x
263
263
  };
264
264
  }
265
265
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ram_28/kf-ai-sdk",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "Type-safe, AI-driven SDK for building modern web applications with role-based access control",
5
5
  "author": "Ramprasad",
6
6
  "license": "MIT",
@@ -98,6 +98,8 @@ export function useForm<B extends BaseBdo<any, any, any>>(
98
98
  useEffect(() => {
99
99
  if (schema?.BDOBlob) {
100
100
  bdo.loadMetadata(schema.BDOBlob);
101
+ } else if (schema?.MetaBlob) {
102
+ bdo.loadMetadata(schema.MetaBlob);
101
103
  }
102
104
  }, [schema, bdo]);
103
105