* fix(response): reset response size on endpoint change * test(request): move test to the right directory
117 lines
3.5 KiB
TypeScript
117 lines
3.5 KiB
TypeScript
import { AuthorizationContract } from '@/interfaces/auth/authorization';
|
|
import { RequestHeader } from '@/interfaces/http';
|
|
import { RouteDefinition } from '@/interfaces/routes/routes';
|
|
import { JsonSchema } from '@/interfaces/schema/shape';
|
|
import { ParametersExternalContract } from '@/interfaces/ui';
|
|
|
|
export enum RequestBodyTypeEnum {
|
|
EMPTY = 'empty',
|
|
JSON = 'json',
|
|
PLAIN_TEXT = 'plain-text',
|
|
FORM_DATA = 'form-data',
|
|
}
|
|
|
|
/**
|
|
* Represents a request that is being built and can be executed.
|
|
*
|
|
* Contains all the necessary data to construct and send an HTTP request.
|
|
*/
|
|
export interface PendingRequest {
|
|
/** HTTP method for the request (GET, POST, PUT, etc.) */
|
|
method: string;
|
|
|
|
/** API endpoint URL path */
|
|
endpoint: string;
|
|
|
|
/** HTTP headers to include with the request */
|
|
headers: RequestHeader[];
|
|
|
|
/**
|
|
* Request body data organized by HTTP method and payload type.
|
|
*
|
|
* Structure: { [method]: { [payloadType]: bodyData } }
|
|
*
|
|
* This allows storing different body content for different HTTP methods
|
|
* and payload types (JSON, FormData, etc.) for the same request,
|
|
* enabling users to switch between methods while preserving their input.
|
|
*
|
|
* Example: {
|
|
* "POST": {
|
|
* "json": '{"name": "John"}',
|
|
* "form-data": FormData object
|
|
* },
|
|
* "PUT": {
|
|
* "json": '{"id": 1, "name": "Jane"}'
|
|
* }
|
|
* }
|
|
*/
|
|
body: {
|
|
[_key in string]?: {
|
|
[_key in RequestBodyTypeEnum]?: FormData | string | null;
|
|
};
|
|
};
|
|
|
|
/** Query parameters to append to the request URL */
|
|
queryParameters: ParametersExternalContract[];
|
|
|
|
/** Currently selected payload type for the request body */
|
|
payloadType: RequestBodyTypeEnum;
|
|
|
|
/**
|
|
* Schema information for the current request.
|
|
*
|
|
* Contains the shape definition for request validation and
|
|
* any errors encountered during schema extraction from routes.
|
|
*/
|
|
schema: {
|
|
shape: JsonSchema;
|
|
extractionErrors: string | null;
|
|
};
|
|
|
|
/** Authorization configuration for the request */
|
|
authorization: AuthorizationContract;
|
|
|
|
/**
|
|
* All available routes for the current endpoint (different HTTP methods).
|
|
*
|
|
* Used to:
|
|
* - Categorize methods as "Supported" vs "Other" in the UI
|
|
* - Provide schema information when switching between HTTP methods
|
|
* - Enable method switching while preserving endpoint context
|
|
*
|
|
* Example: For endpoint "/users", this might contain:
|
|
* - GET /users (list users)
|
|
* - POST /users (create user)
|
|
* - PUT /users (update user)
|
|
*/
|
|
supportedRoutes: RouteDefinition[];
|
|
|
|
/**
|
|
* The currently selected route definition.
|
|
*
|
|
* Represents the specific route the user clicked on or selected,
|
|
* which serves as the base for the current request configuration.
|
|
* This is the "active" route that determines the initial method,
|
|
* endpoint, and schema for the request.
|
|
*/
|
|
routeDefinition: RouteDefinition;
|
|
|
|
/** Whether the request is currently being executed */
|
|
isProcessing?: boolean;
|
|
|
|
/** Request execution duration in milliseconds */
|
|
durationInMs?: number;
|
|
|
|
/** Whether the request was executed at least once */
|
|
wasExecuted?: boolean;
|
|
}
|
|
|
|
export interface Request {
|
|
method: string;
|
|
endpoint: string;
|
|
headers: RequestHeader[];
|
|
body: FormData | string | null;
|
|
queryParameters: ParametersExternalContract[];
|
|
payloadType: RequestBodyTypeEnum;
|
|
}
|