@bolttech/form-engine-core 0.0.1-beta.43 → 0.0.1-beta.44
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/index.esm.js +68 -43
- package/package.json +1 -1
- package/src/types/schema.d.ts +6 -0
- package/src/validations/number.d.ts +30 -0
package/index.esm.js
CHANGED
|
@@ -1222,6 +1222,44 @@ const between = (value, validations) => {
|
|
|
1222
1222
|
const num = Number(value);
|
|
1223
1223
|
return !Number.isNaN(num) && !(+num >= validations.between.start && +num <= validations.between.end);
|
|
1224
1224
|
};
|
|
1225
|
+
/**
|
|
1226
|
+
* Checks if a given value is less than a specified threshold.
|
|
1227
|
+
*
|
|
1228
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
1229
|
+
* @param validations - An object containing validation methods, specifically the `lessThan` property which holds the threshold value.
|
|
1230
|
+
* @returns Returns `false` if the `lessThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is greater than or equal to the `lessThan` threshold.
|
|
1231
|
+
*
|
|
1232
|
+
* @example
|
|
1233
|
+
* ```typescript
|
|
1234
|
+
* const validations = { lessThan: 10 };
|
|
1235
|
+
* console.log(lessThan(5, validations)); // true
|
|
1236
|
+
* console.log(lessThan(15, validations)); // false
|
|
1237
|
+
* ```
|
|
1238
|
+
*/
|
|
1239
|
+
const lessThan = (value, validations) => {
|
|
1240
|
+
const number = Number(value);
|
|
1241
|
+
if (!validations.lessThan || Number.isNaN(number)) return false;
|
|
1242
|
+
return number >= validations.lessThan;
|
|
1243
|
+
};
|
|
1244
|
+
/**
|
|
1245
|
+
* Checks if a given value is greater than a specified threshold.
|
|
1246
|
+
*
|
|
1247
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
1248
|
+
* @param validations - An object containing validation methods, specifically the `greaterThan` property which holds the threshold value.
|
|
1249
|
+
* @returns Returns `false` if the `greaterThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is less than or equal to the `greaterThan` threshold.
|
|
1250
|
+
*
|
|
1251
|
+
* @example
|
|
1252
|
+
* ```typescript
|
|
1253
|
+
* const validations = { greaterThan: 10 };
|
|
1254
|
+
* console.log(greaterThan(15, validations)); // true
|
|
1255
|
+
* console.log(greaterThan(5, validations)); // false
|
|
1256
|
+
* ```
|
|
1257
|
+
*/
|
|
1258
|
+
const greaterThan = (value, validations) => {
|
|
1259
|
+
const number = Number(value);
|
|
1260
|
+
if (!validations.greaterThan || Number.isNaN(number)) return false;
|
|
1261
|
+
return number <= validations.greaterThan;
|
|
1262
|
+
};
|
|
1225
1263
|
/**
|
|
1226
1264
|
* Validates if a value contains sequential numbers.
|
|
1227
1265
|
*
|
|
@@ -2327,6 +2365,8 @@ const multipleValidations = (value, methods) => {
|
|
|
2327
2365
|
const validations = {
|
|
2328
2366
|
max,
|
|
2329
2367
|
min,
|
|
2368
|
+
lessThan,
|
|
2369
|
+
greaterThan,
|
|
2330
2370
|
length,
|
|
2331
2371
|
regex,
|
|
2332
2372
|
url,
|
|
@@ -2873,6 +2913,17 @@ class FormField {
|
|
|
2873
2913
|
}) {
|
|
2874
2914
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2875
2915
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2916
|
+
const configRequest = config => __awaiter(this, void 0, void 0, function* () {
|
|
2917
|
+
try {
|
|
2918
|
+
const responseData = yield makeRequest(config.method, config.url, config.headers, config.body);
|
|
2919
|
+
const apiResponseData = JSON.parse(String(responseData));
|
|
2920
|
+
const response = config.resultPath ? get(apiResponseData, config.resultPath) : apiResponseData;
|
|
2921
|
+
// this.apiResponseData = { response };
|
|
2922
|
+
return response;
|
|
2923
|
+
} catch (e) {
|
|
2924
|
+
return !isNil(config === null || config === void 0 ? void 0 : config.fallbackValue) ? config.fallbackValue : 'error';
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2876
2927
|
if (!((_b = (_a = this.apiSchema) === null || _a === void 0 ? void 0 : _a.defaultConfig) === null || _b === void 0 ? void 0 : _b.events.includes(event)) && !(((_c = this.apiSchema) === null || _c === void 0 ? void 0 : _c.configs) && Object.keys((_d = this.apiSchema) === null || _d === void 0 ? void 0 : _d.configs).some(key => {
|
|
2877
2928
|
var _a, _b;
|
|
2878
2929
|
return (_b = (_a = this.apiSchema) === null || _a === void 0 ? void 0 : _a.configs) === null || _b === void 0 ? void 0 : _b[key].events.includes(event);
|
|
@@ -2883,19 +2934,10 @@ class FormField {
|
|
|
2883
2934
|
};
|
|
2884
2935
|
const config = (_e = this.apiSchema.defaultConfig) === null || _e === void 0 ? void 0 : _e.config;
|
|
2885
2936
|
if (config && ((_g = (_f = this.apiSchema) === null || _f === void 0 ? void 0 : _f.defaultConfig) === null || _g === void 0 ? void 0 : _g.events.includes(event)) && this.checkApiRequestValidations(config)) {
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
// this.apiResponseData = { response };
|
|
2891
|
-
responses.default = {
|
|
2892
|
-
response
|
|
2893
|
-
};
|
|
2894
|
-
} catch (e) {
|
|
2895
|
-
responses.default = {
|
|
2896
|
-
response: !isNil(config === null || config === void 0 ? void 0 : config.fallbackValue) ? config.fallbackValue : 'error'
|
|
2897
|
-
};
|
|
2898
|
-
}
|
|
2937
|
+
const response = yield configRequest(config);
|
|
2938
|
+
responses.default = {
|
|
2939
|
+
response
|
|
2940
|
+
};
|
|
2899
2941
|
}
|
|
2900
2942
|
if (((_h = this.apiSchema) === null || _h === void 0 ? void 0 : _h.configs) && Object.keys((_j = this.apiSchema) === null || _j === void 0 ? void 0 : _j.configs).some(key => {
|
|
2901
2943
|
var _a, _b;
|
|
@@ -2906,38 +2948,21 @@ class FormField {
|
|
|
2906
2948
|
@TODO handle promises with error
|
|
2907
2949
|
*/
|
|
2908
2950
|
const result = yield Promise.all(Object.keys(this.apiSchema.configs).map(configKey => __awaiter(this, void 0, void 0, function* () {
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
res({
|
|
2918
|
-
name: configKey,
|
|
2919
|
-
result: {
|
|
2920
|
-
response
|
|
2921
|
-
}
|
|
2922
|
-
});
|
|
2923
|
-
// responses.named![configKey] = { response };
|
|
2924
|
-
});
|
|
2925
|
-
} catch (e) {
|
|
2926
|
-
res({
|
|
2927
|
-
name: configKey,
|
|
2928
|
-
result: {
|
|
2929
|
-
response: !isNil(config.fallbackValue) ? config.fallbackValue : 'error'
|
|
2930
|
-
}
|
|
2931
|
-
});
|
|
2951
|
+
var _k, _l, _m, _o;
|
|
2952
|
+
const config = (_l = (_k = this.apiSchema) === null || _k === void 0 ? void 0 : _k.configs) === null || _l === void 0 ? void 0 : _l[configKey].config;
|
|
2953
|
+
if (config && ((_o = (_m = this.apiSchema) === null || _m === void 0 ? void 0 : _m.configs) === null || _o === void 0 ? void 0 : _o[configKey].events.includes(event)) && this.checkApiRequestValidations(config)) {
|
|
2954
|
+
const response = yield configRequest(config);
|
|
2955
|
+
return {
|
|
2956
|
+
name: configKey,
|
|
2957
|
+
result: {
|
|
2958
|
+
response
|
|
2932
2959
|
}
|
|
2933
|
-
}
|
|
2934
|
-
}
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
return null;
|
|
2935
2963
|
})));
|
|
2936
|
-
result.forEach(
|
|
2937
|
-
name
|
|
2938
|
-
result
|
|
2939
|
-
}) => {
|
|
2940
|
-
if (responses.named) responses.named[name] = result;
|
|
2964
|
+
result.forEach(payload => {
|
|
2965
|
+
if (payload && responses.named) responses.named[payload.name] = payload.result;
|
|
2941
2966
|
});
|
|
2942
2967
|
}
|
|
2943
2968
|
}
|
package/package.json
CHANGED
package/src/types/schema.d.ts
CHANGED
|
@@ -311,6 +311,8 @@ type TDateValidation = {
|
|
|
311
311
|
*
|
|
312
312
|
* @property {number} [max] - Maximum value or length.
|
|
313
313
|
* @property {number} [min] - Minimum value or length.
|
|
314
|
+
* @property {number} [lessThan] - Minimum value or length.
|
|
315
|
+
* @property {number} [greaterThan] - Minimum value or length.
|
|
314
316
|
* @property {TLengthValidation} [length] - Length validation rule.
|
|
315
317
|
* @property {boolean} [required] - Indicates if the field is required.
|
|
316
318
|
* @property {unknown} [value] - Specific value to match.
|
|
@@ -344,6 +346,8 @@ type TDateValidation = {
|
|
|
344
346
|
* const validationMethods: TValidationMethods = {
|
|
345
347
|
* max: 100,
|
|
346
348
|
* min: 1,
|
|
349
|
+
* lessThan: 1995,
|
|
350
|
+
* greaterThan: 82000,
|
|
347
351
|
* length: { rule: 'greaterOrEqual', target: 8 },
|
|
348
352
|
* required: true,
|
|
349
353
|
* regex: '^[a-zA-Z0-9]+$',
|
|
@@ -394,6 +398,8 @@ type TDateValidation = {
|
|
|
394
398
|
type TValidationMethods = {
|
|
395
399
|
max?: number;
|
|
396
400
|
min?: number;
|
|
401
|
+
lessThan?: number;
|
|
402
|
+
greaterThan?: number;
|
|
397
403
|
length?: TLengthValidation;
|
|
398
404
|
required?: boolean;
|
|
399
405
|
value?: unknown;
|
|
@@ -80,6 +80,36 @@ export declare const min: (value: unknown, validations: TValidationMethods) => b
|
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
82
|
export declare const between: (value: unknown, validations: TValidationMethods) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a given value is less than a specified threshold.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
87
|
+
* @param validations - An object containing validation methods, specifically the `lessThan` property which holds the threshold value.
|
|
88
|
+
* @returns Returns `false` if the `lessThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is greater than or equal to the `lessThan` threshold.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const validations = { lessThan: 10 };
|
|
93
|
+
* console.log(lessThan(5, validations)); // true
|
|
94
|
+
* console.log(lessThan(15, validations)); // false
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const lessThan: (value: unknown, validations: TValidationMethods) => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Checks if a given value is greater than a specified threshold.
|
|
100
|
+
*
|
|
101
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
102
|
+
* @param validations - An object containing validation methods, specifically the `greaterThan` property which holds the threshold value.
|
|
103
|
+
* @returns Returns `false` if the `greaterThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is less than or equal to the `greaterThan` threshold.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const validations = { greaterThan: 10 };
|
|
108
|
+
* console.log(greaterThan(15, validations)); // true
|
|
109
|
+
* console.log(greaterThan(5, validations)); // false
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare const greaterThan: (value: unknown, validations: TValidationMethods) => boolean;
|
|
83
113
|
/**
|
|
84
114
|
* Validates if a value contains sequential numbers.
|
|
85
115
|
*
|