@ram_28/kf-ai-sdk 2.0.15 → 2.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -14
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +1 -1
- package/dist/auth/authConfig.d.ts +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/BaseBdo.d.ts +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +3 -3
- package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
- package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useActivityForm/types.d.ts +6 -7
- package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/types.d.ts +7 -6
- package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
- package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
- package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
- package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
- package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
- package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
- package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
- package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
- package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
- package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
- package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
- package/dist/components/hooks/useBDOTable/types.d.ts +20 -14
- package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
- package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
- package/dist/constants-DEmYwKfC.cjs +1 -0
- package/dist/filter.cjs +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.d.ts +1 -1
- package/dist/form.d.ts.map +1 -1
- package/dist/form.mjs +250 -253
- package/dist/form.types.d.ts +1 -1
- package/dist/form.types.d.ts.map +1 -1
- package/dist/shared-5a7UkED1.js +1180 -0
- package/dist/shared-nnmlRVs7.cjs +1 -0
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +14 -14
- package/dist/table.types.d.ts +1 -1
- package/dist/table.types.d.ts.map +1 -1
- package/dist/types/constants.d.ts +4 -4
- package/dist/workflow/Activity.d.ts +22 -7
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/client.d.ts +2 -2
- package/dist/workflow/client.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +7 -3
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +518 -576
- package/docs/README.md +51 -0
- package/docs/bdo/README.md +161 -0
- package/docs/bdo/api_reference.md +281 -0
- package/docs/examples/bdo/create-product.md +69 -0
- package/docs/examples/bdo/edit-product-dialog.md +95 -0
- package/docs/examples/bdo/filtered-product-table.md +100 -0
- package/docs/examples/bdo/product-listing.md +73 -0
- package/docs/examples/bdo/supplier-dropdown.md +60 -0
- package/docs/examples/workflow/approve-leave-request.md +76 -0
- package/docs/examples/workflow/filtered-activity-table.md +101 -0
- package/docs/examples/workflow/my-pending-requests.md +90 -0
- package/docs/examples/workflow/start-new-workflow.md +47 -0
- package/docs/examples/workflow/submit-leave-request.md +72 -0
- package/docs/examples/workflow/workflow-progress.md +49 -0
- package/docs/useActivityForm/README.md +241 -0
- package/docs/useActivityForm/api_reference.md +279 -0
- package/docs/useActivityTable/README.md +263 -0
- package/docs/useActivityTable/api_reference.md +294 -0
- package/docs/useBDOForm/README.md +172 -0
- package/docs/useBDOForm/api_reference.md +244 -0
- package/docs/useBDOTable/README.md +242 -0
- package/docs/useBDOTable/api_reference.md +253 -0
- package/docs/useFilter/README.md +323 -0
- package/docs/useFilter/api_reference.md +228 -0
- package/docs/workflow/README.md +158 -0
- package/docs/workflow/api_reference.md +161 -0
- package/package.json +2 -2
- package/sdk/auth/authConfig.ts +1 -1
- package/sdk/auth/types.ts +1 -1
- package/sdk/bdo/core/BaseBdo.ts +2 -2
- package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
- package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
- package/sdk/components/hooks/useActivityForm/types.ts +8 -10
- package/sdk/components/hooks/useActivityForm/useActivityForm.ts +52 -265
- package/sdk/components/hooks/useActivityTable/types.ts +6 -5
- package/sdk/components/hooks/useActivityTable/useActivityTable.ts +14 -43
- package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
- package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
- package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
- package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
- package/sdk/components/hooks/useBDOTable/types.ts +20 -12
- package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -7
- package/sdk/form.ts +2 -2
- package/sdk/form.types.ts +4 -4
- package/sdk/table.types.ts +2 -0
- package/sdk/types/constants.ts +4 -4
- package/sdk/workflow/Activity.ts +68 -13
- package/sdk/workflow/client.ts +65 -25
- package/sdk/workflow/types.ts +10 -2
- package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
- package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
- package/dist/components/hooks/useForm/index.d.ts +0 -5
- package/dist/components/hooks/useForm/index.d.ts.map +0 -1
- package/dist/components/hooks/useForm/types.d.ts.map +0 -1
- package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
- package/dist/constants-QX2RX-wu.cjs +0 -1
- package/dist/createResolver-AIgUwoS6.cjs +0 -1
- package/dist/createResolver-ZHXQ7QMa.js +0 -1078
- package/docs/api.md +0 -95
- package/docs/bdo.md +0 -224
- package/docs/gaps.md +0 -410
- package/docs/useActivityTable.md +0 -481
- package/docs/useBDOTable.md +0 -317
- package/docs/useFilter.md +0 -188
- package/docs/useForm.md +0 -376
- package/docs/workflow.md +0 -818
- /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
- /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
- /package/docs/{useAuth.md → useAuth/README.md} +0 -0
- /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
- /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
|
@@ -1,26 +1,32 @@
|
|
|
1
|
+
import type { ListOptionsType, SortType } from '../../../types/common';
|
|
1
2
|
import type { UseTableReturnType, PaginationStateType } from '../useTable/types';
|
|
2
3
|
import type { UseFilterOptionsType } from '../useFilter/types';
|
|
3
|
-
|
|
4
|
-
export interface
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly _id: string;
|
|
9
|
-
readonly name: string;
|
|
10
|
-
};
|
|
11
|
-
list(options?: any): Promise<any>;
|
|
12
|
-
count(options?: any): Promise<any>;
|
|
4
|
+
/** Structural constraint — any object with list() and count() */
|
|
5
|
+
export interface BDOTableSourceType {
|
|
6
|
+
meta: {
|
|
7
|
+
readonly _id: string;
|
|
8
|
+
readonly name: string;
|
|
13
9
|
};
|
|
10
|
+
list(options?: ListOptionsType): Promise<any[]>;
|
|
11
|
+
count(options?: ListOptionsType): Promise<number>;
|
|
12
|
+
}
|
|
13
|
+
/** Infer row type from BDO's list() return type */
|
|
14
|
+
export type BDORowType<B extends BDOTableSourceType> = B extends {
|
|
15
|
+
list(opts?: any): Promise<(infer R)[]>;
|
|
16
|
+
} ? R : never;
|
|
17
|
+
export interface UseBDOTableOptionsType<B extends BDOTableSourceType> {
|
|
18
|
+
/** BDO instance — list() and count() are called for data */
|
|
19
|
+
bdo: B;
|
|
14
20
|
/** Initial state */
|
|
15
21
|
initialState?: {
|
|
16
22
|
sort?: SortType;
|
|
17
23
|
pagination?: PaginationStateType;
|
|
18
|
-
filter?: UseFilterOptionsType<
|
|
24
|
+
filter?: UseFilterOptionsType<BDORowType<B>>;
|
|
19
25
|
};
|
|
20
26
|
/** Error callback */
|
|
21
27
|
onError?: (error: Error) => void;
|
|
22
|
-
/** Success callback — receives rows from current page */
|
|
23
|
-
onSuccess?: (data:
|
|
28
|
+
/** Success callback — receives Item rows from current page */
|
|
29
|
+
onSuccess?: (data: BDORowType<B>[]) => void;
|
|
24
30
|
}
|
|
25
|
-
export type UseBDOTableReturnType<
|
|
31
|
+
export type UseBDOTableReturnType<B extends BDOTableSourceType> = UseTableReturnType<BDORowType<B>>;
|
|
26
32
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useBDOTable/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useBDOTable/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAChD,KAAK,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACnD;AAED,mDAAmD;AACnD,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,kBAAkB,IACjD,CAAC,SAAS;IAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnE,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,kBAAkB;IAClE,4DAA4D;IAC5D,GAAG,EAAE,CAAC,CAAC;IACP,oBAAoB;IACpB,YAAY,CAAC,EAAE;QACb,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,UAAU,CAAC,EAAE,mBAAmB,CAAC;QACjC,MAAM,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KAC9C,CAAC;IACF,qBAAqB;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,8DAA8D;IAC9D,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC;CAC7C;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,kBAAkB,IAC5D,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { UseBDOTableOptionsType, UseBDOTableReturnType } from './types';
|
|
2
|
-
export declare function useBDOTable<
|
|
1
|
+
import type { BDOTableSourceType, UseBDOTableOptionsType, UseBDOTableReturnType } from './types';
|
|
2
|
+
export declare function useBDOTable<B extends BDOTableSourceType>(options: UseBDOTableOptionsType<B>): UseBDOTableReturnType<B>;
|
|
3
3
|
//# sourceMappingURL=useBDOTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBDOTable.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useBDOTable/useBDOTable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useBDOTable.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useBDOTable/useBDOTable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAElB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,WAAW,CAAC,CAAC,SAAS,kBAAkB,EACtD,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GACjC,qBAAqB,CAAC,CAAC,CAAC,CAS1B"}
|
|
@@ -110,7 +110,7 @@ const t = {
|
|
|
110
110
|
Unauthenticated: "unauthenticated"
|
|
111
111
|
}, u = {
|
|
112
112
|
Google: "google",
|
|
113
|
-
|
|
113
|
+
Azure: "azure",
|
|
114
114
|
GitHub: "github",
|
|
115
115
|
Custom: "custom"
|
|
116
116
|
}, C = {
|
|
@@ -146,12 +146,12 @@ const t = {
|
|
|
146
146
|
PAGE: 1,
|
|
147
147
|
/** Maximum search query length */
|
|
148
148
|
SEARCH_MAX_LENGTH: 255
|
|
149
|
-
},
|
|
149
|
+
}, A = {
|
|
150
150
|
/** Date encoded field key: { "$__d__": "YYYY-MM-DD" } */
|
|
151
151
|
Date: "$__d__",
|
|
152
152
|
/** DateTime encoded field key: { "$__dt__": unix_timestamp } */
|
|
153
153
|
DateTime: "$__dt__"
|
|
154
|
-
},
|
|
154
|
+
}, T = {
|
|
155
155
|
/** Successful deletion */
|
|
156
156
|
Success: "success"
|
|
157
157
|
};
|
|
@@ -168,8 +168,8 @@ export {
|
|
|
168
168
|
e as R,
|
|
169
169
|
o as S,
|
|
170
170
|
r as V,
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
A as a,
|
|
172
|
+
T as b,
|
|
173
173
|
u as c,
|
|
174
174
|
C as d
|
|
175
175
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t={EQ:"EQ",NE:"NE",GT:"GT",GTE:"GTE",LT:"LT",LTE:"LTE",Between:"Between",NotBetween:"NotBetween",IN:"IN",NIN:"NIN",Empty:"Empty",NotEmpty:"NotEmpty",Contains:"Contains",NotContains:"NotContains",MinLength:"MinLength",MaxLength:"MaxLength",Length:"Length"},e={And:"And",Or:"Or",Not:"Not"},n={Constant:"Constant",BDOField:"BDOField",AppVariable:"AppVariable"},o={ASC:"ASC",DESC:"DESC"},i={Sum:"Sum",Avg:"Avg",Count:"Count",Max:"Max",Min:"Min",DistinctCount:"DistinctCount",BlankCount:"BlankCount",NotBlankCount:"NotBlankCount",Concat:"Concat",DistinctConcat:"DistinctConcat"},a={List:"List",Metric:"Metric",Pivot:"Pivot"},r={Create:"create",Update:"update"},c={Interactive:"interactive",NonInteractive:"non-interactive"},s={OnBlur:"onBlur",OnChange:"onChange",OnSubmit:"onSubmit",OnTouched:"onTouched",All:"all"},d={Loading:"loading",Authenticated:"authenticated",Unauthenticated:"unauthenticated"},u={Google:"google",Azure:"azure",GitHub:"github",Custom:"custom"},C={Id:"_id",CreatedAt:"_created_at",ModifiedAt:"_modified_at",CreatedBy:"_created_by",ModifiedBy:"_modified_by",Version:"_version",MergeVersion:"_m_version"},E={GET:"GET",POST:"POST",PATCH:"PATCH",DELETE:"DELETE"},p={SEARCH_DEBOUNCE_MS:300,PAGE_SIZE:10,PAGE:1,SEARCH_MAX_LENGTH:255},T={Date:"$__d__",DateTime:"$__dt__"},l={Success:"success"};exports.AuthProviderName=u;exports.AuthStatus=d;exports.ConditionOperator=t;exports.DateEncodingKey=T;exports.Defaults=p;exports.DeleteStatus=l;exports.FormOperation=r;exports.GroupOperator=e;exports.HttpMethod=E;exports.InteractionMode=c;exports.MetricType=i;exports.QueryType=a;exports.RHSType=n;exports.SortDirection=o;exports.SystemField=C;exports.ValidationMode=s;
|
package/dist/filter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./useFilter-Bg0jvIL6.cjs"),e=require("./constants-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./useFilter-Bg0jvIL6.cjs"),e=require("./constants-DEmYwKfC.cjs");exports.isCondition=o.isCondition;exports.isConditionGroup=o.isConditionGroup;exports.useFilter=o.useFilter;exports.ConditionOperator=e.ConditionOperator;exports.FilterValueSource=e.RHSType;exports.GroupOperator=e.GroupOperator;
|
package/dist/filter.mjs
CHANGED
package/dist/form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("./constants-DEmYwKfC.cjs"),_=require("react"),I=require("./shared-nnmlRVs7.cjs"),J=require("@tanstack/react-query"),y=require("./client-D5k4SYuw.cjs"),k=require("./attachment-constants-B5jlqoKI.cjs"),W=require("./metadata-DWXQPDav.cjs");function X(T,a){const g=T.getFields(),b=new Map,C=T.getBoId();let m=null,x=null;async function M(){const S=a.getValues("_id");return S||m||(x||(x=y.api(C).draftInteraction({}).then(e=>(m=e._id,a.setValue("_id",m,{shouldDirty:!1}),m)).catch(e=>{throw x=null,e})),x)}return new Proxy({},{get(S,e){if(typeof e=="symbol")return;if(e==="_id")return a.getValues("_id");if(e==="toJSON")return()=>a.getValues();if(e==="validate")return()=>a.trigger();if(e==="_hasDraft")return()=>!!m;if(b.has(e))return b.get(e);const i=g[e],d=(i==null?void 0:i.meta)??{_id:e,Name:e,Type:"String"},L=(i==null?void 0:i.readOnly)??!1,N=()=>{if(!i)return{valid:!0,errors:[]};let l=a.getValues(e);if("integerPart"in i&&typeof l=="string"&&l!==""){const o=Number(l);isNaN(o)||(l=o,a.setValue(e,o,{shouldDirty:!1}))}if(!i.required&&(l==null||l===""||Array.isArray(l)&&l.length===0))return{valid:!0,errors:[]};const s=i.validate(l);if(!s.valid)return s;const t=I.validateConstraints(i,l);if(!t.valid)return t;if(T.hasMetadata()){const o=T.validateFieldExpression(e,l,a.getValues());if(!o.valid)return o}return{valid:!0,errors:[]}},B=l=>{const s=a.getValues(e);return s??l};if(!L){const l=()=>{const t=a.getValues(e);return d.Type==="File"?t??[]:t},s={label:(i==null?void 0:i.label)??e,required:(i==null?void 0:i.required)??!1,readOnly:!1,defaultValue:i==null?void 0:i.defaultValue,meta:d,get:l,getOrDefault:B,set:t=>{a.setValue(e,t,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:N};if(d.Type==="Image"||d.Type==="File"){const t=C,o=()=>{const n=a.getValues("_id");if(!n)throw new Error("Save the record before attachment operations");return n};d.Type==="Image"?(s.upload=async n=>{k.validateFileExtension(n.name,"Image");const r=await M(),[c]=await y.api(t).getUploadUrl(r,e,[{FileName:n.name,Size:n.size,FileExtension:k.extractFileExtension(n.name)}]);await fetch(c.UploadUrl.URL,{method:"PUT",headers:{"Content-Type":c.ContentType},body:n});const f={_id:c._id,_name:c._name,FileName:c.FileName,FileExtension:c.FileExtension,Size:c.Size,ContentType:c.ContentType};return a.setValue(e,f,{shouldDirty:!0}),f},s.deleteAttachment=async()=>{const n=a.getValues(e),r=o();if(!(n!=null&&n._id))throw new Error(`${e} has no image to delete`);await y.api(t).deleteAttachment(r,e,n._id),a.setValue(e,null,{shouldDirty:!0})},s.getDownloadUrl=async n=>{const r=a.getValues(e),c=o();if(!(r!=null&&r._id))throw new Error(`${e} has no image`);return y.api(t).getDownloadUrl(c,e,r._id,n)}):(s.upload=async n=>{for(const V of n)k.validateFileExtension(V.name,"File");const r=await M(),c=n.map(V=>({FileName:V.name,Size:V.size,FileExtension:k.extractFileExtension(V.name)})),f=await y.api(t).getUploadUrl(r,e,c),R=await Promise.all(n.map(async(V,h)=>(await fetch(f[h].UploadUrl.URL,{method:"PUT",headers:{"Content-Type":f[h].ContentType},body:V}),{_id:f[h]._id,_name:f[h]._name,FileName:f[h].FileName,FileExtension:f[h].FileExtension,Size:f[h].Size,ContentType:f[h].ContentType}))),U=a.getValues(e)??[];return a.setValue(e,[...U,...R],{shouldDirty:!0}),R},s.deleteAttachment=async n=>{const r=a.getValues(e)??[],c=o();await y.api(t).deleteAttachment(c,e,n),a.setValue(e,r.filter(f=>f._id!==n),{shouldDirty:!0})},s.getDownloadUrl=async(n,r)=>{const c=o();return y.api(t).getDownloadUrl(c,e,n,r)},s.getDownloadUrls=async n=>{const r=o();return y.api(t).getDownloadUrls(r,e,n)})}return b.set(e,s),s}const u=()=>{const l=a.getValues(e);return d.Type==="File"?l??[]:l},v={label:(i==null?void 0:i.label)??e,required:(i==null?void 0:i.required)??!1,readOnly:!0,defaultValue:i==null?void 0:i.defaultValue,meta:d,get:u,getOrDefault:B,validate:N};if(d.Type==="Image"||d.Type==="File"){const l=C,s=()=>{const t=a.getValues("_id");if(!t)throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");return t};d.Type==="Image"?v.getDownloadUrl=async t=>{const o=a.getValues(e),n=s();if(!(o!=null&&o._id))throw new Error(`${e} has no image to download`);return y.api(l).getDownloadUrl(n,e,o._id,t)}:(v.getDownloadUrl=async(t,o)=>{const n=s();return y.api(l).getDownloadUrl(n,e,t,o)},v.getDownloadUrls=async t=>{const o=s();return y.api(l).getDownloadUrls(o,e,t)})}return b.set(e,v),v},has(S,e){return typeof e=="symbol"?!1:e==="_id"||e==="toJSON"||e==="validate"||e==="_hasDraft"?!0:e in g},ownKeys(S){return[...Object.keys(g),"_id","toJSON","validate"]},getOwnPropertyDescriptor(S,e){if(typeof e!="symbol")return{configurable:!0,enumerable:e!=="toJSON"&&e!=="validate"&&e!=="_hasDraft"}}})}function Y(T){const{bdo:a,recordId:g,operation:b,defaultValues:C,mode:m="onBlur",enableDraft:x=!1,enableConstraintValidation:M,enableExpressionValidation:S}=T,e=b??(g?"update":"create"),i=_.useMemo(()=>I.createResolver(a,{enableConstraintValidation:M}),[a,M]),{data:d,isLoading:L,isFetching:N,error:B}=J.useQuery({queryKey:["form-record",a.meta._id,g],queryFn:async()=>{const w=await a.get(g);return I.coerceRecordForForm(a.getFields(),w.toJSON())},enabled:e==="update"&&!!g,staleTime:0}),{data:u,isLoading:v,error:l}=J.useQuery({queryKey:["form-draft",a.meta._id],queryFn:async()=>y.api(a.meta._id).draftInteraction({}),enabled:e==="create",staleTime:1/0,gcTime:0,retry:1}),{data:s}=J.useQuery({queryKey:["form-schema",a.meta._id],queryFn:()=>W.getBdoSchema(a.meta._id),staleTime:30*60*1e3,gcTime:60*60*1e3,enabled:S!==!1});_.useEffect(()=>{s!=null&&s.BDOBlob?a.loadMetadata(s.BDOBlob):s!=null&&s.MetaBlob&&a.loadMetadata(s.MetaBlob)},[s,a]);const t=I.useForm({mode:m,resolver:i,defaultValues:C}),o=_.useRef(null);_.useEffect(()=>{e==="update"&&d&&d!==o.current&&(t.reset(d),o.current=d)},[d,e,t]),_.useEffect(()=>{u!=null&&u._id&&t.setValue("_id",u._id)},[u,t]);const n=_.useMemo(()=>X(a,t),[a,t]),r=a.getFields(),c=_.useRef(!1),f=_.useMemo(()=>Object.keys(r).filter(w=>r[w].readOnly),[r]),R=_.useCallback(async(w,F)=>{if(e==="create"&&(u!=null&&u._id))return y.api(a.meta._id).draftInteraction({_id:u._id,[w]:F});if(e==="update"&&g)return y.api(a.meta._id).update(g,{[w]:F})},[e,u,g,a]),U=_.useMemo(()=>I.createSyncField({apiFn:R,allFields:r,readonlyFieldNames:f,rhf:t,isComputingRef:c}),[R,r,f,t]),V=m==="onChange"||m==="all",h=m==="onBlur"||m==="onTouched"||m==="all",Q=_.useMemo(()=>I.createEnhancedRegister({rhf:t,allFields:r,syncField:U,syncOnBlur:h,syncOnChange:V}),[t,r,U,h,V]),$=_.useMemo(()=>I.createEnhancedControl({control:t.control,syncField:U,syncOnBlur:h,syncOnChange:V}),[t.control,U,h,V]),G=_.useCallback((w,F)=>t.handleSubmit(async(P,z)=>{try{const O={},A=t.getValues();if(e==="create")for(const[q,D]of Object.entries(r)){if(D.readOnly)continue;const E=A[q]!==void 0?A[q]:P[q];E!==void 0&&(O[q]=I.coerceFieldValue(D,E))}else{const q=t.formState.dirtyFields;for(const[D,E]of Object.entries(r)){if(E.readOnly||!q[D])continue;const H=A[D]!==void 0?A[D]:P[D];O[D]=I.coerceFieldValue(E,H)}}let j;e==="create"?(O._id=u==null?void 0:u._id,j=await y.api(a.meta._id).draft(O)):j=await y.api(a.meta._id).update(g,O),w==null||w(j,z)}catch(O){F==null||F(O,z)}},(P,z)=>{F==null||F(P,z)}),[t,a,e,g,r,u]);return{item:n,bdo:a,operation:e,recordId:g,register:Q,handleSubmit:G,watch:t.watch,setValue:t.setValue,getValues:t.getValues,reset:t.reset,trigger:t.trigger,control:$,formState:t.formState,errors:t.formState.errors,isDirty:t.formState.isDirty,isValid:t.formState.isValid,isSubmitting:t.formState.isSubmitting,isSubmitSuccessful:t.formState.isSubmitSuccessful,dirtyFields:t.formState.dirtyFields,isLoading:L||v,isFetching:N,loadError:B??l,draftId:u==null?void 0:u._id,isCreatingDraft:v}}exports.FormOperation=K.FormOperation;exports.InteractionMode=K.InteractionMode;exports.ValidationMode=K.ValidationMode;exports.useBDOForm=Y;
|
package/dist/form.d.ts
CHANGED
package/dist/form.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../sdk/form.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../sdk/form.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|