Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve Type Safety and Readability of Validation Logic #1659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/validations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,48 @@ import passportGated from './passport-gated';
import arbitrum from './arbitrum';
import karmaEasAttestation from './karma-eas-attestation';

// Типизация для validationInstance и структуры данных
interface ValidationInstance {
id: string;
github: string;
version: string;
title: string;
description: string;
proposalValidationOnly: boolean;
votingValidationOnly: boolean;
}

interface ValidationData {
validation: any;
examples: any | null;
schema: any | null;
about: string;
id: string;
github: string;
version: string;
title: string;
description: string;
proposalValidationOnly: boolean;
votingValidationOnly: boolean;
}

const validationClasses = {
basic,
'passport-gated': passportGated,
arbitrum: arbitrum,
'karma-eas-attestation': karmaEasAttestation
};

const validations = {};
Object.keys(validationClasses).forEach(function (validationName) {
const validations: { [key: string]: ValidationData } = {};

Object.keys(validationClasses).forEach((validationName) => {
let examples = null;
let schema = null;
let about = '';

try {
examples = JSON.parse(
readFileSync(
path.join(__dirname, validationName, 'examples.json'),
'utf8'
)
readFileSync(path.join(__dirname, validationName, 'examples.json'), 'utf8')
);
} catch (error) {
examples = null;
Expand All @@ -47,7 +70,7 @@ Object.keys(validationClasses).forEach(function (validationName) {
}

const validationClass = validationClasses[validationName];
const validationInstance = new validationClass();
const validationInstance: ValidationInstance = new validationClass();

validations[validationName] = {
validation: validationClass,
Expand Down