File size: 988 Bytes
679ee5f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import { z } from 'zod';
// API Types
export const QuantumStateSchema = z.object({
coherence: z.number(),
stability: z.number(),
performance: z.number(),
timestamp: z.string(),
});
export type QuantumState = z.infer<typeof QuantumStateSchema>;
// API Client
class QuantumAPI {
private baseUrl: string;
constructor(baseUrl = '/api') {
this.baseUrl = baseUrl;
}
async getQuantumState(): Promise<QuantumState> {
const response = await fetch(`${this.baseUrl}/quantum/state`);
const data = await response.json();
return QuantumStateSchema.parse(data);
}
async updateQuantumState(state: Partial<QuantumState>): Promise<QuantumState> {
const response = await fetch(`${this.baseUrl}/quantum/state`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(state),
});
const data = await response.json();
return QuantumStateSchema.parse(data);
}
}
export const api = new QuantumAPI(); |