@ram_28/kf-ai-sdk 2.0.1 → 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 (134) 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 +3 -4
  24. package/dist/bdo/fields/DateField.d.ts.map +1 -1
  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 +5 -4
  32. package/dist/bdo/fields/ObjectField.d.ts.map +1 -1
  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 +9 -16
  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 +1 -18
  40. package/dist/bdo/fields/TextAreaField.d.ts.map +1 -1
  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 +5 -2
  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 +312 -242
  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 +24 -59
  83. package/dist/types/base-fields.d.ts.map +1 -1
  84. package/dist/useFilter-Bg0jvIL6.cjs +1 -0
  85. package/dist/useFilter-DPNLKY3H.js +118 -0
  86. package/dist/utils/formatting.d.ts +10 -1
  87. package/dist/utils/formatting.d.ts.map +1 -1
  88. package/docs/api.md +140 -572
  89. package/docs/bdo.md +742 -0
  90. package/docs/useAuth.md +10 -4
  91. package/docs/useFilter.md +40 -40
  92. package/docs/useForm.md +91 -62
  93. package/docs/useTable.md +38 -38
  94. package/package.json +1 -1
  95. package/sdk/api/client.ts +52 -65
  96. package/sdk/api/metadata.ts +22 -20
  97. package/sdk/base-types.ts +5 -9
  98. package/sdk/bdo/core/BaseBdo.ts +13 -38
  99. package/sdk/bdo/core/Item.ts +34 -56
  100. package/sdk/bdo/core/types.ts +147 -45
  101. package/sdk/bdo/fields/ArrayField.ts +9 -5
  102. package/sdk/bdo/fields/BaseField.ts +19 -29
  103. package/sdk/bdo/fields/BooleanField.ts +4 -5
  104. package/sdk/bdo/fields/DateField.ts +4 -5
  105. package/sdk/bdo/fields/DateTimeField.ts +9 -5
  106. package/sdk/bdo/fields/FileField.ts +39 -0
  107. package/sdk/bdo/fields/NumberField.ts +8 -5
  108. package/sdk/bdo/fields/ObjectField.ts +9 -5
  109. package/sdk/bdo/fields/ReferenceField.ts +22 -28
  110. package/sdk/bdo/fields/SelectField.ts +13 -26
  111. package/sdk/bdo/fields/StringField.ts +10 -5
  112. package/sdk/bdo/fields/TextAreaField.ts +3 -32
  113. package/sdk/bdo/fields/TextField.ts +42 -0
  114. package/sdk/bdo/fields/UserField.ts +52 -0
  115. package/sdk/bdo/fields/index.ts +5 -2
  116. package/sdk/bdo/index.ts +19 -4
  117. package/sdk/bdo.ts +4 -31
  118. package/sdk/bdo.types.ts +26 -21
  119. package/sdk/components/hooks/useFilter/useFilter.ts +13 -30
  120. package/sdk/components/hooks/useForm/createItemProxy.ts +47 -11
  121. package/sdk/components/hooks/useForm/createResolver.ts +65 -6
  122. package/sdk/components/hooks/useForm/index.ts +3 -0
  123. package/sdk/components/hooks/useForm/types.ts +75 -6
  124. package/sdk/components/hooks/useForm/useForm.ts +35 -50
  125. package/sdk/components/hooks/useTable/useTable.ts +10 -2
  126. package/sdk/form.ts +1 -12
  127. package/sdk/index.ts +3 -3
  128. package/sdk/types/base-fields.ts +28 -72
  129. package/sdk/utils/formatting.ts +13 -1
  130. package/dist/client-BIkaIr2y.js +0 -217
  131. package/dist/client-DxjRcEtN.cjs +0 -1
  132. package/dist/constants-C49b9Exc.cjs +0 -1
  133. package/dist/useFilter-DzpP_ag0.cjs +0 -1
  134. package/dist/useFilter-H5bgAZQF.js +0 -120
@@ -18,64 +18,166 @@ export interface ValidationResultType {
18
18
  errors: string[];
19
19
  }
20
20
 
21
- /**
22
- * Base field metadata — only id, label, and isEditable.
23
- * Specialized fields (SelectField, ReferenceField) extend this with their own properties.
24
- */
25
- export interface FieldMetaType {
26
- readonly id: string;
27
- readonly label: string;
28
- readonly isEditable: boolean;
21
+ // ============================================================
22
+ // RAW BACKEND META TYPES
23
+ // These represent the exact JSON shape from the backend,
24
+ // with _id injected by the generator.
25
+ // ============================================================
26
+
27
+ /** Base constraint shape shared by all field types */
28
+ export interface BaseConstraintType {
29
+ Required?: boolean;
30
+ PrimaryKey?: boolean;
31
+ DefaultValue?: unknown;
29
32
  }
30
33
 
31
- /**
32
- * SelectField meta — extends FieldMetaType with static options
33
- */
34
- export interface SelectFieldMetaType<T extends string | number = string> extends FieldMetaType {
35
- readonly options: readonly SelectOptionType<T>[];
34
+ /** Base field meta — raw backend shape + injected _id */
35
+ export interface BaseFieldMetaType {
36
+ _id: string;
37
+ Name: string;
38
+ Type: string;
39
+ ReadOnly?: boolean;
40
+ Required?: boolean;
41
+ Constraint?: BaseConstraintType;
42
+ DefaultValue?: unknown;
36
43
  }
37
44
 
38
- /**
39
- * ReferenceField meta — extends FieldMetaType with reference info
40
- */
41
- export interface ReferenceFieldMetaType extends FieldMetaType {
42
- readonly reference: { bdo: string; fields: string[] };
45
+ export interface StringFieldMetaType extends BaseFieldMetaType {
46
+ Type: "String";
47
+ Constraint?: BaseConstraintType & {
48
+ Length?: number;
49
+ Enum?: string[];
50
+ };
51
+ DefaultValue?: string;
52
+ View?: {
53
+ DataObject?: { Type: string; Id: string };
54
+ Fields?: string[];
55
+ Search?: string[];
56
+ Filter?: Record<string, unknown>;
57
+ Sort?: unknown[];
58
+ };
43
59
  }
44
60
 
61
+ export interface TextFieldMetaType extends BaseFieldMetaType {
62
+ Type: "Text";
63
+ Constraint?: BaseConstraintType & {
64
+ Format?: "Plain" | "Markdown";
65
+ };
66
+ DefaultValue?: string;
67
+ }
45
68
 
46
- /**
47
- * Option for select fields
48
- */
49
- export interface SelectOptionType<T = string> {
50
- value: T;
51
- label: string;
52
- disabled?: boolean;
69
+ export interface NumberFieldMetaType extends BaseFieldMetaType {
70
+ Type: "Number";
71
+ Constraint?: BaseConstraintType & {
72
+ IntegerPart?: number;
73
+ FractionPart?: number;
74
+ };
75
+ DefaultValue?: number;
53
76
  }
54
77
 
55
- /**
56
- * Base configuration for all fields
57
- */
58
- export interface FieldConfigType {
59
- id: string;
60
- label: string;
61
- editable?: boolean;
78
+ export interface BooleanFieldMetaType extends BaseFieldMetaType {
79
+ Type: "Boolean";
80
+ Constraint?: BaseConstraintType;
81
+ DefaultValue?: boolean;
62
82
  }
63
83
 
64
- /**
65
- * Configuration for select fields with predefined options
66
- */
67
- export interface SelectFieldConfigType<T extends string | number = string> extends FieldConfigType {
68
- options: readonly SelectOptionType<T>[];
84
+ export interface DateFieldMetaType extends BaseFieldMetaType {
85
+ Type: "Date";
86
+ Constraint?: BaseConstraintType;
87
+ DefaultValue?: string;
88
+ }
89
+
90
+ export interface DateTimeFieldMetaType extends BaseFieldMetaType {
91
+ Type: "DateTime";
92
+ Constraint?: BaseConstraintType & {
93
+ Precision?: "Second" | "Millisecond";
94
+ };
95
+ DefaultValue?: string;
96
+ }
97
+
98
+ export interface SelectFieldMetaType extends BaseFieldMetaType {
99
+ Type: "String";
100
+ Constraint?: BaseConstraintType & {
101
+ Enum: string[];
102
+ };
103
+ DefaultValue?: string;
104
+ }
105
+
106
+ export interface ReferenceFieldMetaType extends BaseFieldMetaType {
107
+ Type: "Reference";
108
+ Constraint?: BaseConstraintType;
109
+ View?: {
110
+ DataObject: { Type: string; Id: string };
111
+ Fields?: string[];
112
+ Search?: string[];
113
+ Filter?: Record<string, unknown>;
114
+ Sort?: unknown[];
115
+ };
116
+ }
117
+
118
+ export interface UserFieldMetaType extends BaseFieldMetaType {
119
+ Type: "User";
120
+ Constraint?: BaseConstraintType;
121
+ View?: {
122
+ Filter?: Record<string, unknown>;
123
+ Sort?: unknown[];
124
+ BusinessEntity?: string;
125
+ };
126
+ }
127
+
128
+ export interface ArrayFieldMetaType extends BaseFieldMetaType {
129
+ Type: "Array";
130
+ Constraint?: BaseConstraintType;
131
+ Property?: BaseFieldMetaType;
132
+ }
133
+
134
+ export interface ObjectFieldMetaType extends BaseFieldMetaType {
135
+ Type: "Object";
136
+ Constraint?: BaseConstraintType;
137
+ Property?: Record<string, BaseFieldMetaType>;
138
+ }
139
+
140
+ export interface FileFieldMetaType extends BaseFieldMetaType {
141
+ Type: "File";
142
+ Constraint?: BaseConstraintType;
143
+ }
144
+
145
+ // ============================================================
146
+ // RUNTIME ACCESSOR TYPES
147
+ // These represent what item.Title looks like at runtime
148
+ // ============================================================
149
+
150
+ /** Base runtime accessor — every field accessor has these */
151
+ export interface BaseFieldAccessorType<T> {
152
+ readonly label: string;
153
+ readonly required: boolean;
154
+ readonly readOnly: boolean;
155
+ readonly defaultValue: unknown;
156
+ readonly meta: BaseFieldMetaType;
157
+ get(): T | undefined;
158
+ validate(): ValidationResultType;
159
+ }
160
+
161
+ /** Editable accessor adds set() */
162
+ export interface EditableFieldAccessorType<T> extends BaseFieldAccessorType<T> {
163
+ set(value: T): void;
69
164
  }
70
165
 
166
+ /** Readonly accessor has no set() */
167
+ export type ReadonlyFieldAccessorType<T> = BaseFieldAccessorType<T>;
168
+
169
+ /** Union of editable or readonly accessor */
170
+ export type FieldAccessorType<T> = EditableFieldAccessorType<T> | ReadonlyFieldAccessorType<T>;
171
+
172
+ // ============================================================
173
+ // SELECT FIELD OPTIONS
174
+ // ============================================================
175
+
71
176
  /**
72
- * Configuration for reference fields that link to other BDOs
177
+ * Option for select fields
73
178
  */
74
- export interface ReferenceFieldConfigType<
75
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
76
- _TRef = unknown,
77
- > extends FieldConfigType {
78
- referenceBdo: string;
79
- referenceFields?: readonly string[];
179
+ export interface SelectOptionType<T = string> {
180
+ value: T;
181
+ label: string;
182
+ disabled?: boolean;
80
183
  }
81
-
@@ -4,7 +4,7 @@
4
4
  // ============================================================
5
5
 
6
6
  import type { ArrayFieldType } from "../../types/base-fields";
7
- import type { FieldConfigType, ValidationResultType } from "../core/types";
7
+ import type { ArrayFieldMetaType, BaseFieldMetaType, ValidationResultType } from "../core/types";
8
8
  import { BaseField } from "./BaseField";
9
9
 
10
10
  /**
@@ -15,14 +15,18 @@ import { BaseField } from "./BaseField";
15
15
  * @example
16
16
  * ```typescript
17
17
  * readonly Tags = new ArrayField<string>({
18
- * id: "Tags",
19
- * label: "Tags"
18
+ * _id: "Tags", Name: "Tags", Type: "Array",
20
19
  * });
21
20
  * ```
22
21
  */
23
22
  export class ArrayField<T = unknown> extends BaseField<ArrayFieldType<T>> {
24
- constructor(config: FieldConfigType) {
25
- super(config);
23
+ constructor(meta: ArrayFieldMetaType) {
24
+ super(meta);
25
+ }
26
+
27
+ /** Element type descriptor for array items */
28
+ get elementType(): BaseFieldMetaType | undefined {
29
+ return (this._meta as ArrayFieldMetaType).Property;
26
30
  }
27
31
 
28
32
  validate(value: ArrayFieldType<T> | undefined): ValidationResultType {
@@ -3,48 +3,38 @@
3
3
  // Abstract base class for all field types
4
4
  // ============================================================
5
5
 
6
- import type { FieldConfigType, ValidationResultType, FieldMetaType } from "../core/types";
6
+ import type { BaseFieldMetaType, ValidationResultType } from "../core/types";
7
7
 
8
8
  /**
9
- * Abstract base class for all field definitions
9
+ * Abstract base class for all field definitions.
10
+ * Stores the raw backend meta JSON and exposes convenience getters.
10
11
  *
11
12
  * @template T - The TypeScript type of the field value
12
- *
13
- * @example
14
- * ```typescript
15
- * class CustomField extends BaseField<MyType> {
16
- * validate(value: MyType | undefined): ValidationResult {
17
- * // Custom validation logic
18
- * }
19
- * }
20
- * ```
21
13
  */
22
14
  export abstract class BaseField<T> {
23
- protected readonly id: string;
24
- protected readonly label: string;
25
- protected readonly editable: boolean;
15
+ /** Full raw backend meta */
16
+ protected readonly _meta: BaseFieldMetaType;
26
17
  protected _parentBoId?: string;
27
18
 
28
- constructor(config: FieldConfigType) {
29
- this.id = config.id;
30
- this.label = config.label;
31
- this.editable = config.editable ?? true;
19
+ constructor(meta: BaseFieldMetaType) {
20
+ this._meta = meta;
32
21
  }
33
22
 
23
+ // === Convenience getters (transform backend naming → SDK naming) ===
24
+
25
+ get id(): string { return this._meta._id; }
26
+ get label(): string { return this._meta.Name || this._meta._id; }
27
+ get readOnly(): boolean { return this._meta.ReadOnly ?? false; }
28
+ get required(): boolean { return this._meta.Constraint?.Required ?? this._meta.Required ?? false; }
29
+ get defaultValue(): unknown { return this._meta.DefaultValue ?? this._meta.Constraint?.DefaultValue; }
30
+ get primaryKey(): boolean { return this._meta.Constraint?.PrimaryKey ?? false; }
31
+
32
+ /** Full raw meta (the exact JSON passed to constructor) */
33
+ get meta(): BaseFieldMetaType { return this._meta; }
34
+
34
35
  /**
35
36
  * Validate a value for this field
36
37
  * Override in subclasses for custom validation
37
38
  */
38
39
  abstract validate(value: T | undefined): ValidationResultType;
39
-
40
- /**
41
- * Get field metadata (id, label, and field-specific info)
42
- */
43
- get meta(): FieldMetaType {
44
- return {
45
- id: this.id,
46
- label: this.label,
47
- isEditable: this.editable,
48
- };
49
- }
50
40
  }
@@ -4,7 +4,7 @@
4
4
  // ============================================================
5
5
 
6
6
  import type { BooleanFieldType } from "../../types/base-fields";
7
- import type { FieldConfigType, ValidationResultType } from "../core/types";
7
+ import type { BooleanFieldMetaType, ValidationResultType } from "../core/types";
8
8
  import { BaseField } from "./BaseField";
9
9
 
10
10
  /**
@@ -13,14 +13,13 @@ import { BaseField } from "./BaseField";
13
13
  * @example
14
14
  * ```typescript
15
15
  * readonly IsActive = new BooleanField({
16
- * id: "IsActive",
17
- * label: "Is Active"
16
+ * _id: "IsActive", Name: "Is Active", Type: "Boolean",
18
17
  * });
19
18
  * ```
20
19
  */
21
20
  export class BooleanField extends BaseField<BooleanFieldType> {
22
- constructor(config: FieldConfigType) {
23
- super(config);
21
+ constructor(meta: BooleanFieldMetaType) {
22
+ super(meta);
24
23
  }
25
24
 
26
25
  validate(value: BooleanFieldType | undefined): ValidationResultType {
@@ -4,7 +4,7 @@
4
4
  // ============================================================
5
5
 
6
6
  import type { DateFieldType } from "../../types/base-fields";
7
- import type { FieldConfigType, ValidationResultType } from "../core/types";
7
+ import type { DateFieldMetaType, ValidationResultType } from "../core/types";
8
8
  import { BaseField } from "./BaseField";
9
9
 
10
10
  /**
@@ -13,14 +13,13 @@ import { BaseField } from "./BaseField";
13
13
  * @example
14
14
  * ```typescript
15
15
  * readonly BirthDate = new DateField({
16
- * id: "BirthDate",
17
- * label: "Birth Date"
16
+ * _id: "BirthDate", Name: "Birth Date", Type: "Date",
18
17
  * });
19
18
  * ```
20
19
  */
21
20
  export class DateField extends BaseField<DateFieldType> {
22
- constructor(config: FieldConfigType) {
23
- super(config);
21
+ constructor(meta: DateFieldMetaType) {
22
+ super(meta);
24
23
  }
25
24
 
26
25
  validate(value: DateFieldType | undefined): ValidationResultType {
@@ -3,7 +3,7 @@
3
3
  // Field for date and datetime values
4
4
  // ============================================================
5
5
 
6
- import type { FieldConfigType, ValidationResultType } from "../core/types";
6
+ import type { DateTimeFieldMetaType, ValidationResultType } from "../core/types";
7
7
  import { BaseField } from "./BaseField";
8
8
 
9
9
  /**
@@ -17,14 +17,18 @@ type DateTimeValue = string;
17
17
  * @example
18
18
  * ```typescript
19
19
  * readonly CreatedAt = new DateTimeField({
20
- * id: "_created_at",
21
- * label: "Created At"
20
+ * _id: "_created_at", Name: "Created At", Type: "DateTime", ReadOnly: true,
22
21
  * });
23
22
  * ```
24
23
  */
25
24
  export class DateTimeField extends BaseField<DateTimeValue> {
26
- constructor(config: FieldConfigType) {
27
- super(config);
25
+ constructor(meta: DateTimeFieldMetaType) {
26
+ super(meta);
27
+ }
28
+
29
+ /** DateTime-specific: precision */
30
+ get precision(): "Second" | "Millisecond" {
31
+ return (this._meta as DateTimeFieldMetaType).Constraint?.Precision ?? "Second";
28
32
  }
29
33
 
30
34
  validate(value: DateTimeValue | undefined): ValidationResultType {
@@ -0,0 +1,39 @@
1
+ // ============================================================
2
+ // FILE FIELD
3
+ // Field for file attachments
4
+ // ============================================================
5
+
6
+ import type { FileFieldType } from "../../types/base-fields";
7
+ import type { FileFieldMetaType, ValidationResultType } from "../core/types";
8
+ import { BaseField } from "./BaseField";
9
+
10
+ /**
11
+ * Field definition for file attachment fields
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * readonly Attachment = new FileField({
16
+ * _id: "Attachment", Name: "Attachment", Type: "File",
17
+ * });
18
+ * ```
19
+ */
20
+ export class FileField extends BaseField<FileFieldType> {
21
+ constructor(meta: FileFieldMetaType) {
22
+ super(meta);
23
+ }
24
+
25
+ validate(value: FileFieldType | undefined): ValidationResultType {
26
+ if (value === undefined || value === null) {
27
+ return { valid: true, errors: [] };
28
+ }
29
+
30
+ if (typeof value !== "object" || Array.isArray(value)) {
31
+ return {
32
+ valid: false,
33
+ errors: [`${this.label} must be a valid file object`],
34
+ };
35
+ }
36
+
37
+ return { valid: true, errors: [] };
38
+ }
39
+ }
@@ -4,7 +4,7 @@
4
4
  // ============================================================
5
5
 
6
6
  import type { NumberFieldType } from "../../types/base-fields";
7
- import type { FieldConfigType, ValidationResultType } from "../core/types";
7
+ import type { NumberFieldMetaType, ValidationResultType } from "../core/types";
8
8
  import { BaseField } from "./BaseField";
9
9
 
10
10
  /**
@@ -13,16 +13,19 @@ import { BaseField } from "./BaseField";
13
13
  * @example
14
14
  * ```typescript
15
15
  * readonly Price = new NumberField({
16
- * id: "Price",
17
- * label: "Price"
16
+ * _id: "Price", Name: "Price", Type: "Number",
17
+ * Constraint: { IntegerPart: 9, FractionPart: 2 },
18
18
  * });
19
19
  * ```
20
20
  */
21
21
  export class NumberField extends BaseField<NumberFieldType> {
22
- constructor(config: FieldConfigType) {
23
- super(config);
22
+ constructor(meta: NumberFieldMetaType) {
23
+ super(meta);
24
24
  }
25
25
 
26
+ get integerPart(): number { return (this._meta as NumberFieldMetaType).Constraint?.IntegerPart ?? 9; }
27
+ get fractionPart(): number | undefined { return (this._meta as NumberFieldMetaType).Constraint?.FractionPart; }
28
+
26
29
  validate(value: NumberFieldType | undefined): ValidationResultType {
27
30
  if (value !== undefined && value !== null && (typeof value !== "number" || isNaN(value))) {
28
31
  return {
@@ -4,7 +4,7 @@
4
4
  // ============================================================
5
5
 
6
6
  import type { ObjectFieldType } from "../../types/base-fields";
7
- import type { FieldConfigType, ValidationResultType } from "../core/types";
7
+ import type { ObjectFieldMetaType, ValidationResultType } from "../core/types";
8
8
  import { BaseField } from "./BaseField";
9
9
 
10
10
  /**
@@ -13,16 +13,20 @@ import { BaseField } from "./BaseField";
13
13
  * @example
14
14
  * ```typescript
15
15
  * readonly Config = new ObjectField({
16
- * id: "Config",
17
- * label: "Configuration"
16
+ * _id: "Config", Name: "Configuration", Type: "Object",
18
17
  * });
19
18
  * ```
20
19
  */
21
20
  export class ObjectField<
22
21
  T extends Record<string, unknown> = Record<string, unknown>,
23
22
  > extends BaseField<ObjectFieldType<T>> {
24
- constructor(config: FieldConfigType) {
25
- super(config);
23
+ constructor(meta: ObjectFieldMetaType) {
24
+ super(meta);
25
+ }
26
+
27
+ /** Nested property definitions */
28
+ get properties(): Record<string, unknown> | undefined {
29
+ return (this._meta as ObjectFieldMetaType).Property;
26
30
  }
27
31
 
28
32
  validate(value: ObjectFieldType<T> | undefined): ValidationResultType {
@@ -4,35 +4,44 @@
4
4
  // ============================================================
5
5
 
6
6
  import type { ReferenceFieldType } from "../../types/base-fields";
7
- import type { ReferenceFieldConfigType, ValidationResultType, ReferenceFieldMetaType } from "../core/types";
7
+ import type { ReferenceFieldMetaType as ReferenceFieldMetaRawType, ValidationResultType } from "../core/types";
8
8
  import { api } from "../../api/client";
9
9
  import { BaseField } from "./BaseField";
10
10
 
11
11
  /**
12
- * Field definition for reference/lookup fields
12
+ * Field definition for reference/lookup fields.
13
+ * Config is derived from View.DataObject in the raw meta.
13
14
  *
14
15
  * @template TRef - The type of the referenced record
15
16
  *
16
17
  * @example
17
18
  * ```typescript
18
- * readonly SupplierInfo = new ReferenceField<SupplierType>({
19
- * id: "SupplierInfo",
20
- * label: "Supplier",
21
- * referenceBdo: "BDO_Supplier",
22
- * referenceFields: ["_id", "SupplierName", "Email"]
19
+ * readonly SupplierInfo = new ReferenceField<SupplierRefType>({
20
+ * _id: "SupplierInfo", Name: "Supplier", Type: "Reference",
21
+ * View: {
22
+ * DataObject: { Type: "BO", Id: "BDO_Supplier" },
23
+ * Fields: ["_id", "SupplierName", "Email"],
24
+ * },
23
25
  * });
24
26
  * ```
25
27
  */
26
28
  export class ReferenceField<TRef = unknown> extends BaseField<
27
29
  ReferenceFieldType<TRef>
28
30
  > {
29
- protected readonly referenceBdo: string;
30
- protected readonly referenceFields: readonly string[];
31
+ constructor(meta: ReferenceFieldMetaRawType) {
32
+ super(meta);
33
+ }
34
+
35
+ get referenceBdo(): string {
36
+ return (this._meta as ReferenceFieldMetaRawType).View?.DataObject?.Id ?? "";
37
+ }
38
+
39
+ get referenceFields(): readonly string[] {
40
+ return (this._meta as ReferenceFieldMetaRawType).View?.Fields ?? ["_id"];
41
+ }
31
42
 
32
- constructor(config: ReferenceFieldConfigType<TRef>) {
33
- super(config);
34
- this.referenceBdo = config.referenceBdo;
35
- this.referenceFields = config.referenceFields ?? ["_id"];
43
+ get searchFields(): readonly string[] {
44
+ return (this._meta as ReferenceFieldMetaRawType).View?.Search ?? [];
36
45
  }
37
46
 
38
47
  validate(value: ReferenceFieldType<TRef> | undefined): ValidationResultType {
@@ -69,19 +78,4 @@ export class ReferenceField<TRef = unknown> extends BaseField<
69
78
  }
70
79
  return api(this._parentBoId).fetchField<TRef>(instanceId ?? "new", this.id);
71
80
  }
72
-
73
- /**
74
- * Get field metadata including reference info
75
- */
76
- override get meta(): ReferenceFieldMetaType {
77
- return {
78
- id: this.id,
79
- label: this.label,
80
- isEditable: this.editable,
81
- reference: {
82
- bdo: this.referenceBdo,
83
- fields: [...this.referenceFields],
84
- },
85
- };
86
- }
87
81
  }
@@ -3,35 +3,34 @@
3
3
  // Field for single selection from predefined options
4
4
  // ============================================================
5
5
 
6
- import type { SelectFieldConfigType, SelectOptionType, ValidationResultType, SelectFieldMetaType } from "../core/types";
6
+ import type { SelectFieldMetaType as SelectFieldMetaRawType, SelectOptionType, ValidationResultType } from "../core/types";
7
7
  import type { FetchFieldOptionType } from "../../types/common";
8
8
  import { api } from "../../api/client";
9
9
  import { BaseField } from "./BaseField";
10
10
 
11
11
  /**
12
- * Field definition for select fields with predefined options
12
+ * Field definition for select fields.
13
+ * Options are derived from Constraint.Enum in the raw meta.
13
14
  *
14
15
  * @template T - Union type of allowed option values
15
16
  *
16
17
  * @example
17
18
  * ```typescript
18
- * readonly Status = new SelectField<"active" | "inactive" | "pending">({
19
- * id: "Status",
20
- * label: "Status",
21
- * options: [
22
- * { value: "active", label: "Active" },
23
- * { value: "inactive", label: "Inactive" },
24
- * { value: "pending", label: "Pending" }
25
- * ]
19
+ * readonly Status = new SelectField<"active" | "inactive">({
20
+ * _id: "Status", Name: "Status", Type: "String",
21
+ * Constraint: { Enum: ["active", "inactive"] },
26
22
  * });
27
23
  * ```
28
24
  */
29
25
  export class SelectField<T extends string | number = string> extends BaseField<T> {
30
- protected readonly options: readonly SelectOptionType<T>[];
26
+ constructor(meta: SelectFieldMetaRawType) {
27
+ super(meta);
28
+ }
31
29
 
32
- constructor(config: SelectFieldConfigType<T>) {
33
- super(config);
34
- this.options = config.options;
30
+ /** Static options derived from Constraint.Enum */
31
+ get options(): readonly SelectOptionType<T>[] {
32
+ const enumValues = (this._meta as SelectFieldMetaRawType).Constraint?.Enum ?? [];
33
+ return enumValues.map(v => ({ value: v as T, label: v }));
35
34
  }
36
35
 
37
36
  validate(value: T | undefined): ValidationResultType {
@@ -73,16 +72,4 @@ export class SelectField<T extends string | number = string> extends BaseField<T
73
72
  label: item.Label,
74
73
  }));
75
74
  }
76
-
77
- /**
78
- * Get field metadata including static options
79
- */
80
- override get meta(): SelectFieldMetaType<T> {
81
- return {
82
- id: this.id,
83
- label: this.label,
84
- isEditable: this.editable,
85
- options: this.options,
86
- };
87
- }
88
75
  }