@querypanel/node-sdk 1.2.5 → 1.2.7
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/README.md +39 -0
- package/dist/index.cjs +90 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +90 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -201,6 +201,45 @@ if (response.chart.vegaLiteSpec) {
|
|
|
201
201
|
const charts = await qp.listCharts({ tenantId: "tenant_123" });
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
### Saved charts via `/charts/all`
|
|
205
|
+
|
|
206
|
+
`listAllCharts()` calls **`GET /charts/all`**. It accepts the **same options as `listCharts()`** (including **`pagination`** with `page` and `limit`, filters, and sort).
|
|
207
|
+
|
|
208
|
+
**Breaking change:** Older SDK versions returned a **plain array** of charts from `listAllCharts()`. Current versions return **`{ data, pagination }`**, the same **`PaginatedResponse`** shape as **`listCharts()`**. Update callers from `const charts = await qp.listAllCharts(...)` to **`const { data: charts, pagination } = await qp.listAllCharts(...)`** (or use **`result.data`** only).
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
const { data, pagination } = await qp.listAllCharts({
|
|
212
|
+
tenantId: "tenant_123",
|
|
213
|
+
pagination: { page: 1, limit: 50 },
|
|
214
|
+
includeData: true,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Walk every page (same pattern as listCharts)
|
|
218
|
+
let page = 1;
|
|
219
|
+
const limit = 50;
|
|
220
|
+
let allCharts: typeof data = [];
|
|
221
|
+
for (;;) {
|
|
222
|
+
const res = await qp.listAllCharts({
|
|
223
|
+
tenantId: "tenant_123",
|
|
224
|
+
pagination: { page, limit },
|
|
225
|
+
});
|
|
226
|
+
allCharts = allCharts.concat(res.data);
|
|
227
|
+
if (!res.pagination.hasNext) break;
|
|
228
|
+
page += 1;
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Bulk fetch saved charts by ID
|
|
233
|
+
|
|
234
|
+
To load specific saved charts by their **chart UUIDs** (from `createChart` or list responses), use `getChartsByIds()`. It calls **`GET /charts/bulk`** with `ids` as repeated or comma-separated query params. The API returns **`{ data, missingIds }`**. Up to **100** UUIDs per request.
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
const { data, missingIds } = await qp.getChartsByIds(
|
|
238
|
+
["550e8400-e29b-41d4-a716-446655440000"],
|
|
239
|
+
{ tenantId: "tenant_123", includeData: true },
|
|
240
|
+
);
|
|
241
|
+
```
|
|
242
|
+
|
|
204
243
|
Saved charts now include the original `prompt` so you can show the question
|
|
205
244
|
alongside chart history or reuse it in follow-up workflows.
|
|
206
245
|
|
package/dist/index.cjs
CHANGED
|
@@ -382,10 +382,15 @@ var ClickHouseAdapter = class {
|
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
384
|
const allowedSet = new Set(this.allowedTables);
|
|
385
|
-
const tablePattern =
|
|
385
|
+
const tablePattern = /\b(FROM|JOIN)\s+(?:FINAL\s+)?(?:(?:[a-zA-Z_][a-zA-Z0-9_]*)\.)?(["'`]?[a-zA-Z_][a-zA-Z0-9_]*["'`]?)/gi;
|
|
386
386
|
const matches = sql.matchAll(tablePattern);
|
|
387
387
|
for (const match of matches) {
|
|
388
|
-
const
|
|
388
|
+
const clause = match[1]?.toUpperCase();
|
|
389
|
+
const matchIndex = match.index ?? -1;
|
|
390
|
+
if (clause === "JOIN" && matchIndex >= 0 && isArrayJoinClause(sql, matchIndex)) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const table = match[2]?.replace(/["'`]/g, "");
|
|
389
394
|
if (table) {
|
|
390
395
|
if (!allowedSet.has(table)) {
|
|
391
396
|
throw new Error(
|
|
@@ -453,6 +458,11 @@ function normalizeTableFilter2(tables) {
|
|
|
453
458
|
}
|
|
454
459
|
return normalized;
|
|
455
460
|
}
|
|
461
|
+
function isArrayJoinClause(sql, joinIndex) {
|
|
462
|
+
const beforeJoin = sql.slice(0, joinIndex);
|
|
463
|
+
const previousToken = beforeJoin.trim().split(/\s+/).pop()?.toUpperCase();
|
|
464
|
+
return previousToken === "ARRAY";
|
|
465
|
+
}
|
|
456
466
|
function transformColumnRow(row) {
|
|
457
467
|
const unwrappedType = unwrapTypeModifiers(row.type);
|
|
458
468
|
const column = {
|
|
@@ -1305,6 +1315,61 @@ async function listCharts(client, queryEngine, options, signal) {
|
|
|
1305
1315
|
}
|
|
1306
1316
|
return response;
|
|
1307
1317
|
}
|
|
1318
|
+
async function listAllCharts(client, queryEngine, options, signal) {
|
|
1319
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
1320
|
+
const params = new URLSearchParams();
|
|
1321
|
+
if (options?.pagination?.page)
|
|
1322
|
+
params.set("page", `${options.pagination.page}`);
|
|
1323
|
+
if (options?.pagination?.limit)
|
|
1324
|
+
params.set("limit", `${options.pagination.limit}`);
|
|
1325
|
+
if (options?.sortBy) params.set("sort_by", options.sortBy);
|
|
1326
|
+
if (options?.sortDir) params.set("sort_dir", options.sortDir);
|
|
1327
|
+
if (options?.title) params.set("title", options.title);
|
|
1328
|
+
if (options?.userFilter) params.set("user_id", options.userFilter);
|
|
1329
|
+
if (options?.createdFrom) params.set("created_from", options.createdFrom);
|
|
1330
|
+
if (options?.createdTo) params.set("created_to", options.createdTo);
|
|
1331
|
+
if (options?.updatedFrom) params.set("updated_from", options.updatedFrom);
|
|
1332
|
+
if (options?.updatedTo) params.set("updated_to", options.updatedTo);
|
|
1333
|
+
const response = await client.get(
|
|
1334
|
+
`/charts/all${params.toString() ? `?${params.toString()}` : ""}`,
|
|
1335
|
+
tenantId,
|
|
1336
|
+
options?.userId,
|
|
1337
|
+
options?.scopes,
|
|
1338
|
+
signal
|
|
1339
|
+
);
|
|
1340
|
+
if (options?.includeData) {
|
|
1341
|
+
response.data = await Promise.all(
|
|
1342
|
+
response.data.map(async (chart) => {
|
|
1343
|
+
const rows = await executeChartQuery(queryEngine, chart, tenantId);
|
|
1344
|
+
return hydrateChartWithData(chart, rows);
|
|
1345
|
+
})
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
return response;
|
|
1349
|
+
}
|
|
1350
|
+
async function getChartsByIds(client, queryEngine, ids, options, signal) {
|
|
1351
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
1352
|
+
const params = new URLSearchParams();
|
|
1353
|
+
for (const id of ids) {
|
|
1354
|
+
params.append("ids", id);
|
|
1355
|
+
}
|
|
1356
|
+
const response = await client.get(
|
|
1357
|
+
`/charts/bulk${params.toString() ? `?${params.toString()}` : ""}`,
|
|
1358
|
+
tenantId,
|
|
1359
|
+
options?.userId,
|
|
1360
|
+
options?.scopes,
|
|
1361
|
+
signal
|
|
1362
|
+
);
|
|
1363
|
+
if (options?.includeData) {
|
|
1364
|
+
response.data = await Promise.all(
|
|
1365
|
+
response.data.map(async (chart) => {
|
|
1366
|
+
const rows = await executeChartQuery(queryEngine, chart, tenantId);
|
|
1367
|
+
return hydrateChartWithData(chart, rows);
|
|
1368
|
+
})
|
|
1369
|
+
);
|
|
1370
|
+
}
|
|
1371
|
+
return response;
|
|
1372
|
+
}
|
|
1308
1373
|
async function getChart(client, queryEngine, id, options, signal) {
|
|
1309
1374
|
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
1310
1375
|
const chart = await client.get(
|
|
@@ -2772,6 +2837,29 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
|
|
|
2772
2837
|
signal
|
|
2773
2838
|
);
|
|
2774
2839
|
}
|
|
2840
|
+
/**
|
|
2841
|
+
* Lists saved charts via `GET /charts/all` (same query, filters, and pagination as {@link listCharts}).
|
|
2842
|
+
*/
|
|
2843
|
+
async listAllCharts(options, signal) {
|
|
2844
|
+
return await listAllCharts(
|
|
2845
|
+
this.client,
|
|
2846
|
+
this.queryEngine,
|
|
2847
|
+
options,
|
|
2848
|
+
signal
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Bulk gets saved charts by chart IDs (`GET /charts/bulk` with `ids` query params).
|
|
2853
|
+
*/
|
|
2854
|
+
async getChartsByIds(ids, options, signal) {
|
|
2855
|
+
return await getChartsByIds(
|
|
2856
|
+
this.client,
|
|
2857
|
+
this.queryEngine,
|
|
2858
|
+
ids,
|
|
2859
|
+
options,
|
|
2860
|
+
signal
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2775
2863
|
// Session history CRUD operations
|
|
2776
2864
|
/**
|
|
2777
2865
|
* Lists query sessions with pagination and filtering.
|