TypeFetched/src/types/index.ts
Casey Collier b85b9a63e2 Initial commit: TypedFetch - Zero-dependency, type-safe HTTP client
Features:
- Zero configuration, just works out of the box
- Runtime type inference and validation
- Built-in caching with W-TinyLFU algorithm
- Automatic retries with exponential backoff
- Circuit breaker for resilience
- Request deduplication
- Offline support with queue
- OpenAPI schema discovery
- Full TypeScript support with type descriptors
- Modular architecture
- Configurable for advanced use cases

Built with bun, ready for npm publishing
2025-07-20 12:35:43 -04:00

43 lines
No EOL
951 B
TypeScript

/**
* TypedFetch - Type System and Core Types
*/
// Advanced TypeScript utilities for runtime type inference
export type InferFromJSON<T> = T extends string
? string
: T extends number
? number
: T extends boolean
? boolean
: T extends null
? null
: T extends Array<infer U>
? Array<InferFromJSON<U>>
: T extends Record<string, any>
? { [K in keyof T]: InferFromJSON<T[K]> }
: unknown
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
}
// Runtime type storage for discovered APIs
export interface TypeRegistry {
[endpoint: string]: {
request: any
response: any
method: string
lastSeen: number
samples: any[]
}
}
// Enhanced error types
export interface TypedError extends Error {
type: 'network' | 'http' | 'timeout' | 'circuit' | 'offline'
status?: number
retryable: boolean
retryAfter?: number
suggestions: string[]
debug: () => void
}