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
53 lines
No EOL
1.8 KiB
TypeScript
53 lines
No EOL
1.8 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { tf } from '../src/index.js'
|
|
|
|
console.log('🔍 Verbose Test - Step by Step')
|
|
console.log('==============================')
|
|
|
|
async function verboseTest() {
|
|
try {
|
|
console.log('\n1. Making basic GET request...')
|
|
console.log(' URL: https://api.github.com/users/torvalds')
|
|
|
|
const start = performance.now()
|
|
const result = await tf.get('https://api.github.com/users/torvalds')
|
|
const duration = performance.now() - start
|
|
|
|
console.log(` ✅ Success in ${duration.toFixed(2)}ms`)
|
|
console.log(' Data received:', result.data ? 'Yes' : 'No')
|
|
console.log(' User login:', result.data?.login)
|
|
|
|
console.log('\n2. Checking type inference...')
|
|
const types = tf.getAllTypes()
|
|
console.log(' Endpoints tracked:', Object.keys(types).length)
|
|
|
|
console.log('\n3. Checking metrics...')
|
|
const metrics = tf.getMetrics()
|
|
console.log(' Total requests:', metrics.totalRequests)
|
|
console.log(' Cache hits:', metrics.cacheHits)
|
|
console.log(' Avg response time:', metrics.avgResponseTime?.toFixed(2) + 'ms')
|
|
|
|
console.log('\n4. Making cached request...')
|
|
const start2 = performance.now()
|
|
const result2 = await tf.get('https://api.github.com/users/torvalds')
|
|
const duration2 = performance.now() - start2
|
|
console.log(` ✅ Cached response in ${duration2.toFixed(2)}ms`)
|
|
console.log(` Performance improvement: ${((duration - duration2) / duration * 100).toFixed(1)}%`)
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message)
|
|
console.error('Type:', error.type)
|
|
console.error('Suggestions:', error.suggestions)
|
|
if (error.debug) {
|
|
error.debug()
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log('Starting test...')
|
|
verboseTest().then(() => {
|
|
console.log('\n✅ Test completed successfully!')
|
|
}).catch(error => {
|
|
console.error('\n❌ Test failed:', error)
|
|
}) |