@flusys/nestjs-form-builder 7.1.0 → 8.0.0

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 (118) hide show
  1. package/config/index.d.ts +3 -3
  2. package/controllers/form-result.controller.d.ts +3 -3
  3. package/controllers/form.controller.d.ts +3 -3
  4. package/controllers/index.d.ts +2 -2
  5. package/docs/form-builder-swagger.config.d.ts +2 -2
  6. package/docs/index.d.ts +1 -1
  7. package/dtos/form.dto.d.ts +1 -1
  8. package/dtos/index.d.ts +2 -2
  9. package/entities/form-with-company.entity.d.ts +1 -1
  10. package/entities/form.entity.d.ts +1 -1
  11. package/entities/index.d.ts +7 -7
  12. package/enums/index.d.ts +1 -1
  13. package/fesm/262.js +1841 -0
  14. package/fesm/98.js +807 -0
  15. package/fesm/config/index.js +98 -3
  16. package/fesm/controllers/index.js +14 -2
  17. package/fesm/docs/index.js +171 -1
  18. package/fesm/dtos/index.js +571 -2
  19. package/fesm/entities/index.js +342 -10
  20. package/fesm/enums/index.js +38 -1
  21. package/fesm/index.js +482 -10
  22. package/fesm/interfaces/index.js +17 -3
  23. package/fesm/modules/index.js +178 -1
  24. package/fesm/runtime.js +85 -0
  25. package/fesm/services/index.js +35 -4
  26. package/index.d.ts +10 -10
  27. package/interfaces/form-builder-module.interface.d.ts +3 -3
  28. package/interfaces/form-result.interface.d.ts +1 -1
  29. package/interfaces/form.interface.d.ts +2 -2
  30. package/interfaces/index.d.ts +3 -3
  31. package/modules/form-builder.module.d.ts +2 -2
  32. package/modules/index.d.ts +1 -1
  33. package/package.json +26 -36
  34. package/services/form-builder-config.service.d.ts +4 -4
  35. package/services/form-builder-datasource.provider.d.ts +3 -3
  36. package/services/form-result.service.d.ts +6 -6
  37. package/services/form.service.d.ts +7 -7
  38. package/services/index.d.ts +4 -4
  39. package/utils/index.d.ts +2 -2
  40. package/utils/permission.utils.d.ts +1 -1
  41. package/cjs/config/event-actions.js +0 -33
  42. package/cjs/config/form-builder.constants.js +0 -13
  43. package/cjs/config/index.js +0 -20
  44. package/cjs/config/message-keys.js +0 -38
  45. package/cjs/controllers/form-result.controller.js +0 -281
  46. package/cjs/controllers/form-result.controller.spec.js +0 -257
  47. package/cjs/controllers/form.controller.js +0 -231
  48. package/cjs/controllers/form.controller.spec.js +0 -212
  49. package/cjs/controllers/index.js +0 -19
  50. package/cjs/docs/form-builder-swagger.config.js +0 -150
  51. package/cjs/docs/form-builder-swagger.config.spec.js +0 -75
  52. package/cjs/docs/index.js +0 -11
  53. package/cjs/dtos/form-result.dto.js +0 -248
  54. package/cjs/dtos/form.dto.js +0 -270
  55. package/cjs/dtos/index.js +0 -19
  56. package/cjs/entities/form-result.entity.js +0 -100
  57. package/cjs/entities/form-with-company.entity.js +0 -65
  58. package/cjs/entities/form.entity.js +0 -127
  59. package/cjs/entities/index.js +0 -52
  60. package/cjs/entities/index.spec.js +0 -18
  61. package/cjs/enums/form-access-type.enum.js +0 -19
  62. package/cjs/enums/index.js +0 -18
  63. package/cjs/index.js +0 -28
  64. package/cjs/interfaces/form-builder-module.interface.js +0 -4
  65. package/cjs/interfaces/form-result.interface.js +0 -4
  66. package/cjs/interfaces/form.interface.js +0 -4
  67. package/cjs/interfaces/index.js +0 -20
  68. package/cjs/modules/form-builder.module.js +0 -136
  69. package/cjs/modules/form-builder.module.spec.js +0 -133
  70. package/cjs/modules/index.js +0 -18
  71. package/cjs/services/form-builder-config.service.js +0 -69
  72. package/cjs/services/form-builder-config.service.spec.js +0 -121
  73. package/cjs/services/form-builder-datasource.provider.js +0 -125
  74. package/cjs/services/form-builder-datasource.provider.spec.js +0 -147
  75. package/cjs/services/form-result.service.js +0 -366
  76. package/cjs/services/form-result.service.spec.js +0 -823
  77. package/cjs/services/form.service.js +0 -341
  78. package/cjs/services/form.service.spec.js +0 -746
  79. package/cjs/services/index.js +0 -21
  80. package/cjs/utils/computed-field.utils.js +0 -199
  81. package/cjs/utils/computed-field.utils.spec.js +0 -1205
  82. package/cjs/utils/index.js +0 -19
  83. package/cjs/utils/permission.utils.js +0 -44
  84. package/cjs/utils/permission.utils.spec.js +0 -118
  85. package/fesm/config/event-actions.js +0 -12
  86. package/fesm/config/form-builder.constants.js +0 -3
  87. package/fesm/config/message-keys.js +0 -20
  88. package/fesm/controllers/form-result.controller.js +0 -271
  89. package/fesm/controllers/form-result.controller.spec.js +0 -253
  90. package/fesm/controllers/form.controller.js +0 -221
  91. package/fesm/controllers/form.controller.spec.js +0 -208
  92. package/fesm/docs/form-builder-swagger.config.js +0 -146
  93. package/fesm/docs/form-builder-swagger.config.spec.js +0 -71
  94. package/fesm/dtos/form-result.dto.js +0 -215
  95. package/fesm/dtos/form.dto.js +0 -243
  96. package/fesm/entities/form-result.entity.js +0 -90
  97. package/fesm/entities/form-with-company.entity.js +0 -55
  98. package/fesm/entities/form.entity.js +0 -117
  99. package/fesm/entities/index.spec.js +0 -14
  100. package/fesm/enums/form-access-type.enum.js +0 -9
  101. package/fesm/interfaces/form-builder-module.interface.js +0 -3
  102. package/fesm/interfaces/form-result.interface.js +0 -6
  103. package/fesm/interfaces/form.interface.js +0 -3
  104. package/fesm/modules/form-builder.module.js +0 -126
  105. package/fesm/modules/form-builder.module.spec.js +0 -129
  106. package/fesm/services/form-builder-config.service.js +0 -59
  107. package/fesm/services/form-builder-config.service.spec.js +0 -117
  108. package/fesm/services/form-builder-datasource.provider.js +0 -74
  109. package/fesm/services/form-builder-datasource.provider.spec.js +0 -143
  110. package/fesm/services/form-result.service.js +0 -356
  111. package/fesm/services/form-result.service.spec.js +0 -778
  112. package/fesm/services/form.service.js +0 -331
  113. package/fesm/services/form.service.spec.js +0 -701
  114. package/fesm/utils/computed-field.utils.js +0 -195
  115. package/fesm/utils/computed-field.utils.spec.js +0 -1201
  116. package/fesm/utils/index.js +0 -2
  117. package/fesm/utils/permission.utils.js +0 -42
  118. package/fesm/utils/permission.utils.spec.js +0 -114
@@ -1,195 +0,0 @@
1
- /**
2
- * Computed Field Calculation Utilities
3
- *
4
- * This module provides functions to calculate computed field values
5
- * based on form submission data and computed field definitions.
6
- *
7
- * NOTE: Interface definitions here mirror @flusys/ng-form-builder interfaces
8
- * but are defined separately to avoid cross-package dependencies.
9
- * Both use compatible JSON structures for form schema serialization.
10
- *
11
- * @see FLUSYS_NG/projects/ng-form-builder/interfaces/computed-field.interface.ts
12
- */ // ============================================================================
13
- // Type Definitions
14
- // ============================================================================
15
- // ============================================================================
16
- // Type Guards & Helpers
17
- // ============================================================================
18
- function isObject(value) {
19
- return typeof value === 'object' && value !== null;
20
- }
21
- function isDirectValueConfig(config) {
22
- return isObject(config) && config.type === 'direct' && 'value' in config;
23
- }
24
- function isFieldReferenceConfig(config) {
25
- return isObject(config) && config.type === 'field_reference' && 'fieldId' in config;
26
- }
27
- function isArithmeticConfig(config) {
28
- return isObject(config) && config.type === 'arithmetic' && 'operation' in config && 'operands' in config && Array.isArray(config.operands);
29
- }
30
- function isEmptyValue(value) {
31
- return value === null || value === undefined || value === '' || Array.isArray(value) && value.length === 0;
32
- }
33
- /**
34
- * Normalize operator to uppercase string (handles both enum and string values)
35
- */ function normalizeOperator(op) {
36
- const strOp = String(op).toUpperCase();
37
- return strOp === 'OR' ? 'OR' : 'AND';
38
- }
39
- /**
40
- * Calculate all computed fields for a form submission
41
- *
42
- * @param formData - The submitted form data (field values by field ID)
43
- * @param computedFields - Array of computed field definitions from form settings
44
- * @returns Object containing computed field values keyed by their key property
45
- */ export function calculateComputedFields(formData, computedFields) {
46
- if (!computedFields || computedFields.length === 0) {
47
- return {};
48
- }
49
- const result = {};
50
- for (const field of computedFields){
51
- try {
52
- const value = calculateComputedField(formData, field);
53
- result[field.key] = value;
54
- } catch (error) {
55
- // If calculation fails, use default value or null
56
- result[field.key] = field.defaultValue ?? null;
57
- }
58
- }
59
- return result;
60
- }
61
- /**
62
- * Calculate a single computed field value
63
- */ function calculateComputedField(formData, field) {
64
- // Evaluate rules in order, first matching rule wins
65
- for (const rule of field.rules){
66
- if (evaluateCondition(formData, rule.condition)) {
67
- return executeComputation(formData, rule.computation, field.valueType);
68
- }
69
- }
70
- // No rule matched, return default
71
- return field.defaultValue ?? null;
72
- }
73
- /**
74
- * Evaluate a condition group
75
- */ function evaluateCondition(formData, conditionGroup) {
76
- // No condition = always true
77
- if (!conditionGroup || !conditionGroup.conditions || conditionGroup.conditions.length === 0) {
78
- return true;
79
- }
80
- const results = conditionGroup.conditions.map((condition)=>evaluateSingleCondition(formData, condition));
81
- // Normalize operator to handle both string and enum values
82
- const operator = normalizeOperator(conditionGroup.operator);
83
- if (operator === 'AND') {
84
- return results.every((r)=>r);
85
- } else {
86
- return results.some((r)=>r);
87
- }
88
- }
89
- /**
90
- * Evaluate a single condition
91
- */ function evaluateSingleCondition(formData, condition) {
92
- const fieldValue = formData[condition.fieldId];
93
- const compareValue = condition.value;
94
- switch(condition.comparison){
95
- case 'equals':
96
- return fieldValue === compareValue || String(fieldValue) === String(compareValue);
97
- case 'not_equals':
98
- return fieldValue !== compareValue && String(fieldValue) !== String(compareValue);
99
- case 'is_empty':
100
- return isEmptyValue(fieldValue);
101
- case 'is_not_empty':
102
- return !isEmptyValue(fieldValue);
103
- case 'contains':
104
- return String(fieldValue).includes(String(compareValue));
105
- case 'not_contains':
106
- return !String(fieldValue).includes(String(compareValue));
107
- case 'starts_with':
108
- return String(fieldValue).startsWith(String(compareValue));
109
- case 'ends_with':
110
- return String(fieldValue).endsWith(String(compareValue));
111
- case 'greater_than':
112
- return Number(fieldValue) > Number(compareValue);
113
- case 'less_than':
114
- return Number(fieldValue) < Number(compareValue);
115
- case 'greater_or_equal':
116
- return Number(fieldValue) >= Number(compareValue);
117
- case 'less_or_equal':
118
- return Number(fieldValue) <= Number(compareValue);
119
- case 'is_before':
120
- return new Date(String(fieldValue)) < new Date(String(compareValue));
121
- case 'is_after':
122
- return new Date(String(fieldValue)) > new Date(String(compareValue));
123
- case 'is_checked':
124
- return fieldValue === true || fieldValue === 'true' || fieldValue === 1;
125
- case 'is_not_checked':
126
- return fieldValue === false || fieldValue === 'false' || fieldValue === 0 || !fieldValue;
127
- case 'is_any_of':
128
- case 'in':
129
- return Array.isArray(compareValue) && compareValue.includes(fieldValue);
130
- case 'is_none_of':
131
- case 'not_in':
132
- return !Array.isArray(compareValue) || !compareValue.includes(fieldValue);
133
- default:
134
- return false;
135
- }
136
- }
137
- /**
138
- * Execute a computation and return the result
139
- */ function executeComputation(formData, computation, valueType) {
140
- const { config } = computation;
141
- // Use type guards for safe access
142
- if (computation.type === 'direct' && isDirectValueConfig(config)) {
143
- return valueType === 'number' ? Number(config.value) : String(config.value);
144
- }
145
- if (computation.type === 'field_reference' && isFieldReferenceConfig(config)) {
146
- const value = formData[config.fieldId];
147
- if (value === null || value === undefined) {
148
- return null;
149
- }
150
- return valueType === 'number' ? Number(value) : String(value);
151
- }
152
- if (computation.type === 'arithmetic' && isArithmeticConfig(config)) {
153
- return calculateArithmetic(formData, config);
154
- }
155
- // Unknown computation type
156
- return null;
157
- }
158
- /**
159
- * Perform arithmetic calculation
160
- */ function calculateArithmetic(formData, config) {
161
- const values = config.operands.map((operand)=>{
162
- if (operand.type === 'constant') {
163
- return operand.value ?? 0;
164
- } else {
165
- const fieldValue = formData[operand.fieldId ?? ''];
166
- return fieldValue !== null && fieldValue !== undefined ? Number(fieldValue) : 0;
167
- }
168
- });
169
- if (values.length === 0) {
170
- return null;
171
- }
172
- switch(config.operation){
173
- case 'sum':
174
- case 'increment':
175
- return values.reduce((acc, val)=>acc + val, 0);
176
- case 'subtract':
177
- case 'decrement':
178
- return values.reduce((acc, val, idx)=>idx === 0 ? val : acc - val, 0);
179
- case 'multiply':
180
- return values.reduce((acc, val)=>acc * val, 1);
181
- case 'divide':
182
- {
183
- const [first, ...rest] = values;
184
- return rest.reduce((acc, val)=>val !== 0 ? acc / val : acc, first);
185
- }
186
- case 'average':
187
- return values.reduce((acc, val)=>acc + val, 0) / values.length;
188
- case 'min':
189
- return Math.min(...values);
190
- case 'max':
191
- return Math.max(...values);
192
- default:
193
- return null;
194
- }
195
- }