import { post } from '../../utils/post'; class Database { private _tables: string; constructor() { this._tables = ''; } tables(tables: string | { Name: string }[]) { this._tables = Array.isArray(tables) ? tables.map((table) => table.Name).join(',') : tables; return this; } async optimize() { try { const res = await post('optimize_table', { tables: this._tables }); // wp_send_json_error() answers HTTP 200 with success: false. if (res?.success === false) { return { error: { status: 200, statusText: res.data?.description ?? '' } }; } return { status: 200, tables: this._tables }; } catch (error) { // eslint-disable-next-line no-console -- surfaced for debugging; the UI shows its own error. console.error(error); return { error }; } } async resetAutoIncrement() { try { const res = await post('reset_auto_increment', { tables: this._tables }); // wp_send_json_error() answers HTTP 200 with success: false. if (res?.success === false) { return { error: { status: 200, statusText: res.data?.description ?? '' } }; } return { status: 200, tables: this._tables }; } catch (error) { // eslint-disable-next-line no-console -- surfaced for debugging; the UI shows its own error. console.error(error); return { error }; } } } export default new Database();