add modern version of request construction
This commit is contained in:
49
ts/modern/types/common.ts
Normal file
49
ts/modern/types/common.ts
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* HTTP Methods supported by the client
|
||||
*/
|
||||
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
||||
|
||||
/**
|
||||
* Response types supported by the client
|
||||
*/
|
||||
export type ResponseType = 'json' | 'text' | 'binary' | 'stream';
|
||||
|
||||
/**
|
||||
* Form field data for multipart/form-data requests
|
||||
*/
|
||||
export interface FormField {
|
||||
name: string;
|
||||
value: string | Buffer;
|
||||
filename?: string;
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL encoded form field
|
||||
*/
|
||||
export interface UrlEncodedField {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry configuration
|
||||
*/
|
||||
export interface RetryConfig {
|
||||
attempts: number; // Number of retry attempts
|
||||
initialDelay?: number; // Initial delay in ms
|
||||
maxDelay?: number; // Maximum delay in ms
|
||||
factor?: number; // Backoff factor
|
||||
statusCodes?: number[]; // Status codes to retry on
|
||||
shouldRetry?: (error: Error, attemptCount: number) => boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timeout configuration
|
||||
*/
|
||||
export interface TimeoutConfig {
|
||||
request?: number; // Overall request timeout in ms
|
||||
connection?: number; // Connection timeout in ms
|
||||
socket?: number; // Socket idle timeout in ms
|
||||
response?: number; // Response timeout in ms
|
||||
}
|
66
ts/modern/types/pagination.ts
Normal file
66
ts/modern/types/pagination.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { type IExtendedIncomingMessage } from '../../legacy/smartrequest.request.js';
|
||||
|
||||
/**
|
||||
* Pagination strategy options
|
||||
*/
|
||||
export enum PaginationStrategy {
|
||||
OFFSET = 'offset', // Uses page & limit parameters
|
||||
CURSOR = 'cursor', // Uses a cursor/token for next page
|
||||
LINK_HEADER = 'link', // Uses Link headers
|
||||
CUSTOM = 'custom' // Uses a custom pagination handler
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for offset-based pagination
|
||||
*/
|
||||
export interface OffsetPaginationConfig {
|
||||
strategy: PaginationStrategy.OFFSET;
|
||||
pageParam?: string; // Parameter name for page number (default: "page")
|
||||
limitParam?: string; // Parameter name for page size (default: "limit")
|
||||
startPage?: number; // Starting page number (default: 1)
|
||||
pageSize?: number; // Number of items per page (default: 20)
|
||||
totalPath?: string; // JSON path to total item count (default: "total")
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for cursor-based pagination
|
||||
*/
|
||||
export interface CursorPaginationConfig {
|
||||
strategy: PaginationStrategy.CURSOR;
|
||||
cursorParam?: string; // Parameter name for cursor (default: "cursor")
|
||||
cursorPath?: string; // JSON path to next cursor (default: "nextCursor")
|
||||
hasMorePath?: string; // JSON path to check if more items exist (default: "hasMore")
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for Link header-based pagination
|
||||
*/
|
||||
export interface LinkPaginationConfig {
|
||||
strategy: PaginationStrategy.LINK_HEADER;
|
||||
// No additional config needed, uses standard Link header format
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for custom pagination
|
||||
*/
|
||||
export interface CustomPaginationConfig {
|
||||
strategy: PaginationStrategy.CUSTOM;
|
||||
hasNextPage: (response: IExtendedIncomingMessage<any>) => boolean;
|
||||
getNextPageParams: (response: IExtendedIncomingMessage<any>, currentParams: Record<string, string>) => Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Union type of all pagination configurations
|
||||
*/
|
||||
export type TPaginationConfig = OffsetPaginationConfig | CursorPaginationConfig | LinkPaginationConfig | CustomPaginationConfig;
|
||||
|
||||
/**
|
||||
* Interface for a paginated response
|
||||
*/
|
||||
export interface TPaginatedResponse<T> {
|
||||
items: T[]; // Current page items
|
||||
hasNextPage: boolean; // Whether there are more pages
|
||||
getNextPage: () => Promise<TPaginatedResponse<T>>; // Function to get the next page
|
||||
getAllPages: () => Promise<T[]>; // Function to get all remaining pages and combine
|
||||
response: IExtendedIncomingMessage<any>; // Original response
|
||||
}
|
Reference in New Issue
Block a user