schema.ts


Overview

The schema.ts file defines TypeScript schemas for form data validation using the Zod library. It provides structured validation rules for a form containing HTTP request parameters and an array of key-value variables, ensuring that the input data conforms to expected types and formats before further processing.

This file is primarily responsible for:


Detailed Explanation

Imports

import { z } from 'zod';

VariableFormSchema

export const VariableFormSchema = z.object({
  key: z.string(),
  ref: z.string(),
  value: z.string(),
});

Description

Defines the schema for an individual variable object used within the main form. Each variable has three string properties.

Properties

Property

Type

Description

key

string

The key name of the variable.

ref

string

A reference identifier.

value

string

The value assigned to the variable.

Usage Example

const exampleVar = {
  key: "username",
  ref: "user_ref_123",
  value: "john_doe",
};

const parsedVar = VariableFormSchema.parse(exampleVar); // Validates `exampleVar`

FormSchema

export const FormSchema = z.object({
  url: z.string().url(),
  method: z.string(),
  timeout: z.number(),
  headers: z.string(),
  proxy: z.string().url(),
  clean_html: z.boolean(),
  variables: z.array(VariableFormSchema),
});

Description

Defines the main form schema representing HTTP request configuration details and a list of variables.

Properties

Property

Type

Description

url

string (URL format)

The target URL for the HTTP request.

method

string

The HTTP method (e.g., GET, POST).

timeout

number

Request timeout duration in milliseconds or seconds.

headers

string

HTTP headers represented as a string (likely JSON or raw).

proxy

string (URL format)

Proxy URL to route the HTTP request through.

clean_html

boolean

Flag indicating whether to clean HTML content in the response.

variables

array of VariableFormSchema

List of variable objects to be included in the form.

Usage Example

const exampleForm = {
  url: "https://api.example.com/data",
  method: "POST",
  timeout: 5000,
  headers: '{"Content-Type": "application/json"}',
  proxy: "https://proxy.example.com",
  clean_html: true,
  variables: [
    { key: "token", ref: "auth", value: "xyz123" },
    { key: "userId", ref: "user", value: "42" },
  ],
};

const parsedForm = FormSchema.parse(exampleForm); // Validates `exampleForm`

TypeScript Type Inference

export type FormSchemaType = z.infer<typeof FormSchema>;

export type VariableFormSchemaType = z.infer<typeof VariableFormSchema>;

These types can be used for static type checking throughout the application, ensuring consistency between validation and usage.


Implementation Details & Algorithms


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class VariableFormSchema {
        +key: string
        +ref: string
        +value: string
    }

    class FormSchema {
        +url: string (URL)
        +method: string
        +timeout: number
        +headers: string
        +proxy: string (URL)
        +clean_html: boolean
        +variables: VariableFormSchema[]
    }

    FormSchema --> "0..*" VariableFormSchema : contains

Summary