/* Copyright 2026 Marimo. All rights reserved. */ import type { SQLSchemaListPreview, SQLTableListPreview, SQLTablePreview, ValidateSQLResult, } from "../kernel/messages"; import { CachingRequestRegistry } from "../network/CachingRequestRegistry"; import { DeferredRequestRegistry } from "../network/DeferredRequestRegistry"; import { getRequestClient } from "../network/requests"; import type { ListSQLSchemasRequest, ListSQLTablesRequest, PreviewSQLTableRequest, ValidateSQLRequest, } from "../network/types"; // We make a request to the backend to preview the table, passing in Engine, DB, Schema, and Table // The backend returns data tables, which could also exist in other engines, dbs, schemas // Thus, we use the request ID pattern to match the response to the request export const PreviewSQLTable = new DeferredRequestRegistry< Omit, SQLTablePreview >("sql-table-preview", async (requestId, req) => { const client = getRequestClient(); await client.previewSQLTable({ requestId: requestId, ...req, }); }); export const PreviewSQLSchemaList = new DeferredRequestRegistry< Omit, SQLSchemaListPreview >("sql-schema-list-preview", async (requestId, req) => { const client = getRequestClient(); await client.previewSQLSchemaList({ requestId: requestId, ...req, }); }); export const PreviewSQLTableList = new DeferredRequestRegistry< Omit, SQLTableListPreview >("sql-table-list-preview", async (requestId, req) => { const client = getRequestClient(); await client.previewSQLTableList({ requestId: requestId, ...req, }); }); export const ValidateSQL = new CachingRequestRegistry( new DeferredRequestRegistry< Omit, ValidateSQLResult >("validate-sql", async (requestId, req) => { const client = getRequestClient(); await client.validateSQL({ requestId: requestId, ...req, }); }), { // Only keep the last 3 validation results maxSize: 3, }, );