feat: implement bulk validate

This commit is contained in:
divocat
2025-10-03 01:53:03 +03:00
parent 547feb0e06
commit df9dba9742
4 changed files with 33 additions and 0 deletions

View 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,
};
}

View File

@@ -4,3 +4,4 @@ export * from './validateDns';
export * from './validateUrl';
export * from './validatePath';
export * from './validateSubnet';
export * from './bulkValidate';

View File

@@ -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>[];
}

View File

@@ -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,