@ram_28/kf-ai-sdk 2.0.0 → 2.0.2

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 (137) hide show
  1. package/README.md +36 -39
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/metadata.d.ts +26 -22
  4. package/dist/api/metadata.d.ts.map +1 -1
  5. package/dist/api.cjs +1 -1
  6. package/dist/api.mjs +3 -3
  7. package/dist/auth.cjs +1 -1
  8. package/dist/auth.mjs +2 -2
  9. package/dist/base-types.d.ts +1 -1
  10. package/dist/base-types.d.ts.map +1 -1
  11. package/dist/bdo/core/BaseBdo.d.ts +8 -20
  12. package/dist/bdo/core/BaseBdo.d.ts.map +1 -1
  13. package/dist/bdo/core/Item.d.ts +8 -44
  14. package/dist/bdo/core/Item.d.ts.map +1 -1
  15. package/dist/bdo/core/types.d.ts +124 -41
  16. package/dist/bdo/core/types.d.ts.map +1 -1
  17. package/dist/bdo/fields/ArrayField.d.ts +5 -4
  18. package/dist/bdo/fields/ArrayField.d.ts.map +1 -1
  19. package/dist/bdo/fields/BaseField.d.ts +14 -19
  20. package/dist/bdo/fields/BaseField.d.ts.map +1 -1
  21. package/dist/bdo/fields/BooleanField.d.ts +3 -4
  22. package/dist/bdo/fields/BooleanField.d.ts.map +1 -1
  23. package/dist/bdo/fields/DateField.d.ts +18 -0
  24. package/dist/bdo/fields/DateField.d.ts.map +1 -0
  25. package/dist/bdo/fields/DateTimeField.d.ts +5 -4
  26. package/dist/bdo/fields/DateTimeField.d.ts.map +1 -1
  27. package/dist/bdo/fields/FileField.d.ts +18 -0
  28. package/dist/bdo/fields/FileField.d.ts.map +1 -0
  29. package/dist/bdo/fields/NumberField.d.ts +6 -4
  30. package/dist/bdo/fields/NumberField.d.ts.map +1 -1
  31. package/dist/bdo/fields/ObjectField.d.ts +20 -0
  32. package/dist/bdo/fields/ObjectField.d.ts.map +1 -0
  33. package/dist/bdo/fields/ReferenceField.d.ts +13 -14
  34. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  35. package/dist/bdo/fields/SelectField.d.ts +10 -17
  36. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  37. package/dist/bdo/fields/StringField.d.ts +6 -4
  38. package/dist/bdo/fields/StringField.d.ts.map +1 -1
  39. package/dist/bdo/fields/TextAreaField.d.ts +2 -0
  40. package/dist/bdo/fields/TextAreaField.d.ts.map +1 -0
  41. package/dist/bdo/fields/TextField.d.ts +22 -0
  42. package/dist/bdo/fields/TextField.d.ts.map +1 -0
  43. package/dist/bdo/fields/UserField.d.ts +20 -0
  44. package/dist/bdo/fields/UserField.d.ts.map +1 -0
  45. package/dist/bdo/fields/index.d.ts +6 -0
  46. package/dist/bdo/fields/index.d.ts.map +1 -1
  47. package/dist/bdo/index.d.ts +2 -2
  48. package/dist/bdo/index.d.ts.map +1 -1
  49. package/dist/bdo.cjs +1 -1
  50. package/dist/bdo.d.ts +1 -5
  51. package/dist/bdo.d.ts.map +1 -1
  52. package/dist/bdo.mjs +349 -230
  53. package/dist/bdo.types.d.ts +2 -3
  54. package/dist/bdo.types.d.ts.map +1 -1
  55. package/dist/client-Bo-RLKJi.cjs +1 -0
  56. package/dist/client-eA4VvNTo.js +178 -0
  57. package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
  58. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
  59. package/dist/components/hooks/useForm/createResolver.d.ts +12 -2
  60. package/dist/components/hooks/useForm/createResolver.d.ts.map +1 -1
  61. package/dist/components/hooks/useForm/index.d.ts +1 -1
  62. package/dist/components/hooks/useForm/index.d.ts.map +1 -1
  63. package/dist/components/hooks/useForm/types.d.ts +62 -6
  64. package/dist/components/hooks/useForm/types.d.ts.map +1 -1
  65. package/dist/components/hooks/useForm/useForm.d.ts +1 -27
  66. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  67. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  68. package/dist/{constants-DaX7GLgl.js → constants-CM9xOACN.js} +37 -13
  69. package/dist/constants-D0J69if5.cjs +1 -0
  70. package/dist/filter.cjs +1 -1
  71. package/dist/filter.mjs +2 -2
  72. package/dist/form.cjs +1 -1
  73. package/dist/form.d.ts +1 -1
  74. package/dist/form.d.ts.map +1 -1
  75. package/dist/form.mjs +879 -809
  76. package/dist/index.d.ts +1 -1
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/{metadata-Bz8zJqC1.cjs → metadata-BN57S6W9.cjs} +1 -1
  79. package/dist/{metadata-VbQzyD2C.js → metadata-P7DGCgIG.js} +1 -1
  80. package/dist/table.cjs +1 -1
  81. package/dist/table.mjs +74 -70
  82. package/dist/types/base-fields.d.ts +25 -60
  83. package/dist/types/base-fields.d.ts.map +1 -1
  84. package/dist/types/constants.d.ts +6 -0
  85. package/dist/types/constants.d.ts.map +1 -1
  86. package/dist/useFilter-Bg0jvIL6.cjs +1 -0
  87. package/dist/useFilter-DPNLKY3H.js +118 -0
  88. package/dist/utils/formatting.d.ts +10 -1
  89. package/dist/utils/formatting.d.ts.map +1 -1
  90. package/docs/api.md +140 -572
  91. package/docs/bdo.md +742 -0
  92. package/docs/useAuth.md +10 -4
  93. package/docs/useFilter.md +40 -40
  94. package/docs/useForm.md +91 -62
  95. package/docs/useTable.md +38 -38
  96. package/package.json +1 -1
  97. package/sdk/api/client.ts +52 -65
  98. package/sdk/api/metadata.ts +22 -20
  99. package/sdk/base-types.ts +9 -9
  100. package/sdk/bdo/core/BaseBdo.ts +13 -38
  101. package/sdk/bdo/core/Item.ts +34 -56
  102. package/sdk/bdo/core/types.ts +147 -45
  103. package/sdk/bdo/fields/ArrayField.ts +9 -5
  104. package/sdk/bdo/fields/BaseField.ts +19 -29
  105. package/sdk/bdo/fields/BooleanField.ts +4 -5
  106. package/sdk/bdo/fields/DateField.ts +55 -0
  107. package/sdk/bdo/fields/DateTimeField.ts +9 -5
  108. package/sdk/bdo/fields/FileField.ts +39 -0
  109. package/sdk/bdo/fields/NumberField.ts +8 -5
  110. package/sdk/bdo/fields/ObjectField.ts +46 -0
  111. package/sdk/bdo/fields/ReferenceField.ts +22 -28
  112. package/sdk/bdo/fields/SelectField.ts +15 -28
  113. package/sdk/bdo/fields/StringField.ts +10 -5
  114. package/sdk/bdo/fields/TextAreaField.ts +6 -0
  115. package/sdk/bdo/fields/TextField.ts +42 -0
  116. package/sdk/bdo/fields/UserField.ts +52 -0
  117. package/sdk/bdo/fields/index.ts +6 -0
  118. package/sdk/bdo/index.ts +19 -4
  119. package/sdk/bdo.ts +7 -28
  120. package/sdk/bdo.types.ts +26 -21
  121. package/sdk/components/hooks/useFilter/useFilter.ts +13 -30
  122. package/sdk/components/hooks/useForm/createItemProxy.ts +47 -11
  123. package/sdk/components/hooks/useForm/createResolver.ts +65 -6
  124. package/sdk/components/hooks/useForm/index.ts +3 -0
  125. package/sdk/components/hooks/useForm/types.ts +75 -6
  126. package/sdk/components/hooks/useForm/useForm.ts +35 -50
  127. package/sdk/components/hooks/useTable/useTable.ts +10 -2
  128. package/sdk/form.ts +1 -12
  129. package/sdk/index.ts +3 -3
  130. package/sdk/types/base-fields.ts +29 -73
  131. package/sdk/types/constants.ts +6 -0
  132. package/sdk/utils/formatting.ts +13 -1
  133. package/dist/client-BIkaIr2y.js +0 -217
  134. package/dist/client-DxjRcEtN.cjs +0 -1
  135. package/dist/constants-C49b9Exc.cjs +0 -1
  136. package/dist/useFilter-DzpP_ag0.cjs +0 -1
  137. package/dist/useFilter-H5bgAZQF.js +0 -120
package/dist/bdo.mjs CHANGED
@@ -1,39 +1,39 @@
1
- var N = Object.defineProperty;
2
- var y = (r, e, t) => e in r ? N(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
1
+ var b = Object.defineProperty;
2
+ var y = (r, e, t) => e in r ? b(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var n = (r, e, t) => y(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { a as u } from "./client-BIkaIr2y.js";
5
- import { d as V } from "./constants-DaX7GLgl.js";
6
- class h {
4
+ import { a as u } from "./client-eA4VvNTo.js";
5
+ import { d as L } from "./constants-CM9xOACN.js";
6
+ class f {
7
7
  constructor(e, t) {
8
8
  n(this, "_data");
9
9
  n(this, "_bdo");
10
10
  n(this, "_accessorCache", /* @__PURE__ */ new Map());
11
11
  return this._bdo = e, this._data = { ...t }, new Proxy(this, {
12
- get(i, s, a) {
13
- return s === "validate" || s === "toJSON" || s === "_bdo" || s === "_data" || s === "_accessorCache" || s === "_getAccessor" || typeof s == "symbol" ? Reflect.get(i, s, a) : s === "_id" ? i._data._id : i._getAccessor(s);
12
+ get(s, a, i) {
13
+ return a === "validate" || a === "toJSON" || a === "_bdo" || a === "_data" || a === "_accessorCache" || a === "_getAccessor" || typeof a == "symbol" ? Reflect.get(s, a, i) : a === "_id" ? s._data._id : s._getAccessor(a);
14
14
  },
15
- set(i, s, a) {
16
- return s === "_bdo" || s === "_data" || s === "_accessorCache" || s === "validate" || s === "toJSON" ? !1 : typeof s == "symbol" ? Reflect.set(i, s, a) : (i._data[s] = a, !0);
15
+ set(s, a, i) {
16
+ return a === "_bdo" || a === "_data" || a === "_accessorCache" || a === "validate" || a === "toJSON" ? !1 : typeof a == "symbol" ? Reflect.set(s, a, i) : (s._data[a] = i, !0);
17
17
  },
18
- has(i, s) {
19
- return s === "validate" || s === "toJSON" ? !0 : s in i._data || s in i._bdo.getFields();
18
+ has(s, a) {
19
+ return a === "validate" || a === "toJSON" ? !0 : a in s._data || a in s._bdo.getFields();
20
20
  },
21
- ownKeys(i) {
22
- return [...Object.keys(i._bdo.getFields()), "validate", "toJSON"];
21
+ ownKeys(s) {
22
+ return [...Object.keys(s._bdo.getFields()), "validate", "toJSON"];
23
23
  },
24
- getOwnPropertyDescriptor(i, s) {
25
- if (s === "validate" || s === "toJSON")
24
+ getOwnPropertyDescriptor(s, a) {
25
+ if (a === "validate" || a === "toJSON")
26
26
  return {
27
27
  configurable: !0,
28
28
  enumerable: !1,
29
- value: i[s]
29
+ value: s[a]
30
30
  };
31
- const a = i._bdo.getFields();
32
- if (s in a || s in i._data)
31
+ const i = s._bdo.getFields();
32
+ if (a in i || a in s._data)
33
33
  return {
34
34
  configurable: !0,
35
35
  enumerable: !0,
36
- get: () => i._getAccessor(s)
36
+ get: () => s._getAccessor(a)
37
37
  };
38
38
  }
39
39
  });
@@ -45,15 +45,15 @@ class h {
45
45
  _getAccessor(e) {
46
46
  if (this._accessorCache.has(e))
47
47
  return this._accessorCache.get(e);
48
- const i = this._bdo.getFields()[e], s = (i == null ? void 0 : i.meta) ?? {
49
- id: e,
50
- label: e,
51
- isEditable: !0
52
- }, a = s.isEditable, l = () => {
53
- if (i) {
54
- const d = i.validate(this._data[e]);
55
- if (!d.valid)
56
- return d;
48
+ const s = this._bdo.getFields()[e], a = (s == null ? void 0 : s.meta) ?? {
49
+ _id: e,
50
+ Name: e,
51
+ Type: "String"
52
+ }, i = (s == null ? void 0 : s.readOnly) ?? !1, o = () => {
53
+ if (s) {
54
+ const c = s.validate(this._data[e]);
55
+ if (!c.valid)
56
+ return c;
57
57
  }
58
58
  return this._bdo.hasMetadata() ? this._bdo.validateFieldExpression(
59
59
  e,
@@ -61,38 +61,47 @@ class h {
61
61
  this.toJSON()
62
62
  ) : { valid: !0, errors: [] };
63
63
  };
64
- let o;
65
- return a ? o = {
66
- meta: s,
64
+ let l;
65
+ return i ? l = {
66
+ label: (s == null ? void 0 : s.label) ?? e,
67
+ required: (s == null ? void 0 : s.required) ?? !1,
68
+ readOnly: !0,
69
+ defaultValue: s == null ? void 0 : s.defaultValue,
70
+ meta: a,
67
71
  get: () => this._data[e],
68
- set: (d) => {
69
- this._data[e] = d;
70
- },
71
- validate: l
72
- } : o = {
73
- meta: s,
72
+ validate: o
73
+ } : l = {
74
+ label: (s == null ? void 0 : s.label) ?? e,
75
+ required: (s == null ? void 0 : s.required) ?? !1,
76
+ readOnly: !1,
77
+ defaultValue: s == null ? void 0 : s.defaultValue,
78
+ meta: a,
74
79
  get: () => this._data[e],
75
- validate: l
76
- }, this._accessorCache.set(e, o), o;
80
+ set: (c) => {
81
+ this._data[e] = c;
82
+ },
83
+ validate: o
84
+ }, this._accessorCache.set(e, l), l;
77
85
  }
78
86
  /**
79
87
  * Validate all fields and return combined results
80
88
  */
81
89
  validate() {
82
- const e = this._bdo.getFields(), t = [], i = this.toJSON();
83
- for (const [s, a] of Object.entries(e)) {
84
- const l = this._data[s], o = a.validate(l);
85
- if (!o.valid) {
86
- t.push(...o.errors);
90
+ const e = this._bdo.getFields(), t = [], s = this.toJSON();
91
+ for (const [a, i] of Object.entries(e)) {
92
+ if (i.readOnly) continue;
93
+ const o = this._data[a], l = i.validate(o);
94
+ if (!l.valid) {
95
+ t.push(...l.errors);
87
96
  continue;
88
97
  }
89
98
  if (this._bdo.hasMetadata()) {
90
- const d = this._bdo.validateFieldExpression(
91
- s,
92
- l,
93
- i
99
+ const c = this._bdo.validateFieldExpression(
100
+ a,
101
+ o,
102
+ s
94
103
  );
95
- d.valid || t.push(...d.errors);
104
+ c.valid || t.push(...c.errors);
96
105
  }
97
106
  }
98
107
  return {
@@ -107,29 +116,49 @@ class h {
107
116
  return { ...this._data };
108
117
  }
109
118
  }
110
- class f {
119
+ class d {
111
120
  constructor(e) {
112
- n(this, "id");
113
- n(this, "label");
114
- n(this, "editable");
121
+ /** Full raw backend meta */
122
+ n(this, "_meta");
115
123
  n(this, "_parentBoId");
116
- this.id = e.id, this.label = e.label, this.editable = e.editable ?? !0;
124
+ this._meta = e;
117
125
  }
118
- /**
119
- * Get field metadata (id, label, and field-specific info)
120
- */
126
+ // === Convenience getters (transform backend naming → SDK naming) ===
127
+ get id() {
128
+ return this._meta._id;
129
+ }
130
+ get label() {
131
+ return this._meta.Name || this._meta._id;
132
+ }
133
+ get readOnly() {
134
+ return this._meta.ReadOnly ?? !1;
135
+ }
136
+ get required() {
137
+ var e;
138
+ return ((e = this._meta.Constraint) == null ? void 0 : e.Required) ?? this._meta.Required ?? !1;
139
+ }
140
+ get defaultValue() {
141
+ var e;
142
+ return this._meta.DefaultValue ?? ((e = this._meta.Constraint) == null ? void 0 : e.DefaultValue);
143
+ }
144
+ get primaryKey() {
145
+ var e;
146
+ return ((e = this._meta.Constraint) == null ? void 0 : e.PrimaryKey) ?? !1;
147
+ }
148
+ /** Full raw meta (the exact JSON passed to constructor) */
121
149
  get meta() {
122
- return {
123
- id: this.id,
124
- label: this.label,
125
- isEditable: this.editable
126
- };
150
+ return this._meta;
127
151
  }
128
152
  }
129
- class m extends f {
153
+ class h extends d {
130
154
  constructor(e) {
131
155
  super(e);
132
156
  }
157
+ /** String-specific: max length constraint */
158
+ get length() {
159
+ var e;
160
+ return (e = this._meta.Constraint) == null ? void 0 : e.Length;
161
+ }
133
162
  validate(e) {
134
163
  return e != null && typeof e != "string" ? {
135
164
  valid: !1,
@@ -137,10 +166,15 @@ class m extends f {
137
166
  } : { valid: !0, errors: [] };
138
167
  }
139
168
  }
140
- class b extends f {
169
+ class _ extends d {
141
170
  constructor(e) {
142
171
  super(e);
143
172
  }
173
+ /** DateTime-specific: precision */
174
+ get precision() {
175
+ var e;
176
+ return ((e = this._meta.Constraint) == null ? void 0 : e.Precision) ?? "Second";
177
+ }
144
178
  validate(e) {
145
179
  if (e == null || e === "")
146
180
  return { valid: !0, errors: [] };
@@ -156,53 +190,31 @@ class b extends f {
156
190
  } : { valid: !0, errors: [] };
157
191
  }
158
192
  }
159
- class _ extends f {
160
- constructor(t) {
161
- super(t);
162
- n(this, "referenceBdo");
163
- n(this, "referenceFields");
164
- this.referenceBdo = t.referenceBdo, this.referenceFields = t.referenceFields ?? ["_id"];
165
- }
166
- validate(t) {
167
- if (t == null)
193
+ class g extends d {
194
+ constructor(e) {
195
+ super(e);
196
+ }
197
+ /** Business entity ID for user lookup */
198
+ get businessEntity() {
199
+ var e;
200
+ return (e = this._meta.View) == null ? void 0 : e.BusinessEntity;
201
+ }
202
+ validate(e) {
203
+ if (e == null)
168
204
  return { valid: !0, errors: [] };
169
- if (typeof t != "object")
205
+ if (typeof e != "object")
170
206
  return {
171
207
  valid: !1,
172
- errors: [`${this.label} must be a valid reference object`]
208
+ errors: [`${this.label} must be a valid user object`]
173
209
  };
174
- const i = t;
175
- return !("_id" in i) || typeof i._id != "string" ? {
210
+ const t = e;
211
+ return !("_id" in t) || typeof t._id != "string" ? {
176
212
  valid: !1,
177
213
  errors: [`${this.label} must have a valid _id`]
178
214
  } : { valid: !0, errors: [] };
179
215
  }
180
- /**
181
- * Fetch referenced records from the backend, returned as typed TRef[]
182
- */
183
- async fetchOptions(t) {
184
- if (!this._parentBoId)
185
- throw new Error(
186
- `Field ${this.id} not bound to a BDO. Cannot fetch options.`
187
- );
188
- return u(this._parentBoId).fetchField(t ?? "new", this.id);
189
- }
190
- /**
191
- * Get field metadata including reference info
192
- */
193
- get meta() {
194
- return {
195
- id: this.id,
196
- label: this.label,
197
- isEditable: this.editable,
198
- reference: {
199
- bdo: this.referenceBdo,
200
- fields: [...this.referenceFields]
201
- }
202
- };
203
- }
204
216
  }
205
- const p = {
217
+ const N = {
206
218
  // ============================================================
207
219
  // STRING FUNCTIONS (7)
208
220
  // ============================================================
@@ -261,7 +273,7 @@ const p = {
261
273
  */
262
274
  AVG: (...r) => {
263
275
  const e = r.filter((t) => t != null && !isNaN(Number(t)));
264
- return e.length === 0 ? 0 : e.reduce((t, i) => t + Number(i), 0) / e.length;
276
+ return e.length === 0 ? 0 : e.reduce((t, s) => t + Number(s), 0) / e.length;
265
277
  },
266
278
  /**
267
279
  * Get minimum value
@@ -331,10 +343,10 @@ const p = {
331
343
  * @example DATE_DIFF("2024-01-15", "2024-01-10") => 5
332
344
  */
333
345
  DATE_DIFF: (r, e) => {
334
- const t = new Date(r), i = new Date(e);
335
- if (isNaN(t.getTime()) || isNaN(i.getTime())) return 0;
336
- const s = Math.abs(t.getTime() - i.getTime());
337
- return Math.ceil(s / (1e3 * 60 * 60 * 24));
346
+ const t = new Date(r), s = new Date(e);
347
+ if (isNaN(t.getTime()) || isNaN(s.getTime())) return 0;
348
+ const a = Math.abs(t.getTime() - s.getTime());
349
+ return Math.ceil(a / (1e3 * 60 * 60 * 24));
338
350
  },
339
351
  /**
340
352
  * Add days to a date
@@ -372,7 +384,7 @@ const p = {
372
384
  return (r === "x" ? e : e & 3 | 8).toString(16);
373
385
  })
374
386
  };
375
- function v() {
387
+ function p() {
376
388
  const r = /* @__PURE__ */ new Date();
377
389
  return {
378
390
  NOW: r,
@@ -387,7 +399,7 @@ function v() {
387
399
  }
388
400
  };
389
401
  }
390
- function c(r, e) {
402
+ function m(r, e) {
391
403
  var t;
392
404
  switch (r.Type) {
393
405
  case "Literal":
@@ -395,88 +407,88 @@ function c(r, e) {
395
407
  case "Identifier":
396
408
  return e.formValues[r.Name];
397
409
  case "SystemIdentifier":
398
- return w(r, e);
410
+ return v(r, e);
399
411
  case "BinaryExpression":
400
412
  return x(r, e);
401
413
  case "LogicalExpression":
402
- return E(r, e);
414
+ return w(r, e);
403
415
  case "CallExpression":
404
- return F(r, e);
416
+ return O(r, e);
405
417
  case "MemberExpression":
406
- return A(r, e);
418
+ return E(r, e);
407
419
  case "AssignmentExpression":
408
- return ((t = r.Arguments) == null ? void 0 : t.length) === 1 ? c(r.Arguments[0], e) : void 0;
420
+ return ((t = r.Arguments) == null ? void 0 : t.length) === 1 ? m(r.Arguments[0], e) : void 0;
409
421
  default:
410
422
  throw new Error(`Unsupported expression type: ${r.Type}`);
411
423
  }
412
424
  }
413
- function w(r, e) {
414
- const t = r.Name, i = e.systemValues[t];
415
- return r.Property ? i && typeof i == "object" ? i[r.Property.Name] : void 0 : i;
425
+ function v(r, e) {
426
+ const t = r.Name, s = e.systemValues[t];
427
+ return r.Property ? s && typeof s == "object" ? s[r.Property.Name] : void 0 : s;
416
428
  }
417
429
  function x(r, e) {
418
430
  if (!r.Arguments || r.Arguments.length < 2)
419
431
  throw new Error("BinaryExpression requires 2 arguments");
420
- const [t, i] = r.Arguments, s = c(t, e), a = c(i, e);
432
+ const [t, s] = r.Arguments, a = m(t, e), i = m(s, e);
421
433
  switch (r.Operator) {
422
434
  case "==":
423
- return s == a;
435
+ return a == i;
424
436
  case "!=":
425
- return s != a;
437
+ return a != i;
426
438
  case "<":
427
- return Number(s) < Number(a);
439
+ return Number(a) < Number(i);
428
440
  case "<=":
429
- return Number(s) <= Number(a);
441
+ return Number(a) <= Number(i);
430
442
  case ">":
431
- return Number(s) > Number(a);
443
+ return Number(a) > Number(i);
432
444
  case ">=":
433
- return Number(s) >= Number(a);
445
+ return Number(a) >= Number(i);
434
446
  case "+":
435
- return Number(s) + Number(a);
447
+ return Number(a) + Number(i);
436
448
  case "-":
437
- return Number(s) - Number(a);
449
+ return Number(a) - Number(i);
438
450
  case "*":
439
- return Number(s) * Number(a);
451
+ return Number(a) * Number(i);
440
452
  case "/":
441
- return Number(a) !== 0 ? Number(s) / Number(a) : 0;
453
+ return Number(i) !== 0 ? Number(a) / Number(i) : 0;
442
454
  case "%":
443
- return Number(s) % Number(a);
455
+ return Number(a) % Number(i);
444
456
  default:
445
457
  throw new Error(`Unsupported binary operator: ${r.Operator}`);
446
458
  }
447
459
  }
448
- function E(r, e) {
460
+ function w(r, e) {
449
461
  if (!r.Arguments || r.Arguments.length === 0)
450
462
  throw new Error("LogicalExpression requires at least 1 argument");
451
463
  const t = r.Arguments;
452
464
  switch (r.Operator) {
453
465
  case "AND":
454
- return t.every((i) => !!c(i, e));
466
+ return t.every((s) => !!m(s, e));
455
467
  case "OR":
456
- return t.some((i) => !!c(i, e));
468
+ return t.some((s) => !!m(s, e));
457
469
  case "!":
458
- return !c(t[0], e);
470
+ return !m(t[0], e);
459
471
  default:
460
472
  throw new Error(`Unsupported logical operator: ${r.Operator}`);
461
473
  }
462
474
  }
463
- function F(r, e) {
475
+ function O(r, e) {
464
476
  if (!r.Callee)
465
477
  throw new Error("CallExpression requires a Callee");
466
- const t = p[r.Callee];
478
+ const t = N[r.Callee];
467
479
  if (!t)
468
480
  throw new Error(`Unknown function: ${r.Callee}`);
469
- const i = (r.Arguments ?? []).map((s) => c(s, e));
470
- return t(...i);
481
+ const s = (r.Arguments ?? []).map((a) => m(a, e));
482
+ return t(...s);
471
483
  }
472
- function A(r, e) {
473
- var s, a;
474
- if (!((s = r.Arguments) != null && s.length))
484
+ function E(r, e) {
485
+ var a, i;
486
+ if (!((a = r.Arguments) != null && a.length))
475
487
  return;
476
- const t = c(r.Arguments[0], e), i = (a = r.Arguments[0].Property) == null ? void 0 : a.Name;
477
- return i && t && typeof t == "object" ? t[i] : t;
488
+ const t = m(r.Arguments[0], e), s = (i = r.Arguments[0].Property) == null ? void 0 : i.Name;
489
+ return s && t && typeof t == "object" ? t[s] : t;
478
490
  }
479
- class D {
491
+ class F {
480
492
  constructor() {
481
493
  /**
482
494
  * Map of field ID to its validation rules
@@ -498,20 +510,20 @@ class D {
498
510
  * @param metadata - The BDO metadata from the backend
499
511
  */
500
512
  loadMetadata(e) {
501
- var t, i;
513
+ var t, s;
502
514
  this.metadata = e, this.fieldRules.clear();
503
- for (const [s, a] of Object.entries(e.Fields)) {
504
- const l = [];
505
- if (a.Validation && Array.isArray(a.Validation)) {
506
- for (const o of a.Validation)
507
- if (typeof o == "object" && o.ExpressionTree)
508
- l.push(o);
509
- else if (typeof o == "string") {
510
- const d = (i = (t = e.Rules) == null ? void 0 : t.Validation) == null ? void 0 : i[o];
511
- d && l.push(d);
515
+ for (const [a, i] of Object.entries(e.Fields)) {
516
+ const o = [];
517
+ if (i.Validation && Array.isArray(i.Validation)) {
518
+ for (const l of i.Validation)
519
+ if (typeof l == "object" && l.ExpressionTree)
520
+ o.push(l);
521
+ else if (typeof l == "string") {
522
+ const c = (s = (t = e.Rules) == null ? void 0 : t.Validation) == null ? void 0 : s[l];
523
+ c && o.push(c);
512
524
  }
513
525
  }
514
- l.length > 0 && this.fieldRules.set(s, l);
526
+ o.length > 0 && this.fieldRules.set(a, o);
515
527
  }
516
528
  }
517
529
  /**
@@ -543,25 +555,25 @@ class D {
543
555
  * @param allValues - All form field values (for cross-field validation)
544
556
  * @returns ValidationResult with valid=true if all rules pass
545
557
  */
546
- validateField(e, t, i) {
547
- const s = this.fieldRules.get(e);
548
- if (!s || s.length === 0)
558
+ validateField(e, t, s) {
559
+ const a = this.fieldRules.get(e);
560
+ if (!a || a.length === 0)
549
561
  return { valid: !0, errors: [] };
550
- const a = {
551
- formValues: { ...i, [e]: t },
552
- systemValues: v()
562
+ const i = {
563
+ formValues: { ...s, [e]: t },
564
+ systemValues: p()
553
565
  };
554
- for (const l of s)
566
+ for (const o of a)
555
567
  try {
556
- if (!c(l.ExpressionTree, a))
568
+ if (!m(o.ExpressionTree, i))
557
569
  return {
558
570
  valid: !1,
559
- errors: [l.Message || `Validation failed: ${l.Name || l.Id}`]
571
+ errors: [o.Message || `Validation failed: ${o.Name || o.Id}`]
560
572
  };
561
- } catch (o) {
573
+ } catch (l) {
562
574
  console.warn(
563
- `Expression evaluation failed for rule ${l.Id}:`,
564
- o
575
+ `Expression evaluation failed for rule ${o.Id}:`,
576
+ l
565
577
  );
566
578
  }
567
579
  return { valid: !0, errors: [] };
@@ -577,9 +589,9 @@ class D {
577
589
  */
578
590
  validateAll(e) {
579
591
  const t = [];
580
- for (const i of this.fieldRules.keys()) {
581
- const s = this.validateField(i, e[i], e);
582
- s.valid || t.push(...s.errors);
592
+ for (const s of this.fieldRules.keys()) {
593
+ const a = this.validateField(s, e[s], e);
594
+ a.valid || t.push(...a.errors);
583
595
  }
584
596
  return {
585
597
  valid: t.length === 0,
@@ -587,29 +599,18 @@ class D {
587
599
  };
588
600
  }
589
601
  }
590
- const g = "SYS_User";
591
- class S {
602
+ class C {
592
603
  constructor() {
593
604
  // ============================================================
594
605
  // SYSTEM FIELDS (inherited by all BDOs)
595
606
  // ============================================================
596
- n(this, "_id", new m({ id: "_id", label: "ID" }));
597
- n(this, "_created_at", new b({ id: "_created_at", label: "Created At" }));
598
- n(this, "_modified_at", new b({ id: "_modified_at", label: "Modified At" }));
599
- n(this, "_created_by", new _({
600
- id: "_created_by",
601
- label: "Created By",
602
- referenceBdo: g,
603
- referenceFields: ["_id", "username"]
604
- }));
605
- n(this, "_modified_by", new _({
606
- id: "_modified_by",
607
- label: "Modified By",
608
- referenceBdo: g,
609
- referenceFields: ["_id", "username"]
610
- }));
611
- n(this, "_version", new m({ id: "_version", label: "Version" }));
612
- n(this, "_m_version", new m({ id: "_m_version", label: "Metadata Version" }));
607
+ n(this, "_id", new h({ _id: "_id", Name: "ID", Type: "String", ReadOnly: !0 }));
608
+ n(this, "_created_at", new _({ _id: "_created_at", Name: "Created At", Type: "DateTime", ReadOnly: !0 }));
609
+ n(this, "_modified_at", new _({ _id: "_modified_at", Name: "Modified At", Type: "DateTime", ReadOnly: !0 }));
610
+ n(this, "_created_by", new g({ _id: "_created_by", Name: "Created By", Type: "User", ReadOnly: !0 }));
611
+ n(this, "_modified_by", new g({ _id: "_modified_by", Name: "Modified By", Type: "User", ReadOnly: !0 }));
612
+ n(this, "_version", new h({ _id: "_version", Name: "Version", Type: "String", ReadOnly: !0 }));
613
+ n(this, "_m_version", new h({ _id: "_m_version", Name: "Metadata Version", Type: "String", ReadOnly: !0 }));
613
614
  // ============================================================
614
615
  // FIELD DEFINITIONS (auto-discovered)
615
616
  // ============================================================
@@ -627,7 +628,7 @@ class S {
627
628
  /**
628
629
  * Expression engine instance for evaluating backend validation rules
629
630
  */
630
- n(this, "_expressionEngine", new D());
631
+ n(this, "_expressionEngine", new F());
631
632
  }
632
633
  /**
633
634
  * Get all field definitions (system + business) with automatic binding.
@@ -639,8 +640,8 @@ class S {
639
640
  return this._fieldsCache;
640
641
  const e = {};
641
642
  for (const t of Object.keys(this)) {
642
- const i = this[t];
643
- i instanceof f && (e[t] = i);
643
+ const s = this[t];
644
+ s instanceof d && (e[t] = s);
644
645
  }
645
646
  if (!this._fieldsBound) {
646
647
  for (const t of Object.values(e))
@@ -681,8 +682,8 @@ class S {
681
682
  * @param allValues - All form field values (for cross-field validation)
682
683
  * @returns ValidationResultType from expression evaluation
683
684
  */
684
- validateFieldExpression(e, t, i) {
685
- return this._expressionEngine.hasMetadata() ? this._expressionEngine.validateField(e, t, i) : { valid: !0, errors: [] };
685
+ validateFieldExpression(e, t, s) {
686
+ return this._expressionEngine.hasMetadata() ? this._expressionEngine.validateField(e, t, s) : { valid: !0, errors: [] };
686
687
  }
687
688
  // ============================================================
688
689
  // READ OPERATIONS
@@ -692,14 +693,14 @@ class S {
692
693
  */
693
694
  async get(e) {
694
695
  const t = await u(this.meta._id).get(e);
695
- return new h(this, t);
696
+ return new f(this, t);
696
697
  }
697
698
  /**
698
699
  * List records with optional filtering, sorting, and pagination
699
700
  */
700
701
  async list(e) {
701
702
  return (await u(this.meta._id).list(e)).Data.map(
702
- (i) => new h(this, i)
703
+ (s) => new f(this, s)
703
704
  );
704
705
  }
705
706
  /**
@@ -717,7 +718,7 @@ class S {
717
718
  */
718
719
  async create(e) {
719
720
  const t = await u(this.meta._id).create(e);
720
- return new h(
721
+ return new f(
721
722
  this,
722
723
  { ...e, _id: t._id }
723
724
  );
@@ -761,7 +762,7 @@ class S {
761
762
  * Use this when you need get/set/validate methods on fields
762
763
  */
763
764
  createItem(e) {
764
- return new h(this, e ?? {});
765
+ return new f(this, e ?? {});
765
766
  }
766
767
  /**
767
768
  * Patch an existing draft - compute fields during editing
@@ -785,10 +786,18 @@ class S {
785
786
  return u(this.meta._id).pivot(e);
786
787
  }
787
788
  }
788
- class B extends f {
789
+ class R extends d {
789
790
  constructor(e) {
790
791
  super(e);
791
792
  }
793
+ get integerPart() {
794
+ var e;
795
+ return ((e = this._meta.Constraint) == null ? void 0 : e.IntegerPart) ?? 9;
796
+ }
797
+ get fractionPart() {
798
+ var e;
799
+ return (e = this._meta.Constraint) == null ? void 0 : e.FractionPart;
800
+ }
792
801
  validate(e) {
793
802
  return e != null && (typeof e != "number" || isNaN(e)) ? {
794
803
  valid: !1,
@@ -796,7 +805,7 @@ class B extends f {
796
805
  } : { valid: !0, errors: [] };
797
806
  }
798
807
  }
799
- class C extends f {
808
+ class M extends d {
800
809
  constructor(e) {
801
810
  super(e);
802
811
  }
@@ -807,55 +816,116 @@ class C extends f {
807
816
  } : { valid: !0, errors: [] };
808
817
  }
809
818
  }
810
- class R extends f {
811
- constructor(t) {
812
- super(t);
813
- n(this, "options");
814
- this.options = t.options;
815
- }
816
- validate(t) {
817
- if (t == null || t === "")
819
+ class S extends d {
820
+ constructor(e) {
821
+ super(e);
822
+ }
823
+ validate(e) {
824
+ if (e == null || e === "")
825
+ return { valid: !0, errors: [] };
826
+ if (typeof e != "string")
827
+ return {
828
+ valid: !1,
829
+ errors: [`${this.label} must be a valid date string`]
830
+ };
831
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(e))
832
+ return {
833
+ valid: !1,
834
+ errors: [`${this.label} must be in YYYY-MM-DD format`]
835
+ };
836
+ const t = /* @__PURE__ */ new Date(e + "T00:00:00");
837
+ return isNaN(t.getTime()) ? {
838
+ valid: !1,
839
+ errors: [`${this.label} is not a valid date`]
840
+ } : { valid: !0, errors: [] };
841
+ }
842
+ }
843
+ class D extends d {
844
+ constructor(e) {
845
+ super(e);
846
+ }
847
+ /** Static options derived from Constraint.Enum */
848
+ get options() {
849
+ var t;
850
+ return (((t = this._meta.Constraint) == null ? void 0 : t.Enum) ?? []).map((s) => ({ value: s, label: s }));
851
+ }
852
+ validate(e) {
853
+ if (e == null || e === "")
818
854
  return { valid: !0, errors: [] };
819
855
  if (this.options.length === 0)
820
856
  return { valid: !0, errors: [] };
821
- const i = this.options.map((s) => s.value);
822
- return i.includes(t) ? { valid: !0, errors: [] } : {
857
+ const t = this.options.map((s) => s.value);
858
+ return t.includes(e) ? { valid: !0, errors: [] } : {
823
859
  valid: !1,
824
- errors: [`${this.label} must be one of: ${i.join(", ")}`]
860
+ errors: [`${this.label} must be one of: ${t.join(", ")}`]
825
861
  };
826
862
  }
827
863
  /**
828
864
  * Fetch dynamic options from the backend, returned as typed SelectOption[]
829
865
  */
830
- async fetchOptions(t) {
866
+ async fetchOptions(e) {
831
867
  if (!this._parentBoId)
832
868
  throw new Error(
833
869
  `Field ${this.id} not bound to a BDO. Cannot fetch options.`
834
870
  );
835
871
  return (await u(this._parentBoId).fetchField(
836
- t ?? "new",
872
+ e ?? "new",
837
873
  this.id
838
874
  )).map((s) => ({
839
875
  value: s.Value,
840
876
  label: s.Label
841
877
  }));
842
878
  }
879
+ }
880
+ class V extends d {
881
+ constructor(e) {
882
+ super(e);
883
+ }
884
+ get referenceBdo() {
885
+ var e, t;
886
+ return ((t = (e = this._meta.View) == null ? void 0 : e.DataObject) == null ? void 0 : t.Id) ?? "";
887
+ }
888
+ get referenceFields() {
889
+ var e;
890
+ return ((e = this._meta.View) == null ? void 0 : e.Fields) ?? ["_id"];
891
+ }
892
+ get searchFields() {
893
+ var e;
894
+ return ((e = this._meta.View) == null ? void 0 : e.Search) ?? [];
895
+ }
896
+ validate(e) {
897
+ if (e == null)
898
+ return { valid: !0, errors: [] };
899
+ if (typeof e != "object")
900
+ return {
901
+ valid: !1,
902
+ errors: [`${this.label} must be a valid reference object`]
903
+ };
904
+ const t = e;
905
+ return !("_id" in t) || typeof t._id != "string" ? {
906
+ valid: !1,
907
+ errors: [`${this.label} must have a valid _id`]
908
+ } : { valid: !0, errors: [] };
909
+ }
843
910
  /**
844
- * Get field metadata including static options
911
+ * Fetch referenced records from the backend, returned as typed TRef[]
845
912
  */
846
- get meta() {
847
- return {
848
- id: this.id,
849
- label: this.label,
850
- isEditable: this.editable,
851
- options: this.options
852
- };
913
+ async fetchOptions(e) {
914
+ if (!this._parentBoId)
915
+ throw new Error(
916
+ `Field ${this.id} not bound to a BDO. Cannot fetch options.`
917
+ );
918
+ return u(this._parentBoId).fetchField(e ?? "new", this.id);
853
919
  }
854
920
  }
855
- class T extends f {
921
+ class B extends d {
856
922
  constructor(e) {
857
923
  super(e);
858
924
  }
925
+ /** Element type descriptor for array items */
926
+ get elementType() {
927
+ return this._meta.Property;
928
+ }
859
929
  validate(e) {
860
930
  return e != null && !Array.isArray(e) ? {
861
931
  valid: !1,
@@ -863,14 +933,63 @@ class T extends f {
863
933
  } : { valid: !0, errors: [] };
864
934
  }
865
935
  }
936
+ class $ extends d {
937
+ constructor(e) {
938
+ super(e);
939
+ }
940
+ /** Nested property definitions */
941
+ get properties() {
942
+ return this._meta.Property;
943
+ }
944
+ validate(e) {
945
+ return e == null ? { valid: !0, errors: [] } : typeof e != "object" || Array.isArray(e) ? {
946
+ valid: !1,
947
+ errors: [`${this.label} must be a valid object`]
948
+ } : { valid: !0, errors: [] };
949
+ }
950
+ }
951
+ class j extends d {
952
+ constructor(e) {
953
+ super(e);
954
+ }
955
+ /** Text-specific: format */
956
+ get format() {
957
+ var e;
958
+ return ((e = this._meta.Constraint) == null ? void 0 : e.Format) ?? "Plain";
959
+ }
960
+ validate(e) {
961
+ return e != null && typeof e != "string" ? {
962
+ valid: !1,
963
+ errors: [`${this.label} must be a string`]
964
+ } : { valid: !0, errors: [] };
965
+ }
966
+ }
967
+ class U extends d {
968
+ constructor(e) {
969
+ super(e);
970
+ }
971
+ validate(e) {
972
+ return e == null ? { valid: !0, errors: [] } : typeof e != "object" || Array.isArray(e) ? {
973
+ valid: !1,
974
+ errors: [`${this.label} must be a valid file object`]
975
+ } : { valid: !0, errors: [] };
976
+ }
977
+ }
866
978
  export {
867
- T as ArrayField,
868
- S as BaseBdo,
869
- C as BooleanField,
870
- b as DateTimeField,
871
- B as NumberField,
872
- _ as ReferenceField,
873
- R as SelectField,
874
- m as StringField,
875
- V as SystemField
979
+ B as ArrayField,
980
+ C as BaseBdo,
981
+ d as BaseField,
982
+ M as BooleanField,
983
+ S as DateField,
984
+ _ as DateTimeField,
985
+ U as FileField,
986
+ R as NumberField,
987
+ $ as ObjectField,
988
+ V as ReferenceField,
989
+ D as SelectField,
990
+ h as StringField,
991
+ L as SystemField,
992
+ j as TextAreaField,
993
+ j as TextField,
994
+ g as UserField
876
995
  };