File size: 2,659 Bytes
c21180c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ac8526
 
 
 
 
 
 
 
 
 
c21180c
 
 
 
 
 
 
 
 
018ab56
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import axios from 'axios';

const api = axios.create({
  baseURL: import.meta.env.VITE_API_URL || '',
  withCredentials: true,
  headers: { 'Content-Type': 'application/json' },
});

api.interceptors.response.use(
  (response) => response,
  (error) => {
    const message = error.response?.data?.detail || error.message || 'An error occurred';
    return Promise.reject(new Error(message));
  },
);

export default api;

export async function uploadCSV(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  const res = await api.post('/api/upload/csv', formData, {
    headers: { 'Content-Type': 'multipart/form-data' },
  });
  return res.data;
}

export async function getSchema() {
  const res = await api.get('/api/schema');
  return res.data;
}

export async function getRows(offset = 0, limit = 50) {
  const res = await api.get('/api/rows', { params: { offset, limit } });
  return res.data;
}

export async function listOperations() {
  const res = await api.get('/api/ops');
  return res.data;
}

export async function applyOperation(opKey: string, params: Record<string, any>) {
  const res = await api.post(`/api/ops/${opKey}`, { params });
  return res.data;
}

export async function undo() {
  const res = await api.post('/api/history/undo');
  return res.data;
}

export async function redo() {
  const res = await api.post('/api/history/redo');
  return res.data;
}

export async function getHistory() {
  const res = await api.get('/api/history');
  return res.data;
}

export async function createChart(req: { chart_type: string; params: Record<string, any> }) {
  const res = await api.post('/api/viz/chart', req);
  return res.data;
}

export async function exportCSV() {
  const res = await api.get('/api/export/csv', { responseType: 'blob' });
  return res.data;
}

export async function editCell(rowIndex: number, column: string, newValue: string) {
  const res = await api.put('/api/edit/cell', null, { params: { row_index: rowIndex, column, new_value: newValue } });
  return res.data;
}

export async function exportNotebook() {
  const res = await api.post('/api/export/notebook');
  return res.data;
}

export async function createCheckpoint() {
  const res = await api.post('/api/checkpoint');
  return res.data;
}

export async function checkHealth() {
  const res = await api.get('/health');
  return res.data;
}

export async function getDemo() {
  const res = await api.get('/api/demo');
  return res.data as { available: boolean; filename?: string; row_count?: number; columns?: any[] };
}

export async function loadDemo() {
  const res = await api.post('/api/demo/load');
  return res.data;
}