@ram_28/kf-ai-sdk 1.0.8 → 1.0.9

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 (28) hide show
  1. package/dist/components/hooks/index.d.ts +2 -1
  2. package/dist/components/hooks/index.d.ts.map +1 -1
  3. package/dist/components/hooks/useForm/apiClient.d.ts +4 -4
  4. package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
  5. package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +3 -3
  6. package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -1
  7. package/dist/components/hooks/useForm/index.d.ts +7 -4
  8. package/dist/components/hooks/useForm/index.d.ts.map +1 -1
  9. package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +5 -5
  10. package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -1
  11. package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +7 -6
  12. package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -1
  13. package/dist/components/hooks/useForm/schemaParser.utils.d.ts +8 -8
  14. package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -1
  15. package/dist/components/hooks/useForm/types.d.ts +86 -93
  16. package/dist/components/hooks/useForm/types.d.ts.map +1 -1
  17. package/dist/index.cjs +11 -11
  18. package/dist/index.mjs +1003 -1009
  19. package/package.json +1 -1
  20. package/sdk/components/hooks/index.ts +24 -4
  21. package/sdk/components/hooks/useForm/apiClient.ts +5 -5
  22. package/sdk/components/hooks/useForm/expressionValidator.utils.ts +11 -11
  23. package/sdk/components/hooks/useForm/index.ts +41 -45
  24. package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +7 -7
  25. package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +21 -20
  26. package/sdk/components/hooks/useForm/schemaParser.utils.ts +36 -41
  27. package/sdk/components/hooks/useForm/types.ts +107 -113
  28. package/sdk/components/hooks/useForm/useForm.ts +54 -54
@@ -11,9 +11,9 @@ import type { Path } from "react-hook-form";
11
11
  import type {
12
12
  UseFormOptions,
13
13
  UseFormReturn,
14
- BackendSchema,
15
- ProcessedSchema,
16
- ProcessedField,
14
+ BDOSchema,
15
+ FormSchemaConfig,
16
+ FormFieldConfig,
17
17
  } from "./types";
18
18
 
19
19
  import { processSchema, extractReferenceFields } from "./schemaParser.utils";
@@ -62,8 +62,8 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
62
62
  // STATE MANAGEMENT
63
63
  // ============================================================
64
64
 
65
- const [processedSchema, setProcessedSchema] =
66
- useState<ProcessedSchema | null>(null);
65
+ const [schemaConfig, setSchemaConfig] =
66
+ useState<FormSchemaConfig | null>(null);
67
67
  const [referenceData, setReferenceData] = useState<Record<string, any[]>>({});
68
68
  const [submitError, setSubmitError] = useState<Error | null>(null);
69
69
  const [isSubmitting, setIsSubmitting] = useState(false);
@@ -153,8 +153,8 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
153
153
  }
154
154
 
155
155
  // Apply default values from schema
156
- if (processedSchema) {
157
- for (const [fieldName, field] of Object.entries(processedSchema.fields)) {
156
+ if (schemaConfig) {
157
+ for (const [fieldName, field] of Object.entries(schemaConfig.fields)) {
158
158
  if (field.defaultValue !== undefined && !(fieldName in values)) {
159
159
  (values as any)[fieldName] = field.defaultValue;
160
160
  }
@@ -162,7 +162,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
162
162
  }
163
163
 
164
164
  return values;
165
- }, [defaultValues, recordData, operation, processedSchema]);
165
+ }, [defaultValues, recordData, operation, schemaConfig]);
166
166
 
167
167
  const rhfForm = useReactHookForm<T>({
168
168
  mode,
@@ -185,7 +185,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
185
185
  {}, // Pass empty object - validation functions get live values from react-hook-form
186
186
  userRole
187
187
  );
188
- setProcessedSchema(processed);
188
+ setSchemaConfig(processed);
189
189
 
190
190
  // Fetch reference data for reference fields
191
191
  const refFields = extractReferenceFields(processed);
@@ -220,21 +220,21 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
220
220
 
221
221
  // Extract computed field dependencies using optimized analyzer
222
222
  const computedFieldDependencies = useMemo(() => {
223
- if (!processedSchema) return [];
223
+ if (!schemaConfig) return [];
224
224
 
225
225
  const dependencies = new Set<string>();
226
- const computedFieldNames = new Set(processedSchema.computedFields);
226
+ const computedFieldNames = new Set(schemaConfig.computedFields);
227
227
 
228
228
  // Analyze dependencies from computation rules
229
- Object.entries(processedSchema.fieldRules).forEach(([fieldName, rules]) => {
229
+ Object.entries(schemaConfig.fieldRules).forEach(([fieldName, rules]) => {
230
230
  rules.computation.forEach((ruleId) => {
231
- const rule = processedSchema.rules.computation[ruleId];
231
+ const rule = schemaConfig.rules.computation[ruleId];
232
232
  if (rule?.ExpressionTree) {
233
233
  const ruleDeps = getFieldDependencies(rule.ExpressionTree);
234
234
  ruleDeps.forEach((dep) => {
235
235
  // Only add non-computed fields as dependencies
236
236
  if (
237
- processedSchema.fields[dep] &&
237
+ schemaConfig.fields[dep] &&
238
238
  dep !== fieldName &&
239
239
  !computedFieldNames.has(dep)
240
240
  ) {
@@ -246,16 +246,16 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
246
246
  });
247
247
 
248
248
  // Also check formulas (legacy support)
249
- processedSchema.computedFields.forEach((fieldName: string) => {
250
- const field = processedSchema.fields[fieldName];
251
- if (field.backendField.Formula) {
249
+ schemaConfig.computedFields.forEach((fieldName: string) => {
250
+ const field = schemaConfig.fields[fieldName];
251
+ if (field._bdoField.Formula) {
252
252
  const fieldDeps = getFieldDependencies(
253
- field.backendField.Formula.ExpressionTree
253
+ field._bdoField.Formula.ExpressionTree
254
254
  );
255
255
  fieldDeps.forEach((dep) => {
256
256
  // Only add non-computed fields as dependencies
257
257
  if (
258
- processedSchema.fields[dep] &&
258
+ schemaConfig.fields[dep] &&
259
259
  dep !== fieldName &&
260
260
  !computedFieldNames.has(dep)
261
261
  ) {
@@ -266,7 +266,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
266
266
  });
267
267
 
268
268
  return Array.from(dependencies) as Array<Path<T>>;
269
- }, [processedSchema]);
269
+ }, [schemaConfig]);
270
270
 
271
271
  // Watch dependencies are tracked but not used for automatic computation
272
272
  // Computation is triggered manually on blur after validation passes
@@ -278,7 +278,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
278
278
  // Manual computation trigger - called on blur after validation passes
279
279
  const triggerComputationAfterValidation = useCallback(
280
280
  async (fieldName: string) => {
281
- if (!processedSchema || computedFieldDependencies.length === 0) {
281
+ if (!schemaConfig || computedFieldDependencies.length === 0) {
282
282
  return;
283
283
  }
284
284
 
@@ -305,7 +305,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
305
305
 
306
306
  computeTimeoutRef.current = setTimeout(() => {
307
307
  // Additional safety check
308
- if (!processedSchema) return;
308
+ if (!schemaConfig) return;
309
309
 
310
310
  // Prevent concurrent API calls
311
311
  if (isComputingRef.current) {
@@ -338,7 +338,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
338
338
 
339
339
  // Get computed field names to exclude from payload
340
340
  const computedFieldNames = new Set(
341
- processedSchema.computedFields || []
341
+ schemaConfig.computedFields || []
342
342
  );
343
343
 
344
344
  // Find fields that changed from baseline (excluding computed fields)
@@ -430,7 +430,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
430
430
  }, 300); // 300ms debounce
431
431
  },
432
432
  [
433
- processedSchema,
433
+ schemaConfig,
434
434
  operation,
435
435
  recordId,
436
436
  recordData,
@@ -446,7 +446,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
446
446
  // ============================================================
447
447
 
448
448
  const validateForm = useCallback(async (): Promise<boolean> => {
449
- if (!processedSchema) {
449
+ if (!schemaConfig) {
450
450
  return false;
451
451
  }
452
452
 
@@ -460,7 +460,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
460
460
 
461
461
  // Cross-field validation
462
462
  // Transform ValidationRule[] to the format expected by validateCrossField
463
- const transformedRules = processedSchema.crossFieldValidation.map(
463
+ const transformedRules = schemaConfig.crossFieldValidation.map(
464
464
  (rule) => ({
465
465
  Id: rule.Id,
466
466
  Condition: { ExpressionTree: rule.ExpressionTree },
@@ -487,7 +487,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
487
487
 
488
488
  return true;
489
489
  }, [
490
- processedSchema,
490
+ schemaConfig,
491
491
  rhfForm.getValues,
492
492
  rhfForm.trigger,
493
493
  rhfForm.setError,
@@ -499,7 +499,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
499
499
  // ============================================================
500
500
 
501
501
  const submit = useCallback(async (): Promise<void> => {
502
- if (!processedSchema) {
502
+ if (!schemaConfig) {
503
503
  throw new Error("Schema not loaded");
504
504
  }
505
505
 
@@ -520,7 +520,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
520
520
  // - For update: includes only fields that changed from recordData
521
521
  const cleanedData = cleanFormData(
522
522
  formValues as any,
523
- processedSchema.computedFields,
523
+ schemaConfig.computedFields,
524
524
  operation,
525
525
  recordData as Partial<T> | undefined
526
526
  );
@@ -553,7 +553,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
553
553
  } finally {
554
554
  setIsSubmitting(false);
555
555
  }
556
- }, [processedSchema, validateForm, rhfForm, source, operation, recordId, recordData]);
556
+ }, [schemaConfig, validateForm, rhfForm, source, operation, recordId, recordData]);
557
557
 
558
558
  // ============================================================
559
559
  // HANDLE SUBMIT - Simplified API
@@ -571,46 +571,46 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
571
571
  // ============================================================
572
572
 
573
573
  const getField = useCallback(
574
- <K extends keyof T>(fieldName: K): ProcessedField | null => {
575
- return processedSchema?.fields[fieldName as string] || null;
574
+ <K extends keyof T>(fieldName: K): FormFieldConfig | null => {
575
+ return schemaConfig?.fields[fieldName as string] || null;
576
576
  },
577
- [processedSchema]
577
+ [schemaConfig]
578
578
  );
579
579
 
580
- const getFields = useCallback((): Record<keyof T, ProcessedField> => {
581
- if (!processedSchema) return {} as Record<keyof T, ProcessedField>;
580
+ const getFields = useCallback((): Record<keyof T, FormFieldConfig> => {
581
+ if (!schemaConfig) return {} as Record<keyof T, FormFieldConfig>;
582
582
 
583
- const typedFields: Record<keyof T, ProcessedField> = {} as any;
584
- Object.entries(processedSchema.fields).forEach(([key, field]) => {
583
+ const typedFields: Record<keyof T, FormFieldConfig> = {} as any;
584
+ Object.entries(schemaConfig.fields).forEach(([key, field]) => {
585
585
  (typedFields as any)[key] = field;
586
586
  });
587
587
 
588
588
  return typedFields;
589
- }, [processedSchema]);
589
+ }, [schemaConfig]);
590
590
 
591
591
  const hasField = useCallback(
592
592
  <K extends keyof T>(fieldName: K): boolean => {
593
- return !!processedSchema?.fields[fieldName as string];
593
+ return !!schemaConfig?.fields[fieldName as string];
594
594
  },
595
- [processedSchema]
595
+ [schemaConfig]
596
596
  );
597
597
 
598
598
  const isFieldRequired = useCallback(
599
599
  <K extends keyof T>(fieldName: K): boolean => {
600
600
  return (
601
- processedSchema?.requiredFields.includes(fieldName as string) || false
601
+ schemaConfig?.requiredFields.includes(fieldName as string) || false
602
602
  );
603
603
  },
604
- [processedSchema]
604
+ [schemaConfig]
605
605
  );
606
606
 
607
607
  const isFieldComputed = useCallback(
608
608
  <K extends keyof T>(fieldName: K): boolean => {
609
609
  return (
610
- processedSchema?.computedFields.includes(fieldName as string) || false
610
+ schemaConfig?.computedFields.includes(fieldName as string) || false
611
611
  );
612
612
  },
613
- [processedSchema]
613
+ [schemaConfig]
614
614
  );
615
615
 
616
616
  // ============================================================
@@ -637,13 +637,13 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
637
637
  const hasError = !!(loadError || submitError);
638
638
 
639
639
  const computedFields = useMemo<Array<keyof T>>(
640
- () => (processedSchema?.computedFields as Array<keyof T>) || [],
641
- [processedSchema]
640
+ () => (schemaConfig?.computedFields as Array<keyof T>) || [],
641
+ [schemaConfig]
642
642
  );
643
643
 
644
644
  const requiredFields = useMemo<Array<keyof T>>(
645
- () => (processedSchema?.requiredFields as Array<keyof T>) || [],
646
- [processedSchema]
645
+ () => (schemaConfig?.requiredFields as Array<keyof T>) || [],
646
+ [schemaConfig]
647
647
  );
648
648
 
649
649
  // ============================================================
@@ -652,11 +652,11 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
652
652
 
653
653
  // Create validation rules from processed schema (client-side only)
654
654
  const validationRules = useMemo(() => {
655
- if (!processedSchema) return {};
655
+ if (!schemaConfig) return {};
656
656
 
657
657
  const rules: Record<string, any> = {};
658
658
 
659
- Object.entries(processedSchema.fields).forEach(([fieldName, field]) => {
659
+ Object.entries(schemaConfig.fields).forEach(([fieldName, field]) => {
660
660
  const fieldRules: any = {};
661
661
 
662
662
  // Required validation
@@ -689,7 +689,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
689
689
 
690
690
  // Execute client-side validation rules with optimization
691
691
  for (const ruleId of validationRuleIds) {
692
- const rule = processedSchema.rules.validation[ruleId];
692
+ const rule = schemaConfig.rules.validation[ruleId];
693
693
  if (rule) {
694
694
  const result = validateFieldOptimized<T>(
695
695
  fieldName,
@@ -712,7 +712,7 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
712
712
  });
713
713
 
714
714
  return rules;
715
- }, [processedSchema, rhfForm, referenceData]);
715
+ }, [schemaConfig, rhfForm, referenceData]);
716
716
 
717
717
  /**
718
718
  * Enhanced register function that wraps react-hook-form's register
@@ -800,8 +800,8 @@ export function useForm<T extends Record<string, any> = Record<string, any>>(
800
800
  hasError,
801
801
 
802
802
  // Schema information
803
- schema: schema as BackendSchema | null,
804
- processedSchema,
803
+ schema: schema as BDOSchema | null,
804
+ schemaConfig,
805
805
  computedFields,
806
806
  requiredFields,
807
807