@querypanel/node-sdk 1.0.53 → 1.0.54
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.cjs +6 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +6 -84
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -1465,17 +1464,11 @@ function buildModifiedQuestion(originalQuestion, modifications, pipeline) {
|
|
|
1465
1464
|
const from = normalizeDateInput(modifications.dateRange.from);
|
|
1466
1465
|
const to = normalizeDateInput(modifications.dateRange.to);
|
|
1467
1466
|
if (from && to) {
|
|
1468
|
-
hints.push(
|
|
1469
|
-
`replace any existing date filters with exact date range from ${from} to ${to} (inclusive, do not add extra days)`
|
|
1470
|
-
);
|
|
1467
|
+
hints.push(`change date range to ${from} through ${to}`);
|
|
1471
1468
|
} else if (from) {
|
|
1472
|
-
hints.push(
|
|
1473
|
-
`replace any existing date filters with exact start date ${from} (do not shift this date)`
|
|
1474
|
-
);
|
|
1469
|
+
hints.push(`change start date to ${from}`);
|
|
1475
1470
|
} else if (to) {
|
|
1476
|
-
hints.push(
|
|
1477
|
-
`replace any existing date filters with exact end date ${to} (inclusive, do not add extra days)`
|
|
1478
|
-
);
|
|
1471
|
+
hints.push(`change end date to ${to}`);
|
|
1479
1472
|
}
|
|
1480
1473
|
} else {
|
|
1481
1474
|
const parts = [];
|
|
@@ -1591,9 +1584,6 @@ function stripVizSpecOnlyHints(hints) {
|
|
|
1591
1584
|
const { kind: _kind, ...rest } = hints;
|
|
1592
1585
|
return rest;
|
|
1593
1586
|
}
|
|
1594
|
-
function isDateRangeOnly(mods) {
|
|
1595
|
-
return !!mods.dateRange && !mods.timeGranularity && !mods.additionalInstructions && !mods.customSql;
|
|
1596
|
-
}
|
|
1597
1587
|
function resolveTenantId5(client, tenantId) {
|
|
1598
1588
|
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
1599
1589
|
if (!resolved) {
|
|
@@ -1606,6 +1596,7 @@ function resolveTenantId5(client, tenantId) {
|
|
|
1606
1596
|
async function modifyChart(client, queryEngine, input, options, signal) {
|
|
1607
1597
|
const tenantId = resolveTenantId5(client, options?.tenantId);
|
|
1608
1598
|
const sessionId = import_node_crypto4.default.randomUUID();
|
|
1599
|
+
const querypanelSessionId = options?.querypanelSessionId ?? sessionId;
|
|
1609
1600
|
const chartType = options?.chartType ?? "vega-lite";
|
|
1610
1601
|
const hasSqlMods = !!input.sqlModifications;
|
|
1611
1602
|
const hasVizMods = !!input.vizModifications;
|
|
@@ -1638,78 +1629,6 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
1638
1629
|
finalParams = {};
|
|
1639
1630
|
paramMetadata = [];
|
|
1640
1631
|
sqlChanged = true;
|
|
1641
|
-
} else if (hasSqlMods && options?.pipeline === "v2" && isDateRangeOnly(input.sqlModifications)) {
|
|
1642
|
-
let usedFastPath = false;
|
|
1643
|
-
try {
|
|
1644
|
-
const rewriteResponse = await client.post(
|
|
1645
|
-
"/v2/rewrite-datefilter",
|
|
1646
|
-
{
|
|
1647
|
-
previous_sql: input.sql,
|
|
1648
|
-
previous_params: input.params ? Object.entries(input.params).map(([name, value]) => ({
|
|
1649
|
-
name,
|
|
1650
|
-
value
|
|
1651
|
-
})) : [],
|
|
1652
|
-
date_range: input.sqlModifications.dateRange,
|
|
1653
|
-
question: input.question,
|
|
1654
|
-
...tenantSettings ? { tenant_settings: tenantSettings } : {},
|
|
1655
|
-
...databaseName ? { database: databaseName } : {},
|
|
1656
|
-
...metadata?.dialect ? { dialect: metadata.dialect } : {}
|
|
1657
|
-
},
|
|
1658
|
-
tenantId,
|
|
1659
|
-
options?.userId,
|
|
1660
|
-
options?.scopes,
|
|
1661
|
-
signal,
|
|
1662
|
-
sessionId
|
|
1663
|
-
);
|
|
1664
|
-
finalSql = rewriteResponse.sql;
|
|
1665
|
-
paramMetadata = Array.isArray(rewriteResponse.params) ? rewriteResponse.params : [];
|
|
1666
|
-
finalParams = queryEngine.mapGeneratedParams(paramMetadata);
|
|
1667
|
-
applyDateRangeOverrides(
|
|
1668
|
-
input.sqlModifications?.dateRange,
|
|
1669
|
-
finalParams,
|
|
1670
|
-
paramMetadata
|
|
1671
|
-
);
|
|
1672
|
-
rationale = rewriteResponse.rationale;
|
|
1673
|
-
queryId = rewriteResponse.queryId;
|
|
1674
|
-
sqlChanged = finalSql !== input.sql;
|
|
1675
|
-
usedFastPath = true;
|
|
1676
|
-
} catch {
|
|
1677
|
-
}
|
|
1678
|
-
if (!usedFastPath) {
|
|
1679
|
-
const modifiedQuestion = buildModifiedQuestion(
|
|
1680
|
-
input.question,
|
|
1681
|
-
input.sqlModifications,
|
|
1682
|
-
"v2"
|
|
1683
|
-
);
|
|
1684
|
-
finalQuestion = modifiedQuestion;
|
|
1685
|
-
const queryResponse = await client.post(
|
|
1686
|
-
queryEndpoint,
|
|
1687
|
-
{
|
|
1688
|
-
question: modifiedQuestion,
|
|
1689
|
-
previous_sql: input.sql,
|
|
1690
|
-
...options?.maxRetry ? { max_retry: options.maxRetry } : {},
|
|
1691
|
-
...tenantSettings ? { tenant_settings: tenantSettings } : {},
|
|
1692
|
-
...databaseName ? { database: databaseName } : {},
|
|
1693
|
-
...metadata?.dialect ? { dialect: metadata.dialect } : {}
|
|
1694
|
-
},
|
|
1695
|
-
tenantId,
|
|
1696
|
-
options?.userId,
|
|
1697
|
-
options?.scopes,
|
|
1698
|
-
signal,
|
|
1699
|
-
sessionId
|
|
1700
|
-
);
|
|
1701
|
-
finalSql = queryResponse.sql;
|
|
1702
|
-
paramMetadata = Array.isArray(queryResponse.params) ? queryResponse.params : [];
|
|
1703
|
-
finalParams = queryEngine.mapGeneratedParams(paramMetadata);
|
|
1704
|
-
applyDateRangeOverrides(
|
|
1705
|
-
input.sqlModifications?.dateRange,
|
|
1706
|
-
finalParams,
|
|
1707
|
-
paramMetadata
|
|
1708
|
-
);
|
|
1709
|
-
rationale = queryResponse.rationale;
|
|
1710
|
-
queryId = queryResponse.queryId;
|
|
1711
|
-
sqlChanged = finalSql !== input.sql;
|
|
1712
|
-
}
|
|
1713
1632
|
} else if (hasSqlMods && !hasCustomSql) {
|
|
1714
1633
|
const modifiedQuestion = buildModifiedQuestion(
|
|
1715
1634
|
input.question,
|
|
@@ -1723,6 +1642,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
1723
1642
|
queryEndpoint,
|
|
1724
1643
|
{
|
|
1725
1644
|
question: modifiedQuestion,
|
|
1645
|
+
session_id: querypanelSessionId,
|
|
1726
1646
|
previous_sql: input.sql,
|
|
1727
1647
|
...options?.maxRetry ? { max_retry: options.maxRetry } : {},
|
|
1728
1648
|
...tenantSettings ? { tenant_settings: tenantSettings } : {},
|
|
@@ -1825,6 +1745,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
1825
1745
|
rationale,
|
|
1826
1746
|
dialect: metadata?.dialect ?? "unknown",
|
|
1827
1747
|
queryId,
|
|
1748
|
+
querypanelSessionId,
|
|
1828
1749
|
rows,
|
|
1829
1750
|
fields: execution.fields,
|
|
1830
1751
|
chart,
|