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