@querypanel/node-sdk 1.2.10 → 1.3.0-beta.0
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 +132 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +129 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -220,11 +220,8 @@ declare class PostgresAdapter implements DatabaseAdapter {
|
|
|
220
220
|
execute(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<DatabaseExecutionResult>;
|
|
221
221
|
private validateQueryTables;
|
|
222
222
|
/**
|
|
223
|
-
* Convert params to positional array for PostgreSQL.
|
|
224
|
-
*
|
|
225
|
-
* When the record has numeric keys ("1", "2", "3") — e.g. from mapGeneratedParams —
|
|
226
|
-
* use only those in order so placeholder order matches SQL. Otherwise fall back to
|
|
227
|
-
* named keys in alphabetical order for backward compatibility.
|
|
223
|
+
* Convert params to positional array for PostgreSQL ($1, $2, …).
|
|
224
|
+
* Values must align with v2 generation order via numeric keys from mapGeneratedParams.
|
|
228
225
|
*/
|
|
229
226
|
private convertNamedToPositionalParams;
|
|
230
227
|
validate(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<void>;
|
|
@@ -733,7 +730,7 @@ interface AskOptions {
|
|
|
733
730
|
*/
|
|
734
731
|
pipeline?: "v1" | "v2";
|
|
735
732
|
/**
|
|
736
|
-
* Optional
|
|
733
|
+
* Optional model id for v2 SQL generation (e.g. OpenAI or `gemini-*` when the API uses Gemini). Omit for server default.
|
|
737
734
|
*/
|
|
738
735
|
model?: string;
|
|
739
736
|
/**
|
|
@@ -1138,6 +1135,16 @@ declare class CallbackApiClient implements IQueryPanelApi {
|
|
|
1138
1135
|
delete<T = void>(path: string, tenantId: string, userId?: string, scopes?: string[], signal?: AbortSignal, sessionId?: string): Promise<T>;
|
|
1139
1136
|
}
|
|
1140
1137
|
|
|
1138
|
+
/**
|
|
1139
|
+
* Maps v2-style param metadata (array order = $1, $2, $3 in SQL) to a ParamRecord.
|
|
1140
|
+
* Numeric keys preserve placeholder order for PostgreSQL; named keys support tenant lookups.
|
|
1141
|
+
*/
|
|
1142
|
+
declare function mapGeneratedParams(params: Array<Record<string, unknown>>): ParamRecord;
|
|
1143
|
+
/**
|
|
1144
|
+
* Normalizes run-sql / dashboard request params into a ParamRecord.
|
|
1145
|
+
*/
|
|
1146
|
+
declare function normalizeSqlParamsInput(params: unknown[] | Record<string, unknown> | null | undefined): ParamRecord;
|
|
1147
|
+
|
|
1141
1148
|
/** Options when constructing the SDK with HTTP (default) or with a custom API implementation. */
|
|
1142
1149
|
interface QueryPanelSdkAPIOptions {
|
|
1143
1150
|
defaultTenantId?: string;
|
|
@@ -1950,4 +1957,4 @@ declare class QueryPanelSdkAPI {
|
|
|
1950
1957
|
}, signal?: AbortSignal): Promise<SdkDashboard[]>;
|
|
1951
1958
|
}
|
|
1952
1959
|
|
|
1953
|
-
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 };
|
|
1960
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -220,11 +220,8 @@ declare class PostgresAdapter implements DatabaseAdapter {
|
|
|
220
220
|
execute(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<DatabaseExecutionResult>;
|
|
221
221
|
private validateQueryTables;
|
|
222
222
|
/**
|
|
223
|
-
* Convert params to positional array for PostgreSQL.
|
|
224
|
-
*
|
|
225
|
-
* When the record has numeric keys ("1", "2", "3") — e.g. from mapGeneratedParams —
|
|
226
|
-
* use only those in order so placeholder order matches SQL. Otherwise fall back to
|
|
227
|
-
* named keys in alphabetical order for backward compatibility.
|
|
223
|
+
* Convert params to positional array for PostgreSQL ($1, $2, …).
|
|
224
|
+
* Values must align with v2 generation order via numeric keys from mapGeneratedParams.
|
|
228
225
|
*/
|
|
229
226
|
private convertNamedToPositionalParams;
|
|
230
227
|
validate(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<void>;
|
|
@@ -733,7 +730,7 @@ interface AskOptions {
|
|
|
733
730
|
*/
|
|
734
731
|
pipeline?: "v1" | "v2";
|
|
735
732
|
/**
|
|
736
|
-
* Optional
|
|
733
|
+
* Optional model id for v2 SQL generation (e.g. OpenAI or `gemini-*` when the API uses Gemini). Omit for server default.
|
|
737
734
|
*/
|
|
738
735
|
model?: string;
|
|
739
736
|
/**
|
|
@@ -1138,6 +1135,16 @@ declare class CallbackApiClient implements IQueryPanelApi {
|
|
|
1138
1135
|
delete<T = void>(path: string, tenantId: string, userId?: string, scopes?: string[], signal?: AbortSignal, sessionId?: string): Promise<T>;
|
|
1139
1136
|
}
|
|
1140
1137
|
|
|
1138
|
+
/**
|
|
1139
|
+
* Maps v2-style param metadata (array order = $1, $2, $3 in SQL) to a ParamRecord.
|
|
1140
|
+
* Numeric keys preserve placeholder order for PostgreSQL; named keys support tenant lookups.
|
|
1141
|
+
*/
|
|
1142
|
+
declare function mapGeneratedParams(params: Array<Record<string, unknown>>): ParamRecord;
|
|
1143
|
+
/**
|
|
1144
|
+
* Normalizes run-sql / dashboard request params into a ParamRecord.
|
|
1145
|
+
*/
|
|
1146
|
+
declare function normalizeSqlParamsInput(params: unknown[] | Record<string, unknown> | null | undefined): ParamRecord;
|
|
1147
|
+
|
|
1141
1148
|
/** Options when constructing the SDK with HTTP (default) or with a custom API implementation. */
|
|
1142
1149
|
interface QueryPanelSdkAPIOptions {
|
|
1143
1150
|
defaultTenantId?: string;
|
|
@@ -1950,4 +1957,4 @@ declare class QueryPanelSdkAPI {
|
|
|
1950
1957
|
}, signal?: AbortSignal): Promise<SdkDashboard[]>;
|
|
1951
1958
|
}
|
|
1952
1959
|
|
|
1953
|
-
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 };
|
|
1960
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -453,6 +453,37 @@ function toNumber(value) {
|
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
// src/adapters/postgres.ts
|
|
456
|
+
function maxPostgresPlaceholderIndex(sql) {
|
|
457
|
+
let max = 0;
|
|
458
|
+
for (const match of sql.matchAll(/\$(\d+)\b/g)) {
|
|
459
|
+
const index = Number.parseInt(match[1], 10);
|
|
460
|
+
if (Number.isFinite(index) && index > max) {
|
|
461
|
+
max = index;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return max;
|
|
465
|
+
}
|
|
466
|
+
function filterParamsForPostgresSql(sql, params) {
|
|
467
|
+
if (!params || Object.keys(params).length === 0) {
|
|
468
|
+
return void 0;
|
|
469
|
+
}
|
|
470
|
+
const placeholderCount = maxPostgresPlaceholderIndex(sql);
|
|
471
|
+
if (placeholderCount === 0) {
|
|
472
|
+
return void 0;
|
|
473
|
+
}
|
|
474
|
+
const hasNumericKeys = Object.keys(params).some((key) => /^\d+$/.test(key));
|
|
475
|
+
if (hasNumericKeys) {
|
|
476
|
+
const filtered = {};
|
|
477
|
+
for (let index = 1; index <= placeholderCount; index += 1) {
|
|
478
|
+
const key = String(index);
|
|
479
|
+
if (key in params) {
|
|
480
|
+
filtered[key] = params[key];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return Object.keys(filtered).length > 0 ? filtered : void 0;
|
|
484
|
+
}
|
|
485
|
+
return params;
|
|
486
|
+
}
|
|
456
487
|
var PostgresAdapter = class {
|
|
457
488
|
constructor(clientFn, options = {}) {
|
|
458
489
|
this.clientFn = clientFn;
|
|
@@ -470,9 +501,10 @@ var PostgresAdapter = class {
|
|
|
470
501
|
if (this.allowedTables) {
|
|
471
502
|
this.validateQueryTables(sql);
|
|
472
503
|
}
|
|
504
|
+
const boundParams = filterParamsForPostgresSql(sql, params);
|
|
473
505
|
let paramArray;
|
|
474
|
-
if (
|
|
475
|
-
paramArray = this.convertNamedToPositionalParams(
|
|
506
|
+
if (boundParams) {
|
|
507
|
+
paramArray = this.convertNamedToPositionalParams(sql, boundParams);
|
|
476
508
|
}
|
|
477
509
|
const result = await this.clientFn(sql, paramArray);
|
|
478
510
|
const fields = result.fields.map((f) => f.name);
|
|
@@ -502,36 +534,43 @@ var PostgresAdapter = class {
|
|
|
502
534
|
}
|
|
503
535
|
}
|
|
504
536
|
/**
|
|
505
|
-
* Convert params to positional array for PostgreSQL.
|
|
506
|
-
*
|
|
507
|
-
* When the record has numeric keys ("1", "2", "3") — e.g. from mapGeneratedParams —
|
|
508
|
-
* use only those in order so placeholder order matches SQL. Otherwise fall back to
|
|
509
|
-
* named keys in alphabetical order for backward compatibility.
|
|
537
|
+
* Convert params to positional array for PostgreSQL ($1, $2, …).
|
|
538
|
+
* Values must align with v2 generation order via numeric keys from mapGeneratedParams.
|
|
510
539
|
*/
|
|
511
|
-
convertNamedToPositionalParams(params) {
|
|
512
|
-
const
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
540
|
+
convertNamedToPositionalParams(sql, params) {
|
|
541
|
+
const placeholderCount = maxPostgresPlaceholderIndex(sql);
|
|
542
|
+
if (placeholderCount === 0) {
|
|
543
|
+
return [];
|
|
544
|
+
}
|
|
545
|
+
const positionalParams = [];
|
|
546
|
+
for (let index = 1; index <= placeholderCount; index += 1) {
|
|
547
|
+
const key = String(index);
|
|
548
|
+
let val = params[key];
|
|
549
|
+
if (val === void 0 && placeholderCount === 1) {
|
|
550
|
+
const namedKeys = Object.keys(params).filter((k) => !/^\d+$/.test(k));
|
|
551
|
+
if (namedKeys.length === 1) {
|
|
552
|
+
val = params[namedKeys[0]];
|
|
523
553
|
}
|
|
524
|
-
positionalParams.push(val);
|
|
525
554
|
}
|
|
526
|
-
|
|
555
|
+
if (val === void 0) {
|
|
556
|
+
throw new Error(`Missing value for PostgreSQL parameter $${index}`);
|
|
557
|
+
}
|
|
558
|
+
if (typeof val === "string") {
|
|
559
|
+
const match = val.match(/^<([a-zA-Z0-9_]+)>$/);
|
|
560
|
+
const namedKey = match?.[1];
|
|
561
|
+
if (namedKey && namedKey in params) {
|
|
562
|
+
val = params[namedKey];
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
positionalParams.push(val);
|
|
527
566
|
}
|
|
528
|
-
|
|
529
|
-
return namedKeys.map((key) => params[key]);
|
|
567
|
+
return positionalParams;
|
|
530
568
|
}
|
|
531
569
|
async validate(sql, params) {
|
|
570
|
+
const boundParams = filterParamsForPostgresSql(sql, params);
|
|
532
571
|
let paramArray;
|
|
533
|
-
if (
|
|
534
|
-
paramArray = this.convertNamedToPositionalParams(
|
|
572
|
+
if (boundParams) {
|
|
573
|
+
paramArray = this.convertNamedToPositionalParams(sql, boundParams);
|
|
535
574
|
}
|
|
536
575
|
await this.clientFn(`EXPLAIN ${sql}`, paramArray);
|
|
537
576
|
}
|
|
@@ -1174,6 +1213,45 @@ var CallbackApiClient = class {
|
|
|
1174
1213
|
}
|
|
1175
1214
|
};
|
|
1176
1215
|
|
|
1216
|
+
// src/core/map-generated-params.ts
|
|
1217
|
+
function mapGeneratedParams(params) {
|
|
1218
|
+
const record = {};
|
|
1219
|
+
params.forEach((param, index) => {
|
|
1220
|
+
const value = param.value;
|
|
1221
|
+
if (value === void 0) {
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
record[String(index + 1)] = value;
|
|
1225
|
+
const nameCandidate = typeof param.name === "string" && param.name.trim() || typeof param.placeholder === "string" && param.placeholder.trim() || typeof param.position === "number" && String(param.position) || String(index + 1);
|
|
1226
|
+
const key = nameCandidate.replace(/[{}:$]/g, "").trim();
|
|
1227
|
+
record[key] = value;
|
|
1228
|
+
});
|
|
1229
|
+
return record;
|
|
1230
|
+
}
|
|
1231
|
+
function normalizeSqlParamsInput(params) {
|
|
1232
|
+
if (params == null) {
|
|
1233
|
+
return {};
|
|
1234
|
+
}
|
|
1235
|
+
if (Array.isArray(params)) {
|
|
1236
|
+
if (params.length === 0) {
|
|
1237
|
+
return {};
|
|
1238
|
+
}
|
|
1239
|
+
const first = params[0];
|
|
1240
|
+
if (first && typeof first === "object" && "value" in first) {
|
|
1241
|
+
return mapGeneratedParams(params);
|
|
1242
|
+
}
|
|
1243
|
+
const positional = {};
|
|
1244
|
+
params.forEach((value, index) => {
|
|
1245
|
+
positional[String(index + 1)] = value;
|
|
1246
|
+
});
|
|
1247
|
+
return positional;
|
|
1248
|
+
}
|
|
1249
|
+
if (typeof params === "object") {
|
|
1250
|
+
return params;
|
|
1251
|
+
}
|
|
1252
|
+
return {};
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1177
1255
|
// src/core/query-engine.ts
|
|
1178
1256
|
var QueryEngine = class {
|
|
1179
1257
|
constructor() {
|
|
@@ -1244,18 +1322,7 @@ var QueryEngine = class {
|
|
|
1244
1322
|
* - Named keys remain for tenant isolation / other lookups.
|
|
1245
1323
|
*/
|
|
1246
1324
|
mapGeneratedParams(params) {
|
|
1247
|
-
|
|
1248
|
-
params.forEach((param, index) => {
|
|
1249
|
-
const value = param.value;
|
|
1250
|
-
if (value === void 0) {
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
record[String(index + 1)] = value;
|
|
1254
|
-
const nameCandidate = typeof param.name === "string" && param.name.trim() || typeof param.placeholder === "string" && param.placeholder.trim() || typeof param.position === "number" && String(param.position) || String(index + 1);
|
|
1255
|
-
const key = nameCandidate.replace(/[{}:$]/g, "").trim();
|
|
1256
|
-
record[key] = value;
|
|
1257
|
-
});
|
|
1258
|
-
return record;
|
|
1325
|
+
return mapGeneratedParams(params);
|
|
1259
1326
|
}
|
|
1260
1327
|
ensureTenantIsolation(sql, params, metadata, tenantId) {
|
|
1261
1328
|
if (!metadata.tenantFieldName || metadata.enforceTenantIsolation === false) {
|
|
@@ -1275,8 +1342,10 @@ var QueryEngine = class {
|
|
|
1275
1342
|
params[tenantField] = tenantId;
|
|
1276
1343
|
tenantPredicate = `${tenantField} = @${tenantField}`;
|
|
1277
1344
|
} else {
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1345
|
+
const paramIndex = this.nextPostgresPlaceholderIndex(sql, params);
|
|
1346
|
+
params[String(paramIndex)] = tenantId;
|
|
1347
|
+
params[tenantField] = tenantId;
|
|
1348
|
+
tenantPredicate = `${tenantField} = $${paramIndex}`;
|
|
1280
1349
|
}
|
|
1281
1350
|
if (/\bwhere\b/i.test(sql)) {
|
|
1282
1351
|
return sql.replace(
|
|
@@ -1286,6 +1355,23 @@ var QueryEngine = class {
|
|
|
1286
1355
|
}
|
|
1287
1356
|
return `${sql} WHERE ${tenantPredicate}`;
|
|
1288
1357
|
}
|
|
1358
|
+
nextPostgresPlaceholderIndex(sql, params) {
|
|
1359
|
+
let max = 0;
|
|
1360
|
+
for (const match of sql.matchAll(/\$(\d+)\b/g)) {
|
|
1361
|
+
const index = Number.parseInt(match[1], 10);
|
|
1362
|
+
if (Number.isFinite(index) && index > max) {
|
|
1363
|
+
max = index;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
if (max > 0) {
|
|
1367
|
+
return max + 1;
|
|
1368
|
+
}
|
|
1369
|
+
const numericKeys = Object.keys(params).filter((key) => /^\d+$/.test(key)).map((key) => Number.parseInt(key, 10)).filter((index) => Number.isFinite(index));
|
|
1370
|
+
if (numericKeys.length > 0) {
|
|
1371
|
+
return Math.max(...numericKeys) + 1;
|
|
1372
|
+
}
|
|
1373
|
+
return 1;
|
|
1374
|
+
}
|
|
1289
1375
|
};
|
|
1290
1376
|
|
|
1291
1377
|
// src/routes/charts.ts
|
|
@@ -1820,6 +1906,7 @@ function resolveTenantId4(client, tenantId) {
|
|
|
1820
1906
|
function buildSchemaRequest(databaseName, adapter, introspection, metadata) {
|
|
1821
1907
|
const dialect = adapter.getDialect();
|
|
1822
1908
|
const tables = introspection.tables.map((table) => ({
|
|
1909
|
+
schema_name: table.schema,
|
|
1823
1910
|
table_name: table.name,
|
|
1824
1911
|
description: table.comment ?? `Table ${table.name}`,
|
|
1825
1912
|
columns: table.columns.map((column) => ({
|
|
@@ -3495,6 +3582,8 @@ export {
|
|
|
3495
3582
|
QueryErrorCode,
|
|
3496
3583
|
QueryPanelSdkAPI,
|
|
3497
3584
|
QueryPipelineError,
|
|
3498
|
-
anonymizeResults
|
|
3585
|
+
anonymizeResults,
|
|
3586
|
+
mapGeneratedParams,
|
|
3587
|
+
normalizeSqlParamsInput
|
|
3499
3588
|
};
|
|
3500
3589
|
//# sourceMappingURL=index.js.map
|