mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-09 04:56:51 +03:00
feat: implement bulk validate
This commit is contained in:
13
fe-app-podkop/src/validators/bulkValidate.ts
Normal file
13
fe-app-podkop/src/validators/bulkValidate.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { BulkValidationResult, ValidationResult } from './types';
|
||||
|
||||
export function bulkValidate<T>(
|
||||
values: T[],
|
||||
validate: (value: T) => ValidationResult,
|
||||
): BulkValidationResult<T> {
|
||||
const results = values.map((value) => ({ ...validate(value), value }));
|
||||
|
||||
return {
|
||||
valid: results.every((r) => r.valid),
|
||||
results,
|
||||
};
|
||||
}
|
||||
@@ -4,3 +4,4 @@ export * from './validateDns';
|
||||
export * from './validateUrl';
|
||||
export * from './validatePath';
|
||||
export * from './validateSubnet';
|
||||
export * from './bulkValidate';
|
||||
|
||||
@@ -2,3 +2,12 @@ export interface ValidationResult {
|
||||
valid: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface BulkValidationResultItem<T> extends ValidationResult {
|
||||
value: T;
|
||||
}
|
||||
|
||||
export interface BulkValidationResult<T> {
|
||||
valid: boolean;
|
||||
results: BulkValidationResultItem<T>[];
|
||||
}
|
||||
|
||||
@@ -109,6 +109,15 @@ function validateSubnet(value) {
|
||||
return { valid: true, message: "Valid" };
|
||||
}
|
||||
|
||||
// src/validators/bulkValidate.ts
|
||||
function bulkValidate(values, validate) {
|
||||
const results = values.map((value) => ({ ...validate(value), value }));
|
||||
return {
|
||||
valid: results.every((r) => r.valid),
|
||||
results
|
||||
};
|
||||
}
|
||||
|
||||
// src/constants.ts
|
||||
var STATUS_COLORS = {
|
||||
SUCCESS: "#4caf50",
|
||||
@@ -242,6 +251,7 @@ return baseclass.extend({
|
||||
REGIONAL_OPTIONS,
|
||||
STATUS_COLORS,
|
||||
UPDATE_INTERVAL_OPTIONS,
|
||||
bulkValidate,
|
||||
getBaseUrl,
|
||||
validateDNS,
|
||||
validateDomain,
|
||||
|
||||
Reference in New Issue
Block a user