@querypanel/node-sdk 1.3.3 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -37,7 +37,27 @@ interface IntrospectOptions {
37
37
  tables?: string[];
38
38
  }
39
39
 
40
- type DatabaseDialect = "bigquery" | "clickhouse" | "postgres" | "mysql";
40
+ type DatabaseDialect = "bigquery" | "clickhouse" | "postgres" | "redshift" | "mysql";
41
+ /** A schema (or ClickHouse database / BigQuery dataset) in the catalog. */
42
+ interface CatalogSchema {
43
+ schema: string;
44
+ tableCount: number;
45
+ }
46
+ type CatalogTableType = "table" | "view" | "materialized_view";
47
+ /** A table or view in the catalog (no columns; cheap to list). */
48
+ interface CatalogTable {
49
+ schema: string;
50
+ name: string;
51
+ type: CatalogTableType;
52
+ }
53
+ interface ListTablesOptions {
54
+ /** Only list tables in this schema. */
55
+ schema?: string;
56
+ /** Case-insensitive substring match on the table name. */
57
+ search?: string;
58
+ /** Max rows to return. Default 500, capped at 5000. */
59
+ limit?: number;
60
+ }
41
61
  interface DatabaseExecutionResult {
42
62
  fields: string[];
43
63
  rows: Array<Record<string, unknown>>;
@@ -68,6 +88,14 @@ interface DatabaseAdapter {
68
88
  * Get the database dialect/type
69
89
  */
70
90
  getDialect(): DatabaseDialect;
91
+ /**
92
+ * Optional: List schemas with table counts (cheap catalog read for pickers).
93
+ */
94
+ listSchemas?(): Promise<CatalogSchema[]>;
95
+ /**
96
+ * Optional: List tables/views without columns (cheap catalog read for pickers).
97
+ */
98
+ listTables?(options?: ListTablesOptions): Promise<CatalogTable[]>;
71
99
  /**
72
100
  * Optional: Close/cleanup database connection
73
101
  */
@@ -108,6 +136,7 @@ interface BigQueryAdapterOptions {
108
136
  kind?: SchemaIntrospection["db"]["kind"];
109
137
  /**
110
138
  * Optional allow-list of table names (dataset.table or bare table name).
139
+ * `*` or `<dataset>.*` allows every table in the dataset (same as no filter).
111
140
  * When specified, introspection and queries are restricted to these tables only.
112
141
  */
113
142
  allowedTables?: string[];
@@ -135,6 +164,14 @@ declare class BigQueryAdapter implements DatabaseAdapter {
135
164
  * Restricts to the default dataset (or allowedTables) and returns tables/columns only.
136
165
  */
137
166
  introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
167
+ /** The adapter is bound to one dataset, so this returns a single row. */
168
+ listSchemas(): Promise<CatalogSchema[]>;
169
+ /**
170
+ * List tables in the bound dataset. Reads the full catalog (not restricted
171
+ * by `allowedTables`). Default limit 500, max 5000.
172
+ */
173
+ listTables(options?: ListTablesOptions): Promise<CatalogTable[]>;
174
+ private informationSchema;
138
175
  private validateQueryTables;
139
176
  }
140
177
 
@@ -152,6 +189,7 @@ interface ClickHouseAdapterOptions {
152
189
  * Optional allow-list of table names.
153
190
  * When specified, introspection and queries are restricted to these tables only.
154
191
  * ClickHouse tables are not schema-qualified, so just provide table names.
192
+ * `*` or `<database>.*` allows every table (same as no filter).
155
193
  */
156
194
  allowedTables?: string[];
157
195
  }
@@ -179,6 +217,13 @@ declare class ClickHouseAdapter implements DatabaseAdapter {
179
217
  * No indexes, constraints, or statistics
180
218
  */
181
219
  introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
220
+ /** The adapter is bound to one database, so this returns a single row. */
221
+ listSchemas(): Promise<CatalogSchema[]>;
222
+ /**
223
+ * List tables in the bound database. Reads the full catalog (not restricted
224
+ * by `allowedTables`). Default limit 500, max 5000.
225
+ */
226
+ listTables(options?: ListTablesOptions): Promise<CatalogTable[]>;
182
227
  private validateQueryTables;
183
228
  close(): Promise<void>;
184
229
  private query;
@@ -192,16 +237,24 @@ interface PostgresQueryResult {
192
237
  }>;
193
238
  }
194
239
  type PostgresClientFn = (sql: string, params?: unknown[]) => Promise<PostgresQueryResult>;
240
+ type PostgresWireDialect = "postgres" | "redshift";
195
241
  interface PostgresAdapterOptions {
196
242
  /** Logical database name used in introspection metadata. */
197
243
  database?: string;
198
244
  /** Schema to assume when a table is provided without qualification. */
199
245
  defaultSchema?: string;
200
- /** Optional database kind label. Defaults to "postgres". */
246
+ /** Optional database kind label. Defaults to the dialect. */
201
247
  kind?: SchemaIntrospection["db"]["kind"];
248
+ /**
249
+ * Wire-compatible engine behind the client. "redshift" uses Redshift's
250
+ * svv_* catalog views for introspection. Defaults to "postgres".
251
+ */
252
+ dialect?: PostgresWireDialect;
202
253
  /**
203
254
  * Optional allow-list of table names (schema-qualified or bare).
204
- * When specified, introspection and queries are restricted to these tables only.
255
+ * Use `schema.*` to allow every table in a schema (a bare `*` means the
256
+ * default schema). When specified, introspection and queries are restricted
257
+ * to these tables only.
205
258
  */
206
259
  allowedTables?: string[];
207
260
  }
@@ -215,6 +268,7 @@ declare class PostgresAdapter implements DatabaseAdapter {
215
268
  private readonly databaseName;
216
269
  private readonly defaultSchema;
217
270
  private readonly kind;
271
+ private readonly dialect;
218
272
  private readonly allowedTables?;
219
273
  constructor(clientFn: PostgresClientFn, options?: PostgresAdapterOptions);
220
274
  execute(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<DatabaseExecutionResult>;
@@ -225,7 +279,18 @@ declare class PostgresAdapter implements DatabaseAdapter {
225
279
  */
226
280
  private convertNamedToPositionalParams;
227
281
  validate(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<void>;
228
- getDialect(): "postgres";
282
+ getDialect(): PostgresWireDialect;
283
+ /**
284
+ * List schemas with their table/view counts. Reads the full catalog (not
285
+ * restricted by `allowedTables`) so it can back an allowed-tables picker.
286
+ */
287
+ listSchemas(): Promise<CatalogSchema[]>;
288
+ /**
289
+ * List tables/views, optionally filtered by schema and a case-insensitive
290
+ * substring of the table name. Reads the full catalog (not restricted by
291
+ * `allowedTables`). Default limit 500, max 5000.
292
+ */
293
+ listTables(options?: ListTablesOptions): Promise<CatalogTable[]>;
229
294
  /**
230
295
  * Simplified introspection: only collect table/column metadata for IngestRequest
231
296
  * No indexes, constraints, or statistics
@@ -334,6 +399,17 @@ declare class QueryPipelineError extends Error {
334
399
  */
335
400
  isAiProviderError(): boolean;
336
401
  }
402
+ /**
403
+ * Thrown by stageSchemaIngest / syncSchemaInBatches when the introspected schema
404
+ * has more columns than `maxColumns`. Raised before anything is uploaded; narrow
405
+ * the sync with `allowedTables` / `tables` (e.g. `schema.*`) and retry.
406
+ */
407
+ declare class SchemaTooLargeError extends Error {
408
+ readonly tableCount: number;
409
+ readonly columnCount: number;
410
+ readonly maxColumns: number;
411
+ constructor(tableCount: number, columnCount: number, maxColumns: number);
412
+ }
337
413
 
338
414
  type ParamValue = string | number | boolean | string[] | number[];
339
415
  type ParamRecord = Record<string, ParamValue>;
@@ -541,6 +617,57 @@ interface SchemaSyncOptions {
541
617
  tables?: string[];
542
618
  forceReindex?: boolean;
543
619
  }
620
+ /** Progress events emitted by stageSchemaIngest / syncSchemaInBatches. */
621
+ type SchemaSyncProgressEvent = {
622
+ phase: "introspecting";
623
+ } | {
624
+ phase: "introspected";
625
+ tableCount: number;
626
+ columnCount: number;
627
+ } | {
628
+ phase: "uploading";
629
+ done: number;
630
+ total: number;
631
+ } | {
632
+ phase: "committing";
633
+ } | {
634
+ phase: "embedding";
635
+ done: number;
636
+ total: number;
637
+ chunks: number;
638
+ } | {
639
+ phase: "finalizing";
640
+ };
641
+ interface SchemaIngestRequestOptions {
642
+ tenantId?: string;
643
+ userId?: string;
644
+ scopes?: string[];
645
+ }
646
+ interface StageSchemaIngestOptions extends SchemaSyncOptions {
647
+ /** Max docs per batch (1 per table + 1 per column). Default 1000. */
648
+ maxBatchDocs?: number;
649
+ /** Max serialized JSON bytes per batch. Default 2_000_000. */
650
+ maxBatchBytes?: number;
651
+ /** Throw SchemaTooLargeError (before uploading) above this many columns. */
652
+ maxColumns?: number;
653
+ onProgress?: (event: SchemaSyncProgressEvent) => void;
654
+ }
655
+ type SyncSchemaInBatchesOptions = StageSchemaIngestOptions;
656
+ interface StageSchemaIngestResult {
657
+ sessionId: string;
658
+ status: "skipped" | "embedding";
659
+ totalBatches: number;
660
+ tableCount: number;
661
+ columnCount: number;
662
+ /** Present when status is "skipped" (schema unchanged). */
663
+ skippedResult?: IngestResponse;
664
+ driftDetected?: boolean;
665
+ }
666
+ interface SchemaIngestBatchEmbedResponse {
667
+ index: number;
668
+ chunks: number;
669
+ chunks_with_annotations: number;
670
+ }
544
671
 
545
672
  /**
546
673
  * VizSpec types for flexible visualization specifications
@@ -1255,6 +1382,18 @@ declare class QueryPanelSdkAPI {
1255
1382
  tenantFieldType?: string;
1256
1383
  enforceTenantIsolation?: boolean;
1257
1384
  }): void;
1385
+ /**
1386
+ * Attach an Amazon Redshift database. Redshift speaks the Postgres wire
1387
+ * protocol, so `clientFn` can wrap a `pg` client; introspection uses
1388
+ * Redshift's svv_* catalog views and SQL is generated for Redshift.
1389
+ */
1390
+ attachRedshift(name: string, clientFn: PostgresClientFn, options?: Omit<PostgresAdapterOptions, "dialect"> & {
1391
+ description?: string;
1392
+ tags?: string[];
1393
+ tenantFieldName?: string;
1394
+ tenantFieldType?: string;
1395
+ enforceTenantIsolation?: boolean;
1396
+ }): void;
1258
1397
  attachBigQuery(name: string, clientFn: BigQueryClientFn, options: BigQueryAdapterOptions & {
1259
1398
  description?: string;
1260
1399
  tags?: string[];
@@ -1264,6 +1403,17 @@ declare class QueryPanelSdkAPI {
1264
1403
  }): void;
1265
1404
  attachDatabase(name: string, adapter: DatabaseAdapter): void;
1266
1405
  introspect(databaseName: string, tables?: string[]): Promise<SchemaIntrospection>;
1406
+ /**
1407
+ * Lists schemas (ClickHouse: the database, BigQuery: the dataset) with table
1408
+ * counts. Cheap catalog read for building an allowed-tables picker; not
1409
+ * restricted by `allowedTables`.
1410
+ */
1411
+ listSchemas(databaseName: string): Promise<CatalogSchema[]>;
1412
+ /**
1413
+ * Lists tables/views (no columns) filtered by schema and a case-insensitive
1414
+ * name substring. Default limit 500, max 5000. Not restricted by `allowedTables`.
1415
+ */
1416
+ listTables(databaseName: string, options?: ListTablesOptions): Promise<CatalogTable[]>;
1267
1417
  /**
1268
1418
  * Syncs the database schema to QueryPanel for natural language query generation.
1269
1419
  *
@@ -1289,6 +1439,31 @@ declare class QueryPanelSdkAPI {
1289
1439
  * ```
1290
1440
  */
1291
1441
  syncSchema(databaseName: string, options: SchemaSyncOptions, signal?: AbortSignal): Promise<IngestResponse>;
1442
+ /**
1443
+ * Introspects the schema, uploads it in batches to a new ingest session and
1444
+ * commits it. Returns `status: "skipped"` (with `skippedResult`) when the schema
1445
+ * is unchanged, otherwise `status: "embedding"`: call embedSchemaIngestBatch for
1446
+ * every index in [0, totalBatches) and then finalizeSchemaIngest.
1447
+ * Throws SchemaTooLargeError before uploading if `maxColumns` is exceeded.
1448
+ */
1449
+ stageSchemaIngest(databaseName: string, options: StageSchemaIngestOptions, signal?: AbortSignal): Promise<StageSchemaIngestResult>;
1450
+ /** Embeds one batch of a staged ingest session. */
1451
+ embedSchemaIngestBatch(sessionId: string, index: number, options: SchemaIngestRequestOptions, signal?: AbortSignal): Promise<SchemaIngestBatchEmbedResponse>;
1452
+ /** Finalizes a staged ingest session after all batches are embedded. */
1453
+ finalizeSchemaIngest(sessionId: string, options: SchemaIngestRequestOptions, signal?: AbortSignal): Promise<IngestResponse>;
1454
+ /**
1455
+ * Batched alternative to syncSchema for large databases: stage, embed every
1456
+ * batch, and finalize in-process, reporting progress via `onProgress`.
1457
+ *
1458
+ * @example
1459
+ * ```typescript
1460
+ * await qp.syncSchemaInBatches("warehouse", {
1461
+ * tenantId: "tenant_123",
1462
+ * onProgress: (e) => console.log(e.phase, e),
1463
+ * });
1464
+ * ```
1465
+ */
1466
+ syncSchemaInBatches(databaseName: string, options: SyncSchemaInBatchesOptions, signal?: AbortSignal): Promise<IngestResponse>;
1292
1467
  /**
1293
1468
  * Generates SQL from a natural language question and executes it.
1294
1469
  *
@@ -1993,4 +2168,4 @@ declare class QueryPanelSdkAPI {
1993
2168
  }, signal?: AbortSignal): Promise<SdkDashboard[]>;
1994
2169
  }
1995
2170
 
1996
- export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, type PipelineTrace, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
2171
+ export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type CatalogSchema, type CatalogTable, type CatalogTableType, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type ListTablesOptions, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, type PipelineTrace, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, type PostgresWireDialect, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIngestBatchEmbedResponse, type SchemaIngestRequestOptions, type SchemaIntrospection, type SchemaSyncOptions, type SchemaSyncProgressEvent, SchemaTooLargeError, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type StageSchemaIngestOptions, type StageSchemaIngestResult, type SyncSchemaInBatchesOptions, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
package/dist/index.d.ts CHANGED
@@ -37,7 +37,27 @@ interface IntrospectOptions {
37
37
  tables?: string[];
38
38
  }
39
39
 
40
- type DatabaseDialect = "bigquery" | "clickhouse" | "postgres" | "mysql";
40
+ type DatabaseDialect = "bigquery" | "clickhouse" | "postgres" | "redshift" | "mysql";
41
+ /** A schema (or ClickHouse database / BigQuery dataset) in the catalog. */
42
+ interface CatalogSchema {
43
+ schema: string;
44
+ tableCount: number;
45
+ }
46
+ type CatalogTableType = "table" | "view" | "materialized_view";
47
+ /** A table or view in the catalog (no columns; cheap to list). */
48
+ interface CatalogTable {
49
+ schema: string;
50
+ name: string;
51
+ type: CatalogTableType;
52
+ }
53
+ interface ListTablesOptions {
54
+ /** Only list tables in this schema. */
55
+ schema?: string;
56
+ /** Case-insensitive substring match on the table name. */
57
+ search?: string;
58
+ /** Max rows to return. Default 500, capped at 5000. */
59
+ limit?: number;
60
+ }
41
61
  interface DatabaseExecutionResult {
42
62
  fields: string[];
43
63
  rows: Array<Record<string, unknown>>;
@@ -68,6 +88,14 @@ interface DatabaseAdapter {
68
88
  * Get the database dialect/type
69
89
  */
70
90
  getDialect(): DatabaseDialect;
91
+ /**
92
+ * Optional: List schemas with table counts (cheap catalog read for pickers).
93
+ */
94
+ listSchemas?(): Promise<CatalogSchema[]>;
95
+ /**
96
+ * Optional: List tables/views without columns (cheap catalog read for pickers).
97
+ */
98
+ listTables?(options?: ListTablesOptions): Promise<CatalogTable[]>;
71
99
  /**
72
100
  * Optional: Close/cleanup database connection
73
101
  */
@@ -108,6 +136,7 @@ interface BigQueryAdapterOptions {
108
136
  kind?: SchemaIntrospection["db"]["kind"];
109
137
  /**
110
138
  * Optional allow-list of table names (dataset.table or bare table name).
139
+ * `*` or `<dataset>.*` allows every table in the dataset (same as no filter).
111
140
  * When specified, introspection and queries are restricted to these tables only.
112
141
  */
113
142
  allowedTables?: string[];
@@ -135,6 +164,14 @@ declare class BigQueryAdapter implements DatabaseAdapter {
135
164
  * Restricts to the default dataset (or allowedTables) and returns tables/columns only.
136
165
  */
137
166
  introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
167
+ /** The adapter is bound to one dataset, so this returns a single row. */
168
+ listSchemas(): Promise<CatalogSchema[]>;
169
+ /**
170
+ * List tables in the bound dataset. Reads the full catalog (not restricted
171
+ * by `allowedTables`). Default limit 500, max 5000.
172
+ */
173
+ listTables(options?: ListTablesOptions): Promise<CatalogTable[]>;
174
+ private informationSchema;
138
175
  private validateQueryTables;
139
176
  }
140
177
 
@@ -152,6 +189,7 @@ interface ClickHouseAdapterOptions {
152
189
  * Optional allow-list of table names.
153
190
  * When specified, introspection and queries are restricted to these tables only.
154
191
  * ClickHouse tables are not schema-qualified, so just provide table names.
192
+ * `*` or `<database>.*` allows every table (same as no filter).
155
193
  */
156
194
  allowedTables?: string[];
157
195
  }
@@ -179,6 +217,13 @@ declare class ClickHouseAdapter implements DatabaseAdapter {
179
217
  * No indexes, constraints, or statistics
180
218
  */
181
219
  introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
220
+ /** The adapter is bound to one database, so this returns a single row. */
221
+ listSchemas(): Promise<CatalogSchema[]>;
222
+ /**
223
+ * List tables in the bound database. Reads the full catalog (not restricted
224
+ * by `allowedTables`). Default limit 500, max 5000.
225
+ */
226
+ listTables(options?: ListTablesOptions): Promise<CatalogTable[]>;
182
227
  private validateQueryTables;
183
228
  close(): Promise<void>;
184
229
  private query;
@@ -192,16 +237,24 @@ interface PostgresQueryResult {
192
237
  }>;
193
238
  }
194
239
  type PostgresClientFn = (sql: string, params?: unknown[]) => Promise<PostgresQueryResult>;
240
+ type PostgresWireDialect = "postgres" | "redshift";
195
241
  interface PostgresAdapterOptions {
196
242
  /** Logical database name used in introspection metadata. */
197
243
  database?: string;
198
244
  /** Schema to assume when a table is provided without qualification. */
199
245
  defaultSchema?: string;
200
- /** Optional database kind label. Defaults to "postgres". */
246
+ /** Optional database kind label. Defaults to the dialect. */
201
247
  kind?: SchemaIntrospection["db"]["kind"];
248
+ /**
249
+ * Wire-compatible engine behind the client. "redshift" uses Redshift's
250
+ * svv_* catalog views for introspection. Defaults to "postgres".
251
+ */
252
+ dialect?: PostgresWireDialect;
202
253
  /**
203
254
  * Optional allow-list of table names (schema-qualified or bare).
204
- * When specified, introspection and queries are restricted to these tables only.
255
+ * Use `schema.*` to allow every table in a schema (a bare `*` means the
256
+ * default schema). When specified, introspection and queries are restricted
257
+ * to these tables only.
205
258
  */
206
259
  allowedTables?: string[];
207
260
  }
@@ -215,6 +268,7 @@ declare class PostgresAdapter implements DatabaseAdapter {
215
268
  private readonly databaseName;
216
269
  private readonly defaultSchema;
217
270
  private readonly kind;
271
+ private readonly dialect;
218
272
  private readonly allowedTables?;
219
273
  constructor(clientFn: PostgresClientFn, options?: PostgresAdapterOptions);
220
274
  execute(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<DatabaseExecutionResult>;
@@ -225,7 +279,18 @@ declare class PostgresAdapter implements DatabaseAdapter {
225
279
  */
226
280
  private convertNamedToPositionalParams;
227
281
  validate(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<void>;
228
- getDialect(): "postgres";
282
+ getDialect(): PostgresWireDialect;
283
+ /**
284
+ * List schemas with their table/view counts. Reads the full catalog (not
285
+ * restricted by `allowedTables`) so it can back an allowed-tables picker.
286
+ */
287
+ listSchemas(): Promise<CatalogSchema[]>;
288
+ /**
289
+ * List tables/views, optionally filtered by schema and a case-insensitive
290
+ * substring of the table name. Reads the full catalog (not restricted by
291
+ * `allowedTables`). Default limit 500, max 5000.
292
+ */
293
+ listTables(options?: ListTablesOptions): Promise<CatalogTable[]>;
229
294
  /**
230
295
  * Simplified introspection: only collect table/column metadata for IngestRequest
231
296
  * No indexes, constraints, or statistics
@@ -334,6 +399,17 @@ declare class QueryPipelineError extends Error {
334
399
  */
335
400
  isAiProviderError(): boolean;
336
401
  }
402
+ /**
403
+ * Thrown by stageSchemaIngest / syncSchemaInBatches when the introspected schema
404
+ * has more columns than `maxColumns`. Raised before anything is uploaded; narrow
405
+ * the sync with `allowedTables` / `tables` (e.g. `schema.*`) and retry.
406
+ */
407
+ declare class SchemaTooLargeError extends Error {
408
+ readonly tableCount: number;
409
+ readonly columnCount: number;
410
+ readonly maxColumns: number;
411
+ constructor(tableCount: number, columnCount: number, maxColumns: number);
412
+ }
337
413
 
338
414
  type ParamValue = string | number | boolean | string[] | number[];
339
415
  type ParamRecord = Record<string, ParamValue>;
@@ -541,6 +617,57 @@ interface SchemaSyncOptions {
541
617
  tables?: string[];
542
618
  forceReindex?: boolean;
543
619
  }
620
+ /** Progress events emitted by stageSchemaIngest / syncSchemaInBatches. */
621
+ type SchemaSyncProgressEvent = {
622
+ phase: "introspecting";
623
+ } | {
624
+ phase: "introspected";
625
+ tableCount: number;
626
+ columnCount: number;
627
+ } | {
628
+ phase: "uploading";
629
+ done: number;
630
+ total: number;
631
+ } | {
632
+ phase: "committing";
633
+ } | {
634
+ phase: "embedding";
635
+ done: number;
636
+ total: number;
637
+ chunks: number;
638
+ } | {
639
+ phase: "finalizing";
640
+ };
641
+ interface SchemaIngestRequestOptions {
642
+ tenantId?: string;
643
+ userId?: string;
644
+ scopes?: string[];
645
+ }
646
+ interface StageSchemaIngestOptions extends SchemaSyncOptions {
647
+ /** Max docs per batch (1 per table + 1 per column). Default 1000. */
648
+ maxBatchDocs?: number;
649
+ /** Max serialized JSON bytes per batch. Default 2_000_000. */
650
+ maxBatchBytes?: number;
651
+ /** Throw SchemaTooLargeError (before uploading) above this many columns. */
652
+ maxColumns?: number;
653
+ onProgress?: (event: SchemaSyncProgressEvent) => void;
654
+ }
655
+ type SyncSchemaInBatchesOptions = StageSchemaIngestOptions;
656
+ interface StageSchemaIngestResult {
657
+ sessionId: string;
658
+ status: "skipped" | "embedding";
659
+ totalBatches: number;
660
+ tableCount: number;
661
+ columnCount: number;
662
+ /** Present when status is "skipped" (schema unchanged). */
663
+ skippedResult?: IngestResponse;
664
+ driftDetected?: boolean;
665
+ }
666
+ interface SchemaIngestBatchEmbedResponse {
667
+ index: number;
668
+ chunks: number;
669
+ chunks_with_annotations: number;
670
+ }
544
671
 
545
672
  /**
546
673
  * VizSpec types for flexible visualization specifications
@@ -1255,6 +1382,18 @@ declare class QueryPanelSdkAPI {
1255
1382
  tenantFieldType?: string;
1256
1383
  enforceTenantIsolation?: boolean;
1257
1384
  }): void;
1385
+ /**
1386
+ * Attach an Amazon Redshift database. Redshift speaks the Postgres wire
1387
+ * protocol, so `clientFn` can wrap a `pg` client; introspection uses
1388
+ * Redshift's svv_* catalog views and SQL is generated for Redshift.
1389
+ */
1390
+ attachRedshift(name: string, clientFn: PostgresClientFn, options?: Omit<PostgresAdapterOptions, "dialect"> & {
1391
+ description?: string;
1392
+ tags?: string[];
1393
+ tenantFieldName?: string;
1394
+ tenantFieldType?: string;
1395
+ enforceTenantIsolation?: boolean;
1396
+ }): void;
1258
1397
  attachBigQuery(name: string, clientFn: BigQueryClientFn, options: BigQueryAdapterOptions & {
1259
1398
  description?: string;
1260
1399
  tags?: string[];
@@ -1264,6 +1403,17 @@ declare class QueryPanelSdkAPI {
1264
1403
  }): void;
1265
1404
  attachDatabase(name: string, adapter: DatabaseAdapter): void;
1266
1405
  introspect(databaseName: string, tables?: string[]): Promise<SchemaIntrospection>;
1406
+ /**
1407
+ * Lists schemas (ClickHouse: the database, BigQuery: the dataset) with table
1408
+ * counts. Cheap catalog read for building an allowed-tables picker; not
1409
+ * restricted by `allowedTables`.
1410
+ */
1411
+ listSchemas(databaseName: string): Promise<CatalogSchema[]>;
1412
+ /**
1413
+ * Lists tables/views (no columns) filtered by schema and a case-insensitive
1414
+ * name substring. Default limit 500, max 5000. Not restricted by `allowedTables`.
1415
+ */
1416
+ listTables(databaseName: string, options?: ListTablesOptions): Promise<CatalogTable[]>;
1267
1417
  /**
1268
1418
  * Syncs the database schema to QueryPanel for natural language query generation.
1269
1419
  *
@@ -1289,6 +1439,31 @@ declare class QueryPanelSdkAPI {
1289
1439
  * ```
1290
1440
  */
1291
1441
  syncSchema(databaseName: string, options: SchemaSyncOptions, signal?: AbortSignal): Promise<IngestResponse>;
1442
+ /**
1443
+ * Introspects the schema, uploads it in batches to a new ingest session and
1444
+ * commits it. Returns `status: "skipped"` (with `skippedResult`) when the schema
1445
+ * is unchanged, otherwise `status: "embedding"`: call embedSchemaIngestBatch for
1446
+ * every index in [0, totalBatches) and then finalizeSchemaIngest.
1447
+ * Throws SchemaTooLargeError before uploading if `maxColumns` is exceeded.
1448
+ */
1449
+ stageSchemaIngest(databaseName: string, options: StageSchemaIngestOptions, signal?: AbortSignal): Promise<StageSchemaIngestResult>;
1450
+ /** Embeds one batch of a staged ingest session. */
1451
+ embedSchemaIngestBatch(sessionId: string, index: number, options: SchemaIngestRequestOptions, signal?: AbortSignal): Promise<SchemaIngestBatchEmbedResponse>;
1452
+ /** Finalizes a staged ingest session after all batches are embedded. */
1453
+ finalizeSchemaIngest(sessionId: string, options: SchemaIngestRequestOptions, signal?: AbortSignal): Promise<IngestResponse>;
1454
+ /**
1455
+ * Batched alternative to syncSchema for large databases: stage, embed every
1456
+ * batch, and finalize in-process, reporting progress via `onProgress`.
1457
+ *
1458
+ * @example
1459
+ * ```typescript
1460
+ * await qp.syncSchemaInBatches("warehouse", {
1461
+ * tenantId: "tenant_123",
1462
+ * onProgress: (e) => console.log(e.phase, e),
1463
+ * });
1464
+ * ```
1465
+ */
1466
+ syncSchemaInBatches(databaseName: string, options: SyncSchemaInBatchesOptions, signal?: AbortSignal): Promise<IngestResponse>;
1292
1467
  /**
1293
1468
  * Generates SQL from a natural language question and executes it.
1294
1469
  *
@@ -1993,4 +2168,4 @@ declare class QueryPanelSdkAPI {
1993
2168
  }, signal?: AbortSignal): Promise<SdkDashboard[]>;
1994
2169
  }
1995
2170
 
1996
- export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, type PipelineTrace, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
2171
+ export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type CatalogSchema, type CatalogTable, type CatalogTableType, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type ListTablesOptions, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, type PipelineTrace, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, type PostgresWireDialect, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIngestBatchEmbedResponse, type SchemaIngestRequestOptions, type SchemaIntrospection, type SchemaSyncOptions, type SchemaSyncProgressEvent, SchemaTooLargeError, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type StageSchemaIngestOptions, type StageSchemaIngestResult, type SyncSchemaInBatchesOptions, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };