@ram_28/kf-ai-sdk 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -48
- package/dist/api/client.d.ts +14 -14
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/datetime.d.ts +5 -5
- package/dist/api/datetime.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/metadata.d.ts +2 -2
- package/dist/api/metadata.d.ts.map +1 -1
- package/dist/api.cjs +1 -0
- package/dist/api.d.ts +4 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.mjs +27 -0
- package/dist/api.types.cjs +1 -0
- package/dist/api.types.d.ts +4 -0
- package/dist/api.types.d.ts.map +1 -0
- package/dist/api.types.mjs +1 -0
- package/dist/auth/AuthProvider.d.ts +3 -3
- package/dist/auth/AuthProvider.d.ts.map +1 -1
- package/dist/auth/authClient.d.ts +4 -4
- package/dist/auth/authClient.d.ts.map +1 -1
- package/dist/auth/authConfig.d.ts +5 -5
- package/dist/auth/authConfig.d.ts.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/types.d.ts +21 -21
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/useAuth.d.ts +2 -2
- package/dist/auth/useAuth.d.ts.map +1 -1
- package/dist/auth.cjs +1 -0
- package/dist/auth.d.ts +5 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.mjs +280 -0
- package/dist/auth.types.cjs +1 -0
- package/dist/auth.types.d.ts +2 -0
- package/dist/auth.types.d.ts.map +1 -0
- package/dist/auth.types.mjs +1 -0
- package/dist/base-types.d.ts +2 -0
- package/dist/base-types.d.ts.map +1 -0
- package/dist/client-C15j4O5B.cjs +1 -0
- package/dist/client-CfvLiGfP.js +233 -0
- package/dist/cn-Dr87sK3i.js +2775 -0
- package/dist/cn-mXUIg4vp.cjs +1 -0
- package/dist/components/hooks/index.d.ts +3 -3
- package/dist/components/hooks/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/index.d.ts +2 -2
- package/dist/components/hooks/useFilter/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/types.d.ts +19 -31
- package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/useFilter.d.ts +2 -2
- package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
- package/dist/components/hooks/useForm/apiClient.d.ts +6 -6
- package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +7 -7
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/index.d.ts +5 -5
- package/dist/components/hooks/useForm/index.d.ts.map +1 -1
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +10 -10
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +7 -12
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts +7 -7
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -1
- package/dist/components/hooks/useForm/types.d.ts +67 -76
- package/dist/components/hooks/useForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useForm/useForm.d.ts +2 -2
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/apiClient.d.ts +16 -16
- package/dist/components/hooks/useKanban/apiClient.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/context.d.ts +3 -3
- package/dist/components/hooks/useKanban/context.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/dragDropManager.d.ts +7 -7
- package/dist/components/hooks/useKanban/dragDropManager.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/index.d.ts +1 -1
- package/dist/components/hooks/useKanban/index.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/types.d.ts +65 -67
- package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/useKanban.d.ts +2 -2
- package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
- package/dist/components/hooks/useTable/index.d.ts +1 -1
- package/dist/components/hooks/useTable/index.d.ts.map +1 -1
- package/dist/components/hooks/useTable/types.d.ts +10 -10
- package/dist/components/hooks/useTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useTable/useTable.d.ts +2 -2
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
- package/dist/filter.cjs +1 -0
- package/dist/filter.d.ts +3 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.mjs +6 -0
- package/dist/filter.types.cjs +1 -0
- package/dist/filter.types.d.ts +2 -0
- package/dist/filter.types.d.ts.map +1 -0
- package/dist/filter.types.mjs +1 -0
- package/dist/form.cjs +1 -0
- package/dist/form.d.ts +3 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.mjs +1346 -0
- package/dist/form.types.cjs +1 -0
- package/dist/form.types.d.ts +2 -0
- package/dist/form.types.d.ts.map +1 -0
- package/dist/form.types.mjs +1 -0
- package/dist/jsx-runtime-BYECrxsp.cjs +30 -0
- package/dist/jsx-runtime-DGlMoOmv.js +630 -0
- package/dist/kanban.cjs +13 -0
- package/dist/kanban.d.ts +5 -0
- package/dist/kanban.d.ts.map +1 -0
- package/dist/kanban.mjs +694 -0
- package/dist/kanban.types.cjs +1 -0
- package/dist/kanban.types.d.ts +2 -0
- package/dist/kanban.types.d.ts.map +1 -0
- package/dist/kanban.types.mjs +1 -0
- package/dist/kanban.ui.cjs +1 -0
- package/dist/kanban.ui.d.ts +2 -0
- package/dist/kanban.ui.d.ts.map +1 -0
- package/dist/kanban.ui.mjs +104 -0
- package/dist/metadata-2FLBsFcf.cjs +1 -0
- package/dist/metadata-DBcoDth-.js +43 -0
- package/dist/table.cjs +1 -0
- package/dist/table.d.ts +2 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.mjs +148 -0
- package/dist/table.types.cjs +1 -0
- package/dist/table.types.d.ts +2 -0
- package/dist/table.types.d.ts.map +1 -0
- package/dist/table.types.mjs +1 -0
- package/dist/types/base-fields.d.ts +45 -45
- package/dist/types/base-fields.d.ts.map +1 -1
- package/dist/types/common.d.ts +45 -61
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types.cjs +1 -0
- package/dist/types.mjs +1 -0
- package/dist/useFilter-CXFqEHyI.js +129 -0
- package/dist/useFilter-D-bCDo6Z.cjs +1 -0
- package/dist/utils/formatting.d.ts +4 -4
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils.cjs +4 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.mjs +105 -0
- package/package.json +147 -9
- package/sdk/api/client.ts +51 -51
- package/sdk/api/datetime.ts +5 -5
- package/sdk/api/index.ts +28 -33
- package/sdk/api/metadata.ts +4 -4
- package/sdk/api.ts +24 -0
- package/sdk/api.types.ts +58 -0
- package/sdk/auth/AuthProvider.tsx +18 -18
- package/sdk/auth/authClient.ts +9 -9
- package/sdk/auth/authConfig.ts +9 -9
- package/sdk/auth/index.ts +5 -5
- package/sdk/auth/types.ts +21 -21
- package/sdk/auth/useAuth.ts +2 -2
- package/sdk/auth.ts +22 -0
- package/sdk/auth.types.ts +28 -0
- package/sdk/base-types.ts +45 -0
- package/sdk/components/hooks/index.ts +22 -22
- package/sdk/components/hooks/useFilter/index.ts +8 -14
- package/sdk/components/hooks/useFilter/types.ts +29 -58
- package/sdk/components/hooks/useFilter/useFilter.ts +41 -44
- package/sdk/components/hooks/useForm/apiClient.ts +8 -8
- package/sdk/components/hooks/useForm/expressionValidator.utils.ts +18 -18
- package/sdk/components/hooks/useForm/index.ts +24 -24
- package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +22 -22
- package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +26 -62
- package/sdk/components/hooks/useForm/schemaParser.utils.ts +24 -24
- package/sdk/components/hooks/useForm/types.ts +66 -82
- package/sdk/components/hooks/useForm/useForm.ts +15 -21
- package/sdk/components/hooks/useKanban/apiClient.ts +54 -54
- package/sdk/components/hooks/useKanban/context.ts +3 -3
- package/sdk/components/hooks/useKanban/dragDropManager.ts +19 -19
- package/sdk/components/hooks/useKanban/index.ts +26 -26
- package/sdk/components/hooks/useKanban/types.ts +69 -71
- package/sdk/components/hooks/useKanban/useKanban.ts +43 -51
- package/sdk/components/hooks/useKanban/useKanbanSimple.ts +4 -4
- package/sdk/components/hooks/useTable/index.ts +5 -1
- package/sdk/components/hooks/useTable/types.ts +10 -10
- package/sdk/components/hooks/useTable/useTable.ts +10 -10
- package/sdk/filter.ts +13 -0
- package/sdk/filter.types.ts +17 -0
- package/sdk/form.ts +15 -0
- package/sdk/form.types.ts +46 -0
- package/sdk/kanban.ts +23 -0
- package/sdk/kanban.types.ts +50 -0
- package/sdk/kanban.ui.ts +16 -0
- package/sdk/table.ts +7 -0
- package/sdk/table.types.ts +13 -0
- package/sdk/types/base-fields.ts +47 -47
- package/sdk/types/common.ts +47 -71
- package/sdk/types/index.ts +1 -1
- package/sdk/utils/formatting.ts +4 -4
- package/sdk/utils.ts +10 -0
- package/dist/index.cjs +0 -45
- package/dist/index.mjs +0 -6387
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// Enhanced expression evaluator with caching, dependency tracking, and performance optimizations
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
ExpressionTreeType,
|
|
8
|
+
FieldValidationResultType,
|
|
9
|
+
SchemaValidationRuleType,
|
|
10
10
|
} from "./types";
|
|
11
11
|
|
|
12
12
|
// ============================================================
|
|
@@ -58,11 +58,11 @@ class LRUCache<T> {
|
|
|
58
58
|
* Analyze expression dependencies for optimized watching
|
|
59
59
|
*/
|
|
60
60
|
export function analyzeExpressionDependencies(
|
|
61
|
-
expression:
|
|
61
|
+
expression: ExpressionTreeType
|
|
62
62
|
): Set<string> {
|
|
63
63
|
const dependencies = new Set<string>();
|
|
64
64
|
|
|
65
|
-
function traverse(node:
|
|
65
|
+
function traverse(node: ExpressionTreeType): void {
|
|
66
66
|
switch (node.Type) {
|
|
67
67
|
case "Identifier":
|
|
68
68
|
if (node.Name && !node.Name.startsWith("$")) {
|
|
@@ -94,7 +94,7 @@ export function analyzeExpressionDependencies(
|
|
|
94
94
|
* Build dependency graph for multiple expressions
|
|
95
95
|
*/
|
|
96
96
|
export function buildDependencyGraph(
|
|
97
|
-
rules: Record<string,
|
|
97
|
+
rules: Record<string, SchemaValidationRuleType>
|
|
98
98
|
): Map<string, Set<string>> {
|
|
99
99
|
const graph = new Map<string, Set<string>>();
|
|
100
100
|
|
|
@@ -122,7 +122,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
122
122
|
* Create cache key from expression and context
|
|
123
123
|
*/
|
|
124
124
|
private createCacheKey(
|
|
125
|
-
expression:
|
|
125
|
+
expression: ExpressionTreeType,
|
|
126
126
|
context: Record<string, any>
|
|
127
127
|
): string {
|
|
128
128
|
const expressionHash = JSON.stringify(expression);
|
|
@@ -133,7 +133,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
133
133
|
/**
|
|
134
134
|
* Get expression dependencies (cached)
|
|
135
135
|
*/
|
|
136
|
-
getDependencies(expression:
|
|
136
|
+
getDependencies(expression: ExpressionTreeType): Set<string> {
|
|
137
137
|
const expressionKey = JSON.stringify(expression);
|
|
138
138
|
|
|
139
139
|
let dependencies = this.dependencyCache.get(expressionKey);
|
|
@@ -149,7 +149,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
149
149
|
* Check if expression result is cached and context hasn't changed
|
|
150
150
|
*/
|
|
151
151
|
private getCachedResult(
|
|
152
|
-
expression:
|
|
152
|
+
expression: ExpressionTreeType,
|
|
153
153
|
context: Record<string, any>,
|
|
154
154
|
lastContext?: Record<string, any>
|
|
155
155
|
): any | undefined {
|
|
@@ -173,7 +173,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
173
173
|
* Evaluate expression with caching
|
|
174
174
|
*/
|
|
175
175
|
evaluate(
|
|
176
|
-
expression:
|
|
176
|
+
expression: ExpressionTreeType,
|
|
177
177
|
context: Record<string, any>,
|
|
178
178
|
lastContext?: Record<string, any>
|
|
179
179
|
): any {
|
|
@@ -194,7 +194,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
194
194
|
/**
|
|
195
195
|
* Core expression evaluation logic
|
|
196
196
|
*/
|
|
197
|
-
private evaluateNode(node:
|
|
197
|
+
private evaluateNode(node: ExpressionTreeType, context: Record<string, any>): any {
|
|
198
198
|
switch (node.Type) {
|
|
199
199
|
case "Literal":
|
|
200
200
|
return node.Value;
|
|
@@ -222,7 +222,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
222
222
|
/**
|
|
223
223
|
* Get identifier value with system context support
|
|
224
224
|
*/
|
|
225
|
-
private getIdentifierValue(node:
|
|
225
|
+
private getIdentifierValue(node: ExpressionTreeType, context: Record<string, any>): any {
|
|
226
226
|
if (!node.Name) return undefined;
|
|
227
227
|
|
|
228
228
|
// System identifiers
|
|
@@ -249,7 +249,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
249
249
|
/**
|
|
250
250
|
* Evaluate binary expressions with type coercion
|
|
251
251
|
*/
|
|
252
|
-
private evaluateBinaryExpression(node:
|
|
252
|
+
private evaluateBinaryExpression(node: ExpressionTreeType, context: Record<string, any>): any {
|
|
253
253
|
if (!node.Arguments || node.Arguments.length !== 2) {
|
|
254
254
|
throw new Error("Binary expression requires exactly 2 arguments");
|
|
255
255
|
}
|
|
@@ -279,7 +279,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
279
279
|
/**
|
|
280
280
|
* Evaluate logical expressions with short-circuiting
|
|
281
281
|
*/
|
|
282
|
-
private evaluateLogicalExpression(node:
|
|
282
|
+
private evaluateLogicalExpression(node: ExpressionTreeType, context: Record<string, any>): any {
|
|
283
283
|
if (!node.Arguments || node.Arguments.length < 2) {
|
|
284
284
|
throw new Error("Logical expression requires at least 2 arguments");
|
|
285
285
|
}
|
|
@@ -309,7 +309,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
309
309
|
/**
|
|
310
310
|
* Evaluate function calls with built-in functions
|
|
311
311
|
*/
|
|
312
|
-
private evaluateCallExpression(node:
|
|
312
|
+
private evaluateCallExpression(node: ExpressionTreeType, context: Record<string, any>): any {
|
|
313
313
|
if (!node.Callee) {
|
|
314
314
|
throw new Error("Call expression requires a function name");
|
|
315
315
|
}
|
|
@@ -360,7 +360,7 @@ export class OptimizedExpressionEvaluator {
|
|
|
360
360
|
/**
|
|
361
361
|
* Evaluate member expressions
|
|
362
362
|
*/
|
|
363
|
-
private evaluateMemberExpression(node:
|
|
363
|
+
private evaluateMemberExpression(node: ExpressionTreeType, context: Record<string, any>): any {
|
|
364
364
|
if (!node.Arguments || node.Arguments.length === 0) {
|
|
365
365
|
throw new Error("Member expression requires arguments");
|
|
366
366
|
}
|
|
@@ -398,10 +398,10 @@ const globalEvaluator = new OptimizedExpressionEvaluator();
|
|
|
398
398
|
export function validateFieldOptimized<T = Record<string, any>>(
|
|
399
399
|
fieldName: string,
|
|
400
400
|
fieldValue: any,
|
|
401
|
-
validationRules:
|
|
401
|
+
validationRules: SchemaValidationRuleType[],
|
|
402
402
|
formValues: T,
|
|
403
403
|
lastFormValues?: T
|
|
404
|
-
):
|
|
404
|
+
): FieldValidationResultType<T> {
|
|
405
405
|
if (!validationRules || validationRules.length === 0) {
|
|
406
406
|
return { isValid: true };
|
|
407
407
|
}
|
|
@@ -435,7 +435,7 @@ export function validateFieldOptimized<T = Record<string, any>>(
|
|
|
435
435
|
* Optimized computed value calculation
|
|
436
436
|
*/
|
|
437
437
|
export function calculateComputedValueOptimized(
|
|
438
|
-
expression:
|
|
438
|
+
expression: ExpressionTreeType,
|
|
439
439
|
formValues: Record<string, any>,
|
|
440
440
|
lastFormValues?: Record<string, any>
|
|
441
441
|
): any {
|
|
@@ -450,7 +450,7 @@ export function calculateComputedValueOptimized(
|
|
|
450
450
|
/**
|
|
451
451
|
* Get field dependencies for optimized watching
|
|
452
452
|
*/
|
|
453
|
-
export function getFieldDependencies(expression:
|
|
453
|
+
export function getFieldDependencies(expression: ExpressionTreeType): string[] {
|
|
454
454
|
return Array.from(globalEvaluator.getDependencies(expression));
|
|
455
455
|
}
|
|
456
456
|
|
|
@@ -461,11 +461,11 @@ export function batchValidateFields<T = Record<string, any>>(
|
|
|
461
461
|
validations: Array<{
|
|
462
462
|
fieldName: string;
|
|
463
463
|
fieldValue: any;
|
|
464
|
-
rules:
|
|
464
|
+
rules: SchemaValidationRuleType[];
|
|
465
465
|
}>,
|
|
466
466
|
formValues: T,
|
|
467
467
|
lastFormValues?: T
|
|
468
|
-
): Array<
|
|
468
|
+
): Array<FieldValidationResultType<T>> {
|
|
469
469
|
return validations.map(({ fieldName, fieldValue, rules }) =>
|
|
470
470
|
validateFieldOptimized(fieldName, fieldValue, rules, formValues, lastFormValues)
|
|
471
471
|
);
|
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
// Classifies rules by type and determines execution strategy
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
FieldPermission,
|
|
7
|
+
BDOSchemaType,
|
|
8
|
+
FormSchemaConfigType,
|
|
9
|
+
SchemaValidationRuleType,
|
|
10
|
+
RuleTypeType,
|
|
11
|
+
FieldPermissionType,
|
|
13
12
|
} from "./types";
|
|
14
13
|
|
|
15
14
|
// ============================================================
|
|
@@ -20,7 +19,7 @@ import type {
|
|
|
20
19
|
* Check if a validation rule represents a "required" validation
|
|
21
20
|
* Detects patterns like: field != null, TRIM(field) != '', etc.
|
|
22
21
|
*/
|
|
23
|
-
function isRequiredSchemaValidationRule(rule:
|
|
22
|
+
function isRequiredSchemaValidationRule(rule: SchemaValidationRuleType, fieldName: string): boolean {
|
|
24
23
|
const expression = rule.Expression?.toLowerCase() || '';
|
|
25
24
|
const ruleName = rule.Name?.toLowerCase() || '';
|
|
26
25
|
const ruleId = rule.Id?.toLowerCase() || '';
|
|
@@ -48,7 +47,7 @@ function isRequiredSchemaValidationRule(rule: SchemaValidationRule, fieldName: s
|
|
|
48
47
|
* Normalize BDO schema to ensure validation rules are in centralized format
|
|
49
48
|
* Extracts inline validation rules from fields and adds them to Rules.Validation
|
|
50
49
|
*/
|
|
51
|
-
export function normalizeBDOSchema(schema:
|
|
50
|
+
export function normalizeBDOSchema(schema: BDOSchemaType): BDOSchemaType {
|
|
52
51
|
const normalizedSchema = { ...schema };
|
|
53
52
|
|
|
54
53
|
// Initialize Rules section if it doesn't exist
|
|
@@ -84,7 +83,7 @@ export function normalizeBDOSchema(schema: BDOSchema): BDOSchema {
|
|
|
84
83
|
// Extract inline validation rules
|
|
85
84
|
const ruleIds: string[] = [];
|
|
86
85
|
|
|
87
|
-
(field.Validation as
|
|
86
|
+
(field.Validation as SchemaValidationRuleType[]).forEach((rule) => {
|
|
88
87
|
// Add rule to centralized Rules.Validation
|
|
89
88
|
normalizedSchema.Rules.Validation![rule.Id] = rule;
|
|
90
89
|
ruleIds.push(rule.Id);
|
|
@@ -146,11 +145,11 @@ export function normalizeBDOSchema(schema: BDOSchema): BDOSchema {
|
|
|
146
145
|
/**
|
|
147
146
|
* Classify rules by type from BDO schema
|
|
148
147
|
*/
|
|
149
|
-
export function classifyRules(schema:
|
|
148
|
+
export function classifyRules(schema: BDOSchemaType): FormSchemaConfigType["rules"] {
|
|
150
149
|
const rules = {
|
|
151
|
-
validation: {} as Record<string,
|
|
152
|
-
computation: {} as Record<string,
|
|
153
|
-
businessLogic: {} as Record<string,
|
|
150
|
+
validation: {} as Record<string, SchemaValidationRuleType>,
|
|
151
|
+
computation: {} as Record<string, SchemaValidationRuleType>,
|
|
152
|
+
businessLogic: {} as Record<string, SchemaValidationRuleType>,
|
|
154
153
|
};
|
|
155
154
|
|
|
156
155
|
// Extract rules from BDO Rules section
|
|
@@ -178,7 +177,7 @@ export function classifyRules(schema: BDOSchema): FormSchemaConfig["rules"] {
|
|
|
178
177
|
* by analyzing the rule's target field from its name/description
|
|
179
178
|
*/
|
|
180
179
|
function inferComputationRuleTargets(
|
|
181
|
-
schema:
|
|
180
|
+
schema: BDOSchemaType
|
|
182
181
|
): Record<string, string> {
|
|
183
182
|
const ruleToField: Record<string, string> = {};
|
|
184
183
|
|
|
@@ -222,10 +221,10 @@ function inferComputationRuleTargets(
|
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
export function createFieldRuleMapping(
|
|
225
|
-
schema:
|
|
226
|
-
classifiedRules:
|
|
227
|
-
):
|
|
228
|
-
const fieldRules:
|
|
224
|
+
schema: BDOSchemaType,
|
|
225
|
+
classifiedRules: FormSchemaConfigType["rules"]
|
|
226
|
+
): FormSchemaConfigType["fieldRules"] {
|
|
227
|
+
const fieldRules: FormSchemaConfigType["fieldRules"] = {};
|
|
229
228
|
|
|
230
229
|
// Initialize all fields
|
|
231
230
|
Object.keys(schema.Fields).forEach((fieldName) => {
|
|
@@ -288,13 +287,13 @@ export function createFieldRuleMapping(
|
|
|
288
287
|
* Calculate field permissions based on user role
|
|
289
288
|
*/
|
|
290
289
|
export function calculateFieldPermissions(
|
|
291
|
-
schema:
|
|
290
|
+
schema: BDOSchemaType,
|
|
292
291
|
userRole?: string
|
|
293
|
-
): Record<string,
|
|
294
|
-
const fieldPermissions: Record<string,
|
|
292
|
+
): Record<string, FieldPermissionType> {
|
|
293
|
+
const fieldPermissions: Record<string, FieldPermissionType> = {};
|
|
295
294
|
|
|
296
295
|
// Default permissions (no role specified)
|
|
297
|
-
const defaultPermission:
|
|
296
|
+
const defaultPermission: FieldPermissionType = {
|
|
298
297
|
editable: true,
|
|
299
298
|
readable: true,
|
|
300
299
|
hidden: false,
|
|
@@ -338,7 +337,7 @@ export function calculateFieldPermissions(
|
|
|
338
337
|
* Determine if rule should execute client-side or server-side
|
|
339
338
|
*/
|
|
340
339
|
export function getRuleExecutionStrategy(
|
|
341
|
-
ruleType:
|
|
340
|
+
ruleType: RuleTypeType
|
|
342
341
|
): "client" | "server" {
|
|
343
342
|
switch (ruleType) {
|
|
344
343
|
case "Validation":
|
|
@@ -356,11 +355,11 @@ export function getRuleExecutionStrategy(
|
|
|
356
355
|
*/
|
|
357
356
|
export function getRulesForField(
|
|
358
357
|
fieldName: string,
|
|
359
|
-
fieldRules:
|
|
360
|
-
classifiedRules:
|
|
358
|
+
fieldRules: FormSchemaConfigType["fieldRules"],
|
|
359
|
+
classifiedRules: FormSchemaConfigType["rules"],
|
|
361
360
|
executionType: "client" | "server"
|
|
362
|
-
):
|
|
363
|
-
const rules:
|
|
361
|
+
): SchemaValidationRuleType[] {
|
|
362
|
+
const rules: SchemaValidationRuleType[] = [];
|
|
364
363
|
const fieldRuleMap = fieldRules[fieldName];
|
|
365
364
|
|
|
366
365
|
if (!fieldRuleMap) return rules;
|
|
@@ -388,38 +387,3 @@ export function getRulesForField(
|
|
|
388
387
|
|
|
389
388
|
return rules;
|
|
390
389
|
}
|
|
391
|
-
|
|
392
|
-
// ============================================================
|
|
393
|
-
// LEGACY SCHEMA SUPPORT
|
|
394
|
-
// ============================================================
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Convert legacy schema format to BDO format
|
|
398
|
-
* @deprecated Legacy schema format is no longer supported
|
|
399
|
-
*/
|
|
400
|
-
export function convertLegacySchema(legacySchema: Record<string, BDOFieldDefinition>): BDOSchema {
|
|
401
|
-
return {
|
|
402
|
-
Id: "legacy_schema",
|
|
403
|
-
Name: "Legacy Schema",
|
|
404
|
-
Kind: "BusinessObject",
|
|
405
|
-
Description: "Converted from legacy schema format",
|
|
406
|
-
Rules: {
|
|
407
|
-
Validation: {},
|
|
408
|
-
Computation: {},
|
|
409
|
-
BusinessLogic: {},
|
|
410
|
-
},
|
|
411
|
-
Fields: Object.fromEntries(
|
|
412
|
-
Object.entries(legacySchema).map(([fieldName, field]) => [
|
|
413
|
-
fieldName,
|
|
414
|
-
{
|
|
415
|
-
...field,
|
|
416
|
-
Id: fieldName,
|
|
417
|
-
Name: field.Description || fieldName,
|
|
418
|
-
Validation: [], // Legacy format needs to be processed separately
|
|
419
|
-
},
|
|
420
|
-
])
|
|
421
|
-
),
|
|
422
|
-
RolePermission: {},
|
|
423
|
-
Roles: {},
|
|
424
|
-
};
|
|
425
|
-
}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
// Converts backend field schemas to react-hook-form validation rules
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
BDOSchemaType,
|
|
8
|
+
BDOFieldDefinitionType,
|
|
9
|
+
FormFieldConfigType,
|
|
10
|
+
FormSchemaConfigType,
|
|
11
|
+
SchemaValidationRuleType,
|
|
12
|
+
FieldPermissionType,
|
|
13
13
|
} from "./types";
|
|
14
14
|
import {
|
|
15
15
|
calculateDefaultValue,
|
|
@@ -85,8 +85,8 @@ function generateLabel(fieldName: string): string {
|
|
|
85
85
|
*/
|
|
86
86
|
function convertSchemaValidationRules(
|
|
87
87
|
fieldName: string,
|
|
88
|
-
fieldDef:
|
|
89
|
-
_allFields: Record<string,
|
|
88
|
+
fieldDef: BDOFieldDefinitionType,
|
|
89
|
+
_allFields: Record<string, BDOFieldDefinitionType>
|
|
90
90
|
): any {
|
|
91
91
|
const validation: any = {};
|
|
92
92
|
|
|
@@ -130,7 +130,7 @@ function convertSchemaValidationRules(
|
|
|
130
130
|
* Process field options for select/reference fields
|
|
131
131
|
*/
|
|
132
132
|
function processFieldOptions(
|
|
133
|
-
fieldDef:
|
|
133
|
+
fieldDef: BDOFieldDefinitionType
|
|
134
134
|
): Array<{ value: any; label: string }> {
|
|
135
135
|
if (!fieldDef.Values) {
|
|
136
136
|
return [];
|
|
@@ -161,7 +161,7 @@ function processFieldOptions(
|
|
|
161
161
|
* Calculate default value for a field
|
|
162
162
|
*/
|
|
163
163
|
function processDefaultValue(
|
|
164
|
-
fieldDef:
|
|
164
|
+
fieldDef: BDOFieldDefinitionType,
|
|
165
165
|
formValues: Record<string, any> = {}
|
|
166
166
|
): any {
|
|
167
167
|
if (!fieldDef.DefaultValue) {
|
|
@@ -197,17 +197,17 @@ function processDefaultValue(
|
|
|
197
197
|
*/
|
|
198
198
|
function processField(
|
|
199
199
|
fieldName: string,
|
|
200
|
-
fieldDef:
|
|
201
|
-
allFields: Record<string,
|
|
200
|
+
fieldDef: BDOFieldDefinitionType,
|
|
201
|
+
allFields: Record<string, BDOFieldDefinitionType>,
|
|
202
202
|
formValues: Record<string, any> = {},
|
|
203
|
-
permission?:
|
|
203
|
+
permission?: FieldPermissionType,
|
|
204
204
|
rules?: {
|
|
205
205
|
validation: string[];
|
|
206
206
|
computation: string[];
|
|
207
207
|
businessLogic: string[];
|
|
208
208
|
}
|
|
209
|
-
):
|
|
210
|
-
const defaultPermission:
|
|
209
|
+
): FormFieldConfigType {
|
|
210
|
+
const defaultPermission: FieldPermissionType = {
|
|
211
211
|
editable: true,
|
|
212
212
|
readable: true,
|
|
213
213
|
hidden: false,
|
|
@@ -256,21 +256,21 @@ function processField(
|
|
|
256
256
|
* Process complete BDO schema
|
|
257
257
|
*/
|
|
258
258
|
export function processSchema(
|
|
259
|
-
schema:
|
|
259
|
+
schema: BDOSchemaType,
|
|
260
260
|
formValues: Record<string, any> = {},
|
|
261
261
|
userRole?: string
|
|
262
|
-
):
|
|
262
|
+
): FormSchemaConfigType {
|
|
263
263
|
// Ensure schema is in BDO format
|
|
264
264
|
let bdoSchema = schema;
|
|
265
265
|
|
|
266
266
|
// Normalize BDO schema to ensure inline validation rules are centralized
|
|
267
267
|
bdoSchema = normalizeBDOSchema(bdoSchema);
|
|
268
268
|
|
|
269
|
-
const fields: Record<string,
|
|
269
|
+
const fields: Record<string, FormFieldConfigType> = {};
|
|
270
270
|
const fieldOrder: string[] = [];
|
|
271
271
|
const computedFields: string[] = [];
|
|
272
272
|
const requiredFields: string[] = [];
|
|
273
|
-
const crossFieldValidation:
|
|
273
|
+
const crossFieldValidation: SchemaValidationRuleType[] = [];
|
|
274
274
|
|
|
275
275
|
// Classify rules by type
|
|
276
276
|
const classifiedRules = classifyRules(bdoSchema);
|
|
@@ -339,7 +339,7 @@ export function processSchema(
|
|
|
339
339
|
* Update computed field values based on current form values
|
|
340
340
|
*/
|
|
341
341
|
export function updateComputedFields(
|
|
342
|
-
processedSchema:
|
|
342
|
+
processedSchema: FormSchemaConfigType,
|
|
343
343
|
currentValues: Record<string, any>
|
|
344
344
|
): Record<string, any> {
|
|
345
345
|
const computedValues: Record<string, any> = {};
|
|
@@ -401,7 +401,7 @@ function extractFieldDependencies(expressionTree: any): string[] {
|
|
|
401
401
|
* Build field dependency map
|
|
402
402
|
*/
|
|
403
403
|
export function buildDependencyMap(
|
|
404
|
-
processedSchema:
|
|
404
|
+
processedSchema: FormSchemaConfigType
|
|
405
405
|
): Record<string, string[]> {
|
|
406
406
|
const dependencyMap: Record<string, string[]> = {};
|
|
407
407
|
|
|
@@ -445,7 +445,7 @@ export function buildDependencyMap(
|
|
|
445
445
|
/**
|
|
446
446
|
* Validate processed schema
|
|
447
447
|
*/
|
|
448
|
-
export function validateSchema(processedSchema:
|
|
448
|
+
export function validateSchema(processedSchema: FormSchemaConfigType): {
|
|
449
449
|
isValid: boolean;
|
|
450
450
|
errors: string[];
|
|
451
451
|
} {
|
|
@@ -478,7 +478,7 @@ export function validateSchema(processedSchema: FormSchemaConfig): {
|
|
|
478
478
|
/**
|
|
479
479
|
* Build reference field configuration for API calls
|
|
480
480
|
*/
|
|
481
|
-
export function buildReferenceFieldConfig(field:
|
|
481
|
+
export function buildReferenceFieldConfig(field: FormFieldConfigType): any {
|
|
482
482
|
if (field.type !== "reference" || !field._bdoField.Values?.Reference) {
|
|
483
483
|
return null;
|
|
484
484
|
}
|
|
@@ -497,7 +497,7 @@ export function buildReferenceFieldConfig(field: FormFieldConfig): any {
|
|
|
497
497
|
* Extract all reference field configurations from schema
|
|
498
498
|
*/
|
|
499
499
|
export function extractReferenceFields(
|
|
500
|
-
processedSchema:
|
|
500
|
+
processedSchema: FormSchemaConfigType
|
|
501
501
|
): Record<string, any> {
|
|
502
502
|
const referenceFields: Record<string, any> = {};
|
|
503
503
|
|