@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.
Files changed (130) hide show
  1. package/README.md +22 -14
  2. package/dist/api.cjs +1 -1
  3. package/dist/api.mjs +1 -1
  4. package/dist/auth/authConfig.d.ts +1 -1
  5. package/dist/auth/types.d.ts +1 -1
  6. package/dist/auth/types.d.ts.map +1 -1
  7. package/dist/auth.cjs +1 -1
  8. package/dist/auth.mjs +1 -1
  9. package/dist/bdo/core/BaseBdo.d.ts +1 -1
  10. package/dist/bdo.cjs +1 -1
  11. package/dist/bdo.mjs +3 -3
  12. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
  13. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
  14. package/dist/components/hooks/useActivityForm/types.d.ts +6 -7
  15. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  16. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  17. package/dist/components/hooks/useActivityTable/types.d.ts +7 -6
  18. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  19. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
  20. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  21. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
  22. package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
  23. package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
  24. package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
  25. package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
  26. package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
  27. package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
  28. package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
  29. package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
  30. package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
  31. package/dist/components/hooks/useBDOTable/types.d.ts +20 -14
  32. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  33. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  34. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  35. package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
  36. package/dist/constants-DEmYwKfC.cjs +1 -0
  37. package/dist/filter.cjs +1 -1
  38. package/dist/filter.mjs +1 -1
  39. package/dist/form.cjs +1 -1
  40. package/dist/form.d.ts +1 -1
  41. package/dist/form.d.ts.map +1 -1
  42. package/dist/form.mjs +250 -253
  43. package/dist/form.types.d.ts +1 -1
  44. package/dist/form.types.d.ts.map +1 -1
  45. package/dist/shared-5a7UkED1.js +1180 -0
  46. package/dist/shared-nnmlRVs7.cjs +1 -0
  47. package/dist/table.cjs +1 -1
  48. package/dist/table.mjs +14 -14
  49. package/dist/table.types.d.ts +1 -1
  50. package/dist/table.types.d.ts.map +1 -1
  51. package/dist/types/constants.d.ts +4 -4
  52. package/dist/workflow/Activity.d.ts +22 -7
  53. package/dist/workflow/Activity.d.ts.map +1 -1
  54. package/dist/workflow/client.d.ts +2 -2
  55. package/dist/workflow/client.d.ts.map +1 -1
  56. package/dist/workflow/types.d.ts +7 -3
  57. package/dist/workflow/types.d.ts.map +1 -1
  58. package/dist/workflow.cjs +1 -1
  59. package/dist/workflow.mjs +518 -576
  60. package/docs/README.md +51 -0
  61. package/docs/bdo/README.md +161 -0
  62. package/docs/bdo/api_reference.md +281 -0
  63. package/docs/examples/bdo/create-product.md +69 -0
  64. package/docs/examples/bdo/edit-product-dialog.md +95 -0
  65. package/docs/examples/bdo/filtered-product-table.md +100 -0
  66. package/docs/examples/bdo/product-listing.md +73 -0
  67. package/docs/examples/bdo/supplier-dropdown.md +60 -0
  68. package/docs/examples/workflow/approve-leave-request.md +76 -0
  69. package/docs/examples/workflow/filtered-activity-table.md +101 -0
  70. package/docs/examples/workflow/my-pending-requests.md +90 -0
  71. package/docs/examples/workflow/start-new-workflow.md +47 -0
  72. package/docs/examples/workflow/submit-leave-request.md +72 -0
  73. package/docs/examples/workflow/workflow-progress.md +49 -0
  74. package/docs/useActivityForm/README.md +241 -0
  75. package/docs/useActivityForm/api_reference.md +279 -0
  76. package/docs/useActivityTable/README.md +263 -0
  77. package/docs/useActivityTable/api_reference.md +294 -0
  78. package/docs/useBDOForm/README.md +172 -0
  79. package/docs/useBDOForm/api_reference.md +244 -0
  80. package/docs/useBDOTable/README.md +242 -0
  81. package/docs/useBDOTable/api_reference.md +253 -0
  82. package/docs/useFilter/README.md +323 -0
  83. package/docs/useFilter/api_reference.md +228 -0
  84. package/docs/workflow/README.md +158 -0
  85. package/docs/workflow/api_reference.md +161 -0
  86. package/package.json +2 -2
  87. package/sdk/auth/authConfig.ts +1 -1
  88. package/sdk/auth/types.ts +1 -1
  89. package/sdk/bdo/core/BaseBdo.ts +2 -2
  90. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
  91. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
  92. package/sdk/components/hooks/useActivityForm/types.ts +8 -10
  93. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +52 -265
  94. package/sdk/components/hooks/useActivityTable/types.ts +6 -5
  95. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +14 -43
  96. package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
  97. package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
  98. package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
  99. package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
  100. package/sdk/components/hooks/useBDOTable/types.ts +20 -12
  101. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -7
  102. package/sdk/form.ts +2 -2
  103. package/sdk/form.types.ts +4 -4
  104. package/sdk/table.types.ts +2 -0
  105. package/sdk/types/constants.ts +4 -4
  106. package/sdk/workflow/Activity.ts +68 -13
  107. package/sdk/workflow/client.ts +65 -25
  108. package/sdk/workflow/types.ts +10 -2
  109. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
  110. package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
  111. package/dist/components/hooks/useForm/index.d.ts +0 -5
  112. package/dist/components/hooks/useForm/index.d.ts.map +0 -1
  113. package/dist/components/hooks/useForm/types.d.ts.map +0 -1
  114. package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
  115. package/dist/constants-QX2RX-wu.cjs +0 -1
  116. package/dist/createResolver-AIgUwoS6.cjs +0 -1
  117. package/dist/createResolver-ZHXQ7QMa.js +0 -1078
  118. package/docs/api.md +0 -95
  119. package/docs/bdo.md +0 -224
  120. package/docs/gaps.md +0 -410
  121. package/docs/useActivityTable.md +0 -481
  122. package/docs/useBDOTable.md +0 -317
  123. package/docs/useFilter.md +0 -188
  124. package/docs/useForm.md +0 -376
  125. package/docs/workflow.md +0 -818
  126. /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
  127. /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
  128. /package/docs/{useAuth.md → useAuth/README.md} +0 -0
  129. /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
  130. /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
- import type { SortType } from '../../../types/common';
4
- export interface UseBDOTableOptionsType<T> {
5
- /** BDO instance with list() and count() methods */
6
- bdo: {
7
- meta: {
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<T>;
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: T[]) => void;
28
+ /** Success callback — receives Item rows from current page */
29
+ onSuccess?: (data: BDORowType<B>[]) => void;
24
30
  }
25
- export type UseBDOTableReturnType<T> = UseTableReturnType<T>;
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,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,WAAW,sBAAsB,CAAC,CAAC;IACvC,mDAAmD;IACnD,GAAG,EAAE;QACH,IAAI,EAAE;YAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QACtD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;KACpC,CAAC;IACF,oBAAoB;IACpB,YAAY,CAAC,EAAE;QACb,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,UAAU,CAAC,EAAE,mBAAmB,CAAC;QACjC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;KAClC,CAAC;IACF,qBAAqB;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,yDAAyD;IACzD,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;CACjC;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC"}
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<T = any>(options: UseBDOTableOptionsType<T>): UseBDOTableReturnType<T>;
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,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE7E,wBAAgB,WAAW,CAAC,CAAC,GAAG,GAAG,EACjC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GACjC,qBAAqB,CAAC,CAAC,CAAC,CAS1B"}
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
- Microsoft: "microsoft",
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
- }, T = {
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
- }, A = {
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
- T as a,
172
- A as b,
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-QX2RX-wu.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;
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
@@ -1,5 +1,5 @@
1
1
  import { i, a, u as e } from "./useFilter-DPNLKY3H.js";
2
- import { C as t, R as n, G as p } from "./constants-ConHc1oS.js";
2
+ import { C as t, R as n, G as p } from "./constants-Cyi942Yr.js";
3
3
  export {
4
4
  t as ConditionOperator,
5
5
  n as FilterValueSource,
package/dist/form.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./constants-QX2RX-wu.cjs"),b=require("react"),A=require("./createResolver-AIgUwoS6.cjs"),k=require("@tanstack/react-query"),_=require("./client-D5k4SYuw.cjs"),z=require("./attachment-constants-B5jlqoKI.cjs"),K=require("./metadata-DWXQPDav.cjs");function Q(T,t){const d=T.getFields(),g=new Map,D=T.getBoId();let V=null,I=null;async function N(){const O=t.getValues("_id");return O||V||(I||(I=_.api(D).draftInteraction({}).then(e=>(V=e._id,t.setValue("_id",V,{shouldDirty:!1}),V)).catch(e=>{throw I=null,e})),I)}return new Proxy({},{get(O,e){if(typeof e=="symbol")return;if(e==="_id")return t.getValues("_id");if(e==="toJSON")return()=>t.getValues();if(e==="validate")return()=>t.trigger();if(e==="_hasDraft")return()=>!!V;if(g.has(e))return g.get(e);const i=d[e],h=(i==null?void 0:i.meta)??{_id:e,Name:e,Type:"String"},B=(i==null?void 0:i.readOnly)??!1,E=()=>{if(!i)return{valid:!0,errors:[]};let l=t.getValues(e);if("integerPart"in i&&typeof l=="string"&&l!==""){const o=Number(l);isNaN(o)||(l=o,t.setValue(e,o,{shouldDirty:!1}))}if(!i.required&&(l==null||l===""||Array.isArray(l)&&l.length===0))return{valid:!0,errors:[]};const r=i.validate(l);if(!r.valid)return r;const a=A.validateConstraints(i,l);if(!a.valid)return a;if(T.hasMetadata()){const o=T.validateFieldExpression(e,l,t.getValues());if(!o.valid)return o}return{valid:!0,errors:[]}},M=l=>{const r=t.getValues(e);return r??l};if(!B){const l=()=>{const a=t.getValues(e);return h.Type==="File"?a??[]:a},r={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:h,get:l,getOrDefault:M,set:a=>{t.setValue(e,a,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:E};if(h.Type==="Image"||h.Type==="File"){const a=D,o=()=>{const n=t.getValues("_id");if(!n)throw new Error("Save the record before attachment operations");return n};h.Type==="Image"?(r.upload=async n=>{z.validateFileExtension(n.name,"Image");const s=await N(),[f]=await _.api(a).getUploadUrl(s,e,[{FileName:n.name,Size:n.size,FileExtension:z.extractFileExtension(n.name)}]);await fetch(f.UploadUrl.URL,{method:"PUT",headers:{"Content-Type":f.ContentType},body:n});const c={_id:f._id,_name:f._name,FileName:f.FileName,FileExtension:f.FileExtension,Size:f.Size,ContentType:f.ContentType};return t.setValue(e,c,{shouldDirty:!0}),c},r.deleteAttachment=async()=>{const n=t.getValues(e),s=o();if(!(n!=null&&n._id))throw new Error(`${e} has no image to delete`);await _.api(a).deleteAttachment(s,e,n._id),t.setValue(e,null,{shouldDirty:!0})},r.getDownloadUrl=async n=>{const s=t.getValues(e),f=o();if(!(s!=null&&s._id))throw new Error(`${e} has no image`);return _.api(a).getDownloadUrl(f,e,s._id,n)}):(r.upload=async n=>{for(const m of n)z.validateFileExtension(m.name,"File");const s=await N(),f=n.map(m=>({FileName:m.name,Size:m.size,FileExtension:z.extractFileExtension(m.name)})),c=await _.api(a).getUploadUrl(s,e,f),P=await Promise.all(n.map(async(m,y)=>(await fetch(c[y].UploadUrl.URL,{method:"PUT",headers:{"Content-Type":c[y].ContentType},body:m}),{_id:c[y]._id,_name:c[y]._name,FileName:c[y].FileName,FileExtension:c[y].FileExtension,Size:c[y].Size,ContentType:c[y].ContentType}))),w=t.getValues(e)??[];return t.setValue(e,[...w,...P],{shouldDirty:!0}),P},r.deleteAttachment=async n=>{const s=t.getValues(e)??[],f=o();await _.api(a).deleteAttachment(f,e,n),t.setValue(e,s.filter(c=>c._id!==n),{shouldDirty:!0})},r.getDownloadUrl=async(n,s)=>{const f=o();return _.api(a).getDownloadUrl(f,e,n,s)},r.getDownloadUrls=async n=>{const s=o();return _.api(a).getDownloadUrls(s,e,n)})}return g.set(e,r),r}const u=()=>{const l=t.getValues(e);return h.Type==="File"?l??[]:l},U={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:h,get:u,getOrDefault:M,validate:E};if(h.Type==="Image"||h.Type==="File"){const l=D,r=()=>{const a=t.getValues("_id");if(!a)throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");return a};h.Type==="Image"?U.getDownloadUrl=async a=>{const o=t.getValues(e),n=r();if(!(o!=null&&o._id))throw new Error(`${e} has no image to download`);return _.api(l).getDownloadUrl(n,e,o._id,a)}:(U.getDownloadUrl=async(a,o)=>{const n=r();return _.api(l).getDownloadUrl(n,e,a,o)},U.getDownloadUrls=async a=>{const o=r();return _.api(l).getDownloadUrls(o,e,a)})}return g.set(e,U),U},has(O,e){return typeof e=="symbol"?!1:e==="_id"||e==="toJSON"||e==="validate"||e==="_hasDraft"?!0:e in d},ownKeys(O){return[...Object.keys(d),"_id","toJSON","validate"]},getOwnPropertyDescriptor(O,e){if(typeof e!="symbol")return{configurable:!0,enumerable:e!=="toJSON"&&e!=="validate"&&e!=="_hasDraft"}}})}function j(T,t){const d=T.meta.Type;if(typeof t=="string"&&d==="Number")return t===""?void 0:Number(t);if(!(typeof t=="string"&&t===""&&(d==="Date"||d==="DateTime"))){if(typeof t=="string"&&t!==""&&d==="DateTime"){let g=t;return g.endsWith("Z")&&(g=g.slice(0,-1)),((g.split("T")[1]||"").match(/:/g)||[]).length===1&&(g+=":00"),g+"Z"}return t}}function Z(T,t){var D;const d=T.getFields(),g={...t};for(const[V,I]of Object.entries(g))typeof I=="string"&&((D=d[V])==null?void 0:D.meta.Type)==="DateTime"&&I.endsWith("Z")&&(g[V]=I.slice(0,-1));return g}function $(T){const{bdo:t,recordId:d,operation:g,defaultValues:D,mode:V="onBlur",enableDraft:I=!1,enableConstraintValidation:N,enableExpressionValidation:O}=T,e=g??(d?"update":"create"),i=b.useMemo(()=>A.createResolver(t,{enableConstraintValidation:N}),[t,N]),{data:h,isLoading:B,isFetching:E,error:M}=k.useQuery({queryKey:["form-record",t.meta._id,d],queryFn:async()=>{const w=await t.get(d);return Z(t,w.toJSON())},enabled:e==="update"&&!!d,staleTime:0}),{data:u,isLoading:U,error:l}=k.useQuery({queryKey:["form-draft",t.meta._id],queryFn:async()=>_.api(t.meta._id).draftInteraction({}),enabled:e==="create",staleTime:1/0,gcTime:0,retry:1}),{data:r}=k.useQuery({queryKey:["form-schema",t.meta._id],queryFn:()=>K.getBdoSchema(t.meta._id),staleTime:30*60*1e3,gcTime:60*60*1e3,enabled:O!==!1});b.useEffect(()=>{r!=null&&r.BDOBlob?t.loadMetadata(r.BDOBlob):r!=null&&r.MetaBlob&&t.loadMetadata(r.MetaBlob)},[r,t]);const a=A.useForm({mode:V,resolver:i,defaultValues:D}),o=b.useRef(null);b.useEffect(()=>{e==="update"&&h&&h!==o.current&&(a.reset(h),o.current=h)},[h,e,a]),b.useEffect(()=>{u!=null&&u._id&&a.setValue("_id",u._id)},[u,a]);const n=b.useMemo(()=>Q(t,a),[t,a]),s=t.getFields(),f=b.useCallback((w,m)=>{var S;const y=a.register(w,m);return(S=s[w])!=null&&S.readOnly?{...y,disabled:!0}:y},[a,s]),c=b.useRef(null);b.useEffect(()=>{if(e!=="create"||!(u!=null&&u._id))return;const w=a.watch((m,{type:y})=>{y==="change"&&(c.current&&clearTimeout(c.current),c.current=setTimeout(async()=>{const S=a.getValues(),F=a.formState.dirtyFields,q={};for(const[v,x]of Object.entries(S))s[v]&&!s[v].readOnly&&F[v]&&(q[v]=j(s[v],x));if(Object.keys(q).length>0)try{await _.api(t.meta._id).draftInteraction({_id:u._id,...q})}catch{}},800))});return()=>{w.unsubscribe(),c.current&&clearTimeout(c.current)}},[a,e,u,s,t]);const P=b.useCallback((w,m)=>a.handleSubmit(async(y,S)=>{try{const F={},q=a.getValues();if(e==="create")for(const[x,R]of Object.entries(s)){if(R.readOnly)continue;const C=q[x]!==void 0?q[x]:y[x];C!==void 0&&(F[x]=j(R,C))}else{const x=a.formState.dirtyFields;for(const[R,C]of Object.entries(s)){if(C.readOnly||!x[R])continue;const J=q[R]!==void 0?q[R]:y[R];F[R]=j(C,J)}}let v;e==="create"?(F._id=u==null?void 0:u._id,v=await _.api(t.meta._id).draft(F)):v=await _.api(t.meta._id).update(d,F),w==null||w(v,S)}catch(F){m==null||m(F,S)}},(y,S)=>{m==null||m(y,S)}),[a,t,e,d,s,u]);return{item:n,bdo:t,operation:e,recordId:d,register:f,handleSubmit:P,watch:a.watch,setValue:a.setValue,getValues:a.getValues,reset:a.reset,trigger:a.trigger,control:a.control,formState:a.formState,errors:a.formState.errors,isDirty:a.formState.isDirty,isValid:a.formState.isValid,isSubmitting:a.formState.isSubmitting,isSubmitSuccessful:a.formState.isSubmitSuccessful,dirtyFields:a.formState.dirtyFields,isLoading:B||U,isFetching:E,loadError:M??l,draftId:u==null?void 0:u._id,isCreatingDraft:U}}exports.FormOperation=L.FormOperation;exports.InteractionMode=L.InteractionMode;exports.ValidationMode=L.ValidationMode;exports.useForm=$;
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
@@ -1,3 +1,3 @@
1
- export { useForm } from "./components/hooks/useForm";
1
+ export { useBDOForm } from "./components/hooks/useBDOForm";
2
2
  export { ValidationMode, FormOperation, InteractionMode } from "./types/constants";
3
3
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../sdk/form.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
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"}