@querypanel/node-sdk 1.0.26 → 1.0.27
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 +1292 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +388 -0
- package/dist/index.d.ts +388 -0
- package/dist/index.js +1262 -0
- package/dist/index.js.map +1 -0
- package/package.json +1 -1
- package/dist/cjs/__tests__/ingest.test.d.ts +0 -5
- package/dist/cjs/__tests__/ingest.test.d.ts.map +0 -1
- package/dist/cjs/__tests__/ingest.test.js +0 -95
- package/dist/cjs/__tests__/ingest.test.js.map +0 -1
- package/dist/cjs/adapters/clickhouse.d.ts +0 -48
- package/dist/cjs/adapters/clickhouse.d.ts.map +0 -1
- package/dist/cjs/adapters/clickhouse.js +0 -284
- package/dist/cjs/adapters/clickhouse.js.map +0 -1
- package/dist/cjs/adapters/introspection.spec.d.ts +0 -2
- package/dist/cjs/adapters/introspection.spec.d.ts.map +0 -1
- package/dist/cjs/adapters/introspection.spec.js +0 -192
- package/dist/cjs/adapters/introspection.spec.js.map +0 -1
- package/dist/cjs/adapters/postgres.d.ts +0 -46
- package/dist/cjs/adapters/postgres.d.ts.map +0 -1
- package/dist/cjs/adapters/postgres.js +0 -457
- package/dist/cjs/adapters/postgres.js.map +0 -1
- package/dist/cjs/adapters/postgres.spec.d.ts +0 -2
- package/dist/cjs/adapters/postgres.spec.d.ts.map +0 -1
- package/dist/cjs/adapters/postgres.spec.js +0 -37
- package/dist/cjs/adapters/postgres.spec.js.map +0 -1
- package/dist/cjs/adapters/types.d.ts +0 -38
- package/dist/cjs/adapters/types.d.ts.map +0 -1
- package/dist/cjs/adapters/types.js +0 -3
- package/dist/cjs/adapters/types.js.map +0 -1
- package/dist/cjs/anonymize.spec.d.ts +0 -2
- package/dist/cjs/anonymize.spec.d.ts.map +0 -1
- package/dist/cjs/anonymize.spec.js +0 -78
- package/dist/cjs/anonymize.spec.js.map +0 -1
- package/dist/cjs/clickhouseClient.spec.d.ts +0 -2
- package/dist/cjs/clickhouseClient.spec.d.ts.map +0 -1
- package/dist/cjs/clickhouseClient.spec.js +0 -286
- package/dist/cjs/clickhouseClient.spec.js.map +0 -1
- package/dist/cjs/connectors/__tests__/clickhouse.introspect.test.d.ts +0 -2
- package/dist/cjs/connectors/__tests__/clickhouse.introspect.test.d.ts.map +0 -1
- package/dist/cjs/connectors/__tests__/clickhouse.introspect.test.js +0 -119
- package/dist/cjs/connectors/__tests__/clickhouse.introspect.test.js.map +0 -1
- package/dist/cjs/connectors/base.d.ts +0 -13
- package/dist/cjs/connectors/base.d.ts.map +0 -1
- package/dist/cjs/connectors/base.js +0 -3
- package/dist/cjs/connectors/base.js.map +0 -1
- package/dist/cjs/connectors/clickhouse.d.ts +0 -53
- package/dist/cjs/connectors/clickhouse.d.ts.map +0 -1
- package/dist/cjs/connectors/clickhouse.js +0 -270
- package/dist/cjs/connectors/clickhouse.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -490
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -843
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/index.test.d.ts +0 -2
- package/dist/cjs/index.test.d.ts.map +0 -1
- package/dist/cjs/index.test.js +0 -185
- package/dist/cjs/index.test.js.map +0 -1
- package/dist/cjs/introspectV3.d.ts +0 -45
- package/dist/cjs/introspectV3.d.ts.map +0 -1
- package/dist/cjs/introspectV3.js +0 -99
- package/dist/cjs/introspectV3.js.map +0 -1
- package/dist/cjs/multidb.spec.d.ts +0 -2
- package/dist/cjs/multidb.spec.d.ts.map +0 -1
- package/dist/cjs/multidb.spec.js +0 -76
- package/dist/cjs/multidb.spec.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/schema/types.d.ts +0 -73
- package/dist/cjs/schema/types.d.ts.map +0 -1
- package/dist/cjs/schema/types.js +0 -3
- package/dist/cjs/schema/types.js.map +0 -1
- package/dist/cjs/tenant-isolation.spec.d.ts +0 -2
- package/dist/cjs/tenant-isolation.spec.d.ts.map +0 -1
- package/dist/cjs/tenant-isolation.spec.js +0 -420
- package/dist/cjs/tenant-isolation.spec.js.map +0 -1
- package/dist/cjs/utils/clickhouse.d.ts +0 -9
- package/dist/cjs/utils/clickhouse.d.ts.map +0 -1
- package/dist/cjs/utils/clickhouse.js +0 -99
- package/dist/cjs/utils/clickhouse.js.map +0 -1
- package/dist/esm/adapters/clickhouse.d.ts +0 -48
- package/dist/esm/adapters/clickhouse.d.ts.map +0 -1
- package/dist/esm/adapters/clickhouse.js +0 -280
- package/dist/esm/adapters/clickhouse.js.map +0 -1
- package/dist/esm/adapters/introspection.spec.d.ts +0 -2
- package/dist/esm/adapters/introspection.spec.d.ts.map +0 -1
- package/dist/esm/adapters/introspection.spec.js +0 -190
- package/dist/esm/adapters/introspection.spec.js.map +0 -1
- package/dist/esm/adapters/postgres.d.ts +0 -46
- package/dist/esm/adapters/postgres.d.ts.map +0 -1
- package/dist/esm/adapters/postgres.js +0 -453
- package/dist/esm/adapters/postgres.js.map +0 -1
- package/dist/esm/adapters/postgres.spec.d.ts +0 -2
- package/dist/esm/adapters/postgres.spec.d.ts.map +0 -1
- package/dist/esm/adapters/postgres.spec.js +0 -35
- package/dist/esm/adapters/postgres.spec.js.map +0 -1
- package/dist/esm/adapters/types.d.ts +0 -38
- package/dist/esm/adapters/types.d.ts.map +0 -1
- package/dist/esm/adapters/types.js +0 -2
- package/dist/esm/adapters/types.js.map +0 -1
- package/dist/esm/anonymize.spec.d.ts +0 -2
- package/dist/esm/anonymize.spec.d.ts.map +0 -1
- package/dist/esm/anonymize.spec.js +0 -76
- package/dist/esm/anonymize.spec.js.map +0 -1
- package/dist/esm/clickhouseClient.spec.d.ts +0 -2
- package/dist/esm/clickhouseClient.spec.d.ts.map +0 -1
- package/dist/esm/clickhouseClient.spec.js +0 -281
- package/dist/esm/clickhouseClient.spec.js.map +0 -1
- package/dist/esm/connectors/base.d.ts +0 -14
- package/dist/esm/connectors/base.d.ts.map +0 -1
- package/dist/esm/connectors/base.js +0 -2
- package/dist/esm/connectors/base.js.map +0 -1
- package/dist/esm/connectors/clickhouse.d.ts +0 -35
- package/dist/esm/connectors/clickhouse.d.ts.map +0 -1
- package/dist/esm/connectors/clickhouse.js +0 -281
- package/dist/esm/connectors/clickhouse.js.map +0 -1
- package/dist/esm/index.d.ts +0 -490
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -838
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.test.d.ts +0 -2
- package/dist/esm/index.test.d.ts.map +0 -1
- package/dist/esm/index.test.js +0 -183
- package/dist/esm/index.test.js.map +0 -1
- package/dist/esm/introspectV3.d.ts +0 -45
- package/dist/esm/introspectV3.d.ts.map +0 -1
- package/dist/esm/introspectV3.js +0 -96
- package/dist/esm/introspectV3.js.map +0 -1
- package/dist/esm/multidb.spec.d.ts +0 -2
- package/dist/esm/multidb.spec.d.ts.map +0 -1
- package/dist/esm/multidb.spec.js +0 -74
- package/dist/esm/multidb.spec.js.map +0 -1
- package/dist/esm/schema/types.d.ts +0 -73
- package/dist/esm/schema/types.d.ts.map +0 -1
- package/dist/esm/schema/types.js +0 -2
- package/dist/esm/schema/types.js.map +0 -1
- package/dist/esm/tenant-isolation.spec.d.ts +0 -2
- package/dist/esm/tenant-isolation.spec.d.ts.map +0 -1
- package/dist/esm/tenant-isolation.spec.js +0 -418
- package/dist/esm/tenant-isolation.spec.js.map +0 -1
- package/dist/esm/utils/clickhouse.d.ts +0 -9
- package/dist/esm/utils/clickhouse.d.ts.map +0 -1
- package/dist/esm/utils/clickhouse.js +0 -92
- package/dist/esm/utils/clickhouse.js.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,1262 @@
|
|
|
1
|
+
// src/utils/clickhouse.ts
|
|
2
|
+
var WRAPPER_REGEX = /^(Nullable|LowCardinality|SimpleAggregateFunction)\((.+)\)$/i;
|
|
3
|
+
function unwrapTypeModifiers(type) {
|
|
4
|
+
let current = type.trim();
|
|
5
|
+
let match = WRAPPER_REGEX.exec(current);
|
|
6
|
+
while (match) {
|
|
7
|
+
const inner = match[2];
|
|
8
|
+
if (!inner) {
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
current = inner.trim();
|
|
12
|
+
match = WRAPPER_REGEX.exec(current);
|
|
13
|
+
}
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
function parseKeyExpression(expression) {
|
|
17
|
+
if (!expression) return [];
|
|
18
|
+
let value = expression.trim();
|
|
19
|
+
if (!value) return [];
|
|
20
|
+
if (/^tuple\s*\(/i.test(value) && value.endsWith(")")) {
|
|
21
|
+
value = value.replace(/^tuple\s*\(/i, "").replace(/\)$/, "");
|
|
22
|
+
}
|
|
23
|
+
const columns = [];
|
|
24
|
+
let depth = 0;
|
|
25
|
+
let token = "";
|
|
26
|
+
for (const ch of value) {
|
|
27
|
+
if (ch === "(") {
|
|
28
|
+
depth += 1;
|
|
29
|
+
token += ch;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === ")") {
|
|
33
|
+
depth = Math.max(0, depth - 1);
|
|
34
|
+
token += ch;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (ch === "," && depth === 0) {
|
|
38
|
+
const col = token.trim();
|
|
39
|
+
if (col) columns.push(stripWrapper(col));
|
|
40
|
+
token = "";
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
token += ch;
|
|
44
|
+
}
|
|
45
|
+
const last = token.trim();
|
|
46
|
+
if (last) columns.push(stripWrapper(last));
|
|
47
|
+
return columns.filter(Boolean);
|
|
48
|
+
}
|
|
49
|
+
function stripWrapper(value) {
|
|
50
|
+
const noQuotes = stripQuotes(value);
|
|
51
|
+
const withoutTicks = noQuotes.replace(/`/g, "").trim();
|
|
52
|
+
const parts = withoutTicks.split(".");
|
|
53
|
+
return parts[parts.length - 1]?.trim() ?? "";
|
|
54
|
+
}
|
|
55
|
+
function stripQuotes(value) {
|
|
56
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
57
|
+
return value.slice(1, -1);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/adapters/clickhouse.ts
|
|
63
|
+
var ClickHouseAdapter = class {
|
|
64
|
+
constructor(clientFn, options = {}) {
|
|
65
|
+
this.clientFn = clientFn;
|
|
66
|
+
this.databaseName = options.database ?? "default";
|
|
67
|
+
this.defaultFormat = options.defaultFormat ?? "JSONEachRow";
|
|
68
|
+
this.kind = options.kind ?? "clickhouse";
|
|
69
|
+
if (options.allowedTables) {
|
|
70
|
+
this.allowedTables = normalizeTableFilter(options.allowedTables);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
databaseName;
|
|
74
|
+
defaultFormat;
|
|
75
|
+
kind;
|
|
76
|
+
allowedTables;
|
|
77
|
+
async execute(sql, params) {
|
|
78
|
+
if (this.allowedTables) {
|
|
79
|
+
this.validateQueryTables(sql);
|
|
80
|
+
}
|
|
81
|
+
const queryOptions = {
|
|
82
|
+
format: this.defaultFormat
|
|
83
|
+
};
|
|
84
|
+
if (params) {
|
|
85
|
+
queryOptions.params = params;
|
|
86
|
+
}
|
|
87
|
+
const rows = await this.query(sql, queryOptions);
|
|
88
|
+
const fields = rows.length > 0 ? Object.keys(rows[0] ?? {}) : [];
|
|
89
|
+
return { fields, rows };
|
|
90
|
+
}
|
|
91
|
+
async validate(sql, params) {
|
|
92
|
+
const queryOptions = {
|
|
93
|
+
format: this.defaultFormat
|
|
94
|
+
};
|
|
95
|
+
if (params) {
|
|
96
|
+
queryOptions.params = params;
|
|
97
|
+
}
|
|
98
|
+
await this.query(`EXPLAIN ${sql}`, queryOptions);
|
|
99
|
+
}
|
|
100
|
+
getDialect() {
|
|
101
|
+
return "clickhouse";
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Simplified introspection: only collect table/column metadata for IngestRequest
|
|
105
|
+
* No indexes, constraints, or statistics
|
|
106
|
+
*/
|
|
107
|
+
async introspect(options) {
|
|
108
|
+
const tablesToIntrospect = options?.tables ? normalizeTableFilter(options.tables) : this.allowedTables;
|
|
109
|
+
const allowTables = tablesToIntrospect ?? [];
|
|
110
|
+
const hasFilter = allowTables.length > 0;
|
|
111
|
+
const queryParams = {
|
|
112
|
+
db: this.databaseName
|
|
113
|
+
};
|
|
114
|
+
if (hasFilter) {
|
|
115
|
+
queryParams.tables = allowTables;
|
|
116
|
+
}
|
|
117
|
+
const filterClause = hasFilter ? " AND name IN {tables:Array(String)}" : "";
|
|
118
|
+
const tables = await this.query(
|
|
119
|
+
`SELECT name, engine, comment, primary_key
|
|
120
|
+
FROM system.tables
|
|
121
|
+
WHERE database = {db:String}${filterClause}
|
|
122
|
+
ORDER BY name`,
|
|
123
|
+
{ params: queryParams }
|
|
124
|
+
);
|
|
125
|
+
const columnFilterClause = hasFilter ? " AND table IN {tables:Array(String)}" : "";
|
|
126
|
+
const columns = await this.query(
|
|
127
|
+
`SELECT table, name, type, position, comment, is_in_primary_key
|
|
128
|
+
FROM system.columns
|
|
129
|
+
WHERE database = {db:String}${columnFilterClause}
|
|
130
|
+
ORDER BY table, position`,
|
|
131
|
+
{ params: queryParams }
|
|
132
|
+
);
|
|
133
|
+
const columnsByTable = /* @__PURE__ */ new Map();
|
|
134
|
+
for (const rawColumn of columns) {
|
|
135
|
+
const list = columnsByTable.get(rawColumn.table) ?? [];
|
|
136
|
+
list.push(transformColumnRow(rawColumn));
|
|
137
|
+
columnsByTable.set(rawColumn.table, list);
|
|
138
|
+
}
|
|
139
|
+
const tableSchemas = tables.map((table) => {
|
|
140
|
+
const tableColumns = columnsByTable.get(table.name) ?? [];
|
|
141
|
+
const primaryKeyColumns = parseKeyExpression(table.primary_key);
|
|
142
|
+
for (const column of tableColumns) {
|
|
143
|
+
column.isPrimaryKey = column.isPrimaryKey || primaryKeyColumns.includes(column.name);
|
|
144
|
+
}
|
|
145
|
+
const base = {
|
|
146
|
+
name: table.name,
|
|
147
|
+
schema: this.databaseName,
|
|
148
|
+
type: asTableType(table.engine),
|
|
149
|
+
columns: tableColumns
|
|
150
|
+
};
|
|
151
|
+
const comment = sanitize(table.comment);
|
|
152
|
+
if (comment !== void 0) {
|
|
153
|
+
base.comment = comment;
|
|
154
|
+
}
|
|
155
|
+
return base;
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
db: {
|
|
159
|
+
kind: this.kind,
|
|
160
|
+
name: this.databaseName
|
|
161
|
+
},
|
|
162
|
+
tables: tableSchemas,
|
|
163
|
+
introspectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
validateQueryTables(sql) {
|
|
167
|
+
if (!this.allowedTables || this.allowedTables.length === 0) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const allowedSet = new Set(this.allowedTables);
|
|
171
|
+
const tablePattern = /(?:FROM|JOIN)\s+(?:FINAL\s+)?(?:(?:[a-zA-Z_][a-zA-Z0-9_]*)\.)?(["'`]?[a-zA-Z_][a-zA-Z0-9_]*["'`]?)/gi;
|
|
172
|
+
const matches = sql.matchAll(tablePattern);
|
|
173
|
+
for (const match of matches) {
|
|
174
|
+
const table = match[1]?.replace(/["'`]/g, "");
|
|
175
|
+
if (table) {
|
|
176
|
+
if (!allowedSet.has(table)) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Query references table "${table}" which is not in the allowed tables list`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async close() {
|
|
185
|
+
}
|
|
186
|
+
async query(sql, options) {
|
|
187
|
+
const params = {
|
|
188
|
+
query: sql
|
|
189
|
+
};
|
|
190
|
+
const format = options?.format ?? this.defaultFormat;
|
|
191
|
+
if (format !== void 0) {
|
|
192
|
+
params.format = format;
|
|
193
|
+
}
|
|
194
|
+
if (options?.params) {
|
|
195
|
+
params.query_params = options.params;
|
|
196
|
+
}
|
|
197
|
+
if (options?.settings) {
|
|
198
|
+
params.clickhouse_settings = options.settings;
|
|
199
|
+
}
|
|
200
|
+
const result = await this.clientFn(params);
|
|
201
|
+
return this.extractRows(result);
|
|
202
|
+
}
|
|
203
|
+
async extractRows(result) {
|
|
204
|
+
if (Array.isArray(result)) {
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
if (result && typeof result.json === "function") {
|
|
208
|
+
const payload = await result.json();
|
|
209
|
+
return normalizePayload(payload);
|
|
210
|
+
}
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
function normalizePayload(payload) {
|
|
215
|
+
if (Array.isArray(payload)) {
|
|
216
|
+
return payload;
|
|
217
|
+
}
|
|
218
|
+
if (payload && typeof payload === "object") {
|
|
219
|
+
const maybeData = payload.data;
|
|
220
|
+
if (Array.isArray(maybeData)) {
|
|
221
|
+
return maybeData;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
function normalizeTableFilter(tables) {
|
|
227
|
+
if (!tables?.length) return [];
|
|
228
|
+
const seen = /* @__PURE__ */ new Set();
|
|
229
|
+
const normalized = [];
|
|
230
|
+
for (const table of tables) {
|
|
231
|
+
if (!table) continue;
|
|
232
|
+
const trimmed = table.trim();
|
|
233
|
+
if (!trimmed) continue;
|
|
234
|
+
const parts = trimmed.split(".");
|
|
235
|
+
const tableName = parts[parts.length - 1];
|
|
236
|
+
if (!tableName || seen.has(tableName)) continue;
|
|
237
|
+
seen.add(tableName);
|
|
238
|
+
normalized.push(tableName);
|
|
239
|
+
}
|
|
240
|
+
return normalized;
|
|
241
|
+
}
|
|
242
|
+
function transformColumnRow(row) {
|
|
243
|
+
const unwrappedType = unwrapTypeModifiers(row.type);
|
|
244
|
+
const column = {
|
|
245
|
+
name: row.name,
|
|
246
|
+
type: unwrappedType,
|
|
247
|
+
rawType: row.type,
|
|
248
|
+
isPrimaryKey: Boolean(toNumber(row.is_in_primary_key))
|
|
249
|
+
};
|
|
250
|
+
const comment = sanitize(row.comment);
|
|
251
|
+
if (comment !== void 0) column.comment = comment;
|
|
252
|
+
return column;
|
|
253
|
+
}
|
|
254
|
+
function asTableType(engine) {
|
|
255
|
+
if (typeof engine === "string") {
|
|
256
|
+
const normalized = engine.toLowerCase();
|
|
257
|
+
if (normalized.includes("view")) {
|
|
258
|
+
return "view";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return "table";
|
|
262
|
+
}
|
|
263
|
+
function sanitize(value) {
|
|
264
|
+
if (value === null || value === void 0) return void 0;
|
|
265
|
+
const trimmed = String(value).trim();
|
|
266
|
+
return trimmed.length ? trimmed : void 0;
|
|
267
|
+
}
|
|
268
|
+
function toNumber(value) {
|
|
269
|
+
if (value === null || value === void 0) return void 0;
|
|
270
|
+
if (typeof value === "number") return value;
|
|
271
|
+
const parsed = Number.parseFloat(String(value));
|
|
272
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/adapters/postgres.ts
|
|
276
|
+
var PostgresAdapter = class {
|
|
277
|
+
constructor(clientFn, options = {}) {
|
|
278
|
+
this.clientFn = clientFn;
|
|
279
|
+
this.databaseName = options.database ?? "postgres";
|
|
280
|
+
this.defaultSchema = options.defaultSchema ?? "public";
|
|
281
|
+
this.kind = options.kind ?? "postgres";
|
|
282
|
+
if (options.allowedTables) {
|
|
283
|
+
this.allowedTables = normalizeTableFilter2(
|
|
284
|
+
options.allowedTables,
|
|
285
|
+
this.defaultSchema
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
databaseName;
|
|
290
|
+
defaultSchema;
|
|
291
|
+
kind;
|
|
292
|
+
allowedTables;
|
|
293
|
+
async execute(sql, params) {
|
|
294
|
+
if (this.allowedTables) {
|
|
295
|
+
this.validateQueryTables(sql);
|
|
296
|
+
}
|
|
297
|
+
let paramArray;
|
|
298
|
+
if (params) {
|
|
299
|
+
paramArray = this.convertNamedToPositionalParams(params);
|
|
300
|
+
}
|
|
301
|
+
const result = await this.clientFn(sql, paramArray);
|
|
302
|
+
const fields = result.fields.map((f) => f.name);
|
|
303
|
+
return { fields, rows: result.rows };
|
|
304
|
+
}
|
|
305
|
+
validateQueryTables(sql) {
|
|
306
|
+
if (!this.allowedTables || this.allowedTables.length === 0) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const allowedSet = new Set(
|
|
310
|
+
this.allowedTables.map((t) => tableKey(t.schema, t.table))
|
|
311
|
+
);
|
|
312
|
+
const tablePattern = /(?:FROM|JOIN)\s+(?:ONLY\s+)?(?:([a-zA-Z_][a-zA-Z0-9_]*)\.)?(["']?[a-zA-Z_][a-zA-Z0-9_]*["']?)/gi;
|
|
313
|
+
const matches = sql.matchAll(tablePattern);
|
|
314
|
+
for (const match of matches) {
|
|
315
|
+
const schema = match[1] ?? this.defaultSchema;
|
|
316
|
+
const table = match[2]?.replace(/['"]/g, "");
|
|
317
|
+
if (table) {
|
|
318
|
+
const key = tableKey(schema, table);
|
|
319
|
+
if (!allowedSet.has(key)) {
|
|
320
|
+
throw new Error(
|
|
321
|
+
`Query references table "${schema}.${table}" which is not in the allowed tables list`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Convert named params to positional array for PostgreSQL
|
|
329
|
+
* PostgreSQL expects $1, $2, $3 in SQL and an array of values [val1, val2, val3]
|
|
330
|
+
*/
|
|
331
|
+
convertNamedToPositionalParams(params) {
|
|
332
|
+
const numericKeys = Object.keys(params).filter((k) => /^\d+$/.test(k)).map((k) => Number.parseInt(k, 10)).sort((a, b) => a - b);
|
|
333
|
+
const namedKeys = Object.keys(params).filter((k) => !/^\d+$/.test(k)).sort();
|
|
334
|
+
const positionalParams = [];
|
|
335
|
+
for (const key of numericKeys) {
|
|
336
|
+
let val = params[String(key)];
|
|
337
|
+
if (typeof val === "string") {
|
|
338
|
+
const match = val.match(/^<([a-zA-Z0-9_]+)>$/);
|
|
339
|
+
const namedKey = match?.[1];
|
|
340
|
+
if (namedKey && namedKey in params) {
|
|
341
|
+
val = params[namedKey];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
positionalParams.push(val);
|
|
345
|
+
}
|
|
346
|
+
for (const key of namedKeys) {
|
|
347
|
+
const val = params[key];
|
|
348
|
+
positionalParams.push(val);
|
|
349
|
+
}
|
|
350
|
+
return positionalParams;
|
|
351
|
+
}
|
|
352
|
+
async validate(sql, params) {
|
|
353
|
+
let paramArray;
|
|
354
|
+
if (params) {
|
|
355
|
+
paramArray = this.convertNamedToPositionalParams(params);
|
|
356
|
+
}
|
|
357
|
+
await this.clientFn(`EXPLAIN ${sql}`, paramArray);
|
|
358
|
+
}
|
|
359
|
+
getDialect() {
|
|
360
|
+
return "postgres";
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Simplified introspection: only collect table/column metadata for IngestRequest
|
|
364
|
+
* No indexes, constraints, or statistics
|
|
365
|
+
*/
|
|
366
|
+
async introspect(options) {
|
|
367
|
+
const tablesToIntrospect = options?.tables ? normalizeTableFilter2(options.tables, this.defaultSchema) : this.allowedTables;
|
|
368
|
+
const normalizedTables = tablesToIntrospect ?? [];
|
|
369
|
+
const tablesResult = await this.clientFn(
|
|
370
|
+
buildTablesQuery(normalizedTables)
|
|
371
|
+
);
|
|
372
|
+
const tableRows = tablesResult.rows;
|
|
373
|
+
const columnsResult = await this.clientFn(
|
|
374
|
+
buildColumnsQuery(normalizedTables)
|
|
375
|
+
);
|
|
376
|
+
const columnRows = columnsResult.rows;
|
|
377
|
+
const tablesByKey = /* @__PURE__ */ new Map();
|
|
378
|
+
for (const row of tableRows) {
|
|
379
|
+
const key = tableKey(row.schema_name, row.table_name);
|
|
380
|
+
const table = {
|
|
381
|
+
name: row.table_name,
|
|
382
|
+
schema: row.schema_name,
|
|
383
|
+
type: asTableType2(row.table_type),
|
|
384
|
+
columns: []
|
|
385
|
+
};
|
|
386
|
+
const comment = sanitize2(row.comment);
|
|
387
|
+
if (comment !== void 0) {
|
|
388
|
+
table.comment = comment;
|
|
389
|
+
}
|
|
390
|
+
tablesByKey.set(key, table);
|
|
391
|
+
}
|
|
392
|
+
for (const row of columnRows) {
|
|
393
|
+
const key = tableKey(row.table_schema, row.table_name);
|
|
394
|
+
const table = tablesByKey.get(key);
|
|
395
|
+
if (!table) continue;
|
|
396
|
+
const column = {
|
|
397
|
+
name: row.column_name,
|
|
398
|
+
type: row.data_type,
|
|
399
|
+
isPrimaryKey: row.is_primary_key
|
|
400
|
+
};
|
|
401
|
+
const rawType = row.udt_name ?? void 0;
|
|
402
|
+
if (rawType !== void 0) column.rawType = rawType;
|
|
403
|
+
const comment = sanitize2(row.description);
|
|
404
|
+
if (comment !== void 0) column.comment = comment;
|
|
405
|
+
table.columns.push(column);
|
|
406
|
+
}
|
|
407
|
+
const tables = Array.from(tablesByKey.values()).sort((a, b) => {
|
|
408
|
+
if (a.schema === b.schema) {
|
|
409
|
+
return a.name.localeCompare(b.name);
|
|
410
|
+
}
|
|
411
|
+
return a.schema.localeCompare(b.schema);
|
|
412
|
+
});
|
|
413
|
+
return {
|
|
414
|
+
db: {
|
|
415
|
+
kind: this.kind,
|
|
416
|
+
name: this.databaseName
|
|
417
|
+
},
|
|
418
|
+
tables,
|
|
419
|
+
introspectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
function normalizeTableFilter2(tables, defaultSchema) {
|
|
424
|
+
if (!tables?.length) return [];
|
|
425
|
+
const normalized = [];
|
|
426
|
+
const seen = /* @__PURE__ */ new Set();
|
|
427
|
+
for (const raw of tables) {
|
|
428
|
+
if (!raw) continue;
|
|
429
|
+
const trimmed = raw.trim();
|
|
430
|
+
if (!trimmed) continue;
|
|
431
|
+
const parts = trimmed.split(".");
|
|
432
|
+
const table = parts.pop() ?? "";
|
|
433
|
+
const schema = parts.pop() ?? defaultSchema;
|
|
434
|
+
if (!isSafeIdentifier(schema) || !isSafeIdentifier(table)) {
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
const key = tableKey(schema, table);
|
|
438
|
+
if (seen.has(key)) continue;
|
|
439
|
+
seen.add(key);
|
|
440
|
+
normalized.push({ schema, table });
|
|
441
|
+
}
|
|
442
|
+
return normalized;
|
|
443
|
+
}
|
|
444
|
+
function buildTablesQuery(tables) {
|
|
445
|
+
const filter = buildFilterClause(tables, "n.nspname", "c.relname");
|
|
446
|
+
return `SELECT
|
|
447
|
+
c.relname AS table_name,
|
|
448
|
+
n.nspname AS schema_name,
|
|
449
|
+
CASE c.relkind
|
|
450
|
+
WHEN 'r' THEN 'table'
|
|
451
|
+
WHEN 'v' THEN 'view'
|
|
452
|
+
WHEN 'm' THEN 'materialized_view'
|
|
453
|
+
ELSE c.relkind::text
|
|
454
|
+
END AS table_type,
|
|
455
|
+
obj_description(c.oid) AS comment
|
|
456
|
+
FROM pg_class c
|
|
457
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
458
|
+
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
459
|
+
AND c.relkind IN ('r', 'v', 'm')
|
|
460
|
+
${filter}
|
|
461
|
+
ORDER BY n.nspname, c.relname;`;
|
|
462
|
+
}
|
|
463
|
+
function buildColumnsQuery(tables) {
|
|
464
|
+
const filter = buildFilterClause(
|
|
465
|
+
tables,
|
|
466
|
+
"cols.table_schema",
|
|
467
|
+
"cols.table_name"
|
|
468
|
+
);
|
|
469
|
+
return `SELECT
|
|
470
|
+
cols.table_name,
|
|
471
|
+
cols.table_schema,
|
|
472
|
+
cols.column_name,
|
|
473
|
+
cols.data_type,
|
|
474
|
+
cols.udt_name,
|
|
475
|
+
pgd.description,
|
|
476
|
+
EXISTS(
|
|
477
|
+
SELECT 1
|
|
478
|
+
FROM information_schema.table_constraints tc
|
|
479
|
+
JOIN information_schema.key_column_usage kcu
|
|
480
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
481
|
+
AND tc.table_schema = kcu.table_schema
|
|
482
|
+
WHERE tc.constraint_type = 'PRIMARY KEY'
|
|
483
|
+
AND tc.table_schema = cols.table_schema
|
|
484
|
+
AND tc.table_name = cols.table_name
|
|
485
|
+
AND kcu.column_name = cols.column_name
|
|
486
|
+
) AS is_primary_key
|
|
487
|
+
FROM information_schema.columns cols
|
|
488
|
+
LEFT JOIN pg_catalog.pg_class c
|
|
489
|
+
ON c.relname = cols.table_name
|
|
490
|
+
AND c.relkind IN ('r', 'v', 'm')
|
|
491
|
+
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
|
492
|
+
LEFT JOIN pg_catalog.pg_attribute attr
|
|
493
|
+
ON attr.attrelid = c.oid
|
|
494
|
+
AND attr.attname = cols.column_name
|
|
495
|
+
LEFT JOIN pg_catalog.pg_description pgd
|
|
496
|
+
ON pgd.objoid = attr.attrelid AND pgd.objsubid = attr.attnum
|
|
497
|
+
WHERE cols.table_schema NOT IN ('pg_catalog', 'information_schema')
|
|
498
|
+
${filter}
|
|
499
|
+
ORDER BY cols.table_schema, cols.table_name, cols.ordinal_position;`;
|
|
500
|
+
}
|
|
501
|
+
function buildFilterClause(tables, schemaExpr, tableExpr) {
|
|
502
|
+
if (!tables.length) return "";
|
|
503
|
+
const clauses = tables.map(({ schema, table }) => {
|
|
504
|
+
return `(${schemaExpr} = '${schema}' AND ${tableExpr} = '${table}')`;
|
|
505
|
+
});
|
|
506
|
+
return `AND (${clauses.join(" OR ")})`;
|
|
507
|
+
}
|
|
508
|
+
function tableKey(schema, table) {
|
|
509
|
+
return `${schema}.${table}`;
|
|
510
|
+
}
|
|
511
|
+
function isSafeIdentifier(value) {
|
|
512
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
|
|
513
|
+
}
|
|
514
|
+
function asTableType2(value) {
|
|
515
|
+
const normalized = value.toLowerCase();
|
|
516
|
+
if (normalized.includes("view")) {
|
|
517
|
+
return normalized.includes("materialized") ? "materialized_view" : "view";
|
|
518
|
+
}
|
|
519
|
+
return "table";
|
|
520
|
+
}
|
|
521
|
+
function sanitize2(value) {
|
|
522
|
+
if (value === null || value === void 0) return void 0;
|
|
523
|
+
const trimmed = String(value).trim();
|
|
524
|
+
return trimmed.length ? trimmed : void 0;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// src/core/client.ts
|
|
528
|
+
import { importPKCS8, SignJWT } from "jose";
|
|
529
|
+
var ApiClient = class {
|
|
530
|
+
baseUrl;
|
|
531
|
+
privateKey;
|
|
532
|
+
organizationId;
|
|
533
|
+
defaultTenantId;
|
|
534
|
+
additionalHeaders;
|
|
535
|
+
fetchImpl;
|
|
536
|
+
cachedPrivateKey;
|
|
537
|
+
constructor(baseUrl, privateKey, organizationId, options) {
|
|
538
|
+
if (!baseUrl) {
|
|
539
|
+
throw new Error("Base URL is required");
|
|
540
|
+
}
|
|
541
|
+
if (!privateKey) {
|
|
542
|
+
throw new Error("Private key is required");
|
|
543
|
+
}
|
|
544
|
+
if (!organizationId) {
|
|
545
|
+
throw new Error("Organization ID is required");
|
|
546
|
+
}
|
|
547
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
548
|
+
this.privateKey = privateKey;
|
|
549
|
+
this.organizationId = organizationId;
|
|
550
|
+
this.defaultTenantId = options?.defaultTenantId;
|
|
551
|
+
this.additionalHeaders = options?.additionalHeaders;
|
|
552
|
+
this.fetchImpl = options?.fetch ?? globalThis.fetch;
|
|
553
|
+
if (!this.fetchImpl) {
|
|
554
|
+
throw new Error(
|
|
555
|
+
"Fetch implementation not found. Provide options.fetch or use Node 18+."
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
getDefaultTenantId() {
|
|
560
|
+
return this.defaultTenantId;
|
|
561
|
+
}
|
|
562
|
+
async get(path, tenantId, userId, scopes, signal, sessionId) {
|
|
563
|
+
return await this.request(path, {
|
|
564
|
+
method: "GET",
|
|
565
|
+
headers: await this.buildHeaders(tenantId, userId, scopes, false, sessionId),
|
|
566
|
+
signal
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
async post(path, body, tenantId, userId, scopes, signal, sessionId) {
|
|
570
|
+
return await this.request(path, {
|
|
571
|
+
method: "POST",
|
|
572
|
+
headers: await this.buildHeaders(tenantId, userId, scopes, true, sessionId),
|
|
573
|
+
body: JSON.stringify(body ?? {}),
|
|
574
|
+
signal
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
async put(path, body, tenantId, userId, scopes, signal, sessionId) {
|
|
578
|
+
return await this.request(path, {
|
|
579
|
+
method: "PUT",
|
|
580
|
+
headers: await this.buildHeaders(tenantId, userId, scopes, true, sessionId),
|
|
581
|
+
body: JSON.stringify(body ?? {}),
|
|
582
|
+
signal
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
async delete(path, tenantId, userId, scopes, signal, sessionId) {
|
|
586
|
+
return await this.request(path, {
|
|
587
|
+
method: "DELETE",
|
|
588
|
+
headers: await this.buildHeaders(tenantId, userId, scopes, false, sessionId),
|
|
589
|
+
signal
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
async request(path, init) {
|
|
593
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, init);
|
|
594
|
+
const text = await response.text();
|
|
595
|
+
let json;
|
|
596
|
+
try {
|
|
597
|
+
json = text ? JSON.parse(text) : void 0;
|
|
598
|
+
} catch {
|
|
599
|
+
json = void 0;
|
|
600
|
+
}
|
|
601
|
+
if (!response.ok) {
|
|
602
|
+
const error = new Error(
|
|
603
|
+
json?.error || response.statusText || "Request failed"
|
|
604
|
+
);
|
|
605
|
+
error.status = response.status;
|
|
606
|
+
if (json?.details) error.details = json.details;
|
|
607
|
+
throw error;
|
|
608
|
+
}
|
|
609
|
+
return json;
|
|
610
|
+
}
|
|
611
|
+
async buildHeaders(tenantId, userId, scopes, includeJson = true, sessionId) {
|
|
612
|
+
const token = await this.generateJWT(tenantId, userId, scopes);
|
|
613
|
+
const headers = {
|
|
614
|
+
Authorization: `Bearer ${token}`,
|
|
615
|
+
Accept: "application/json"
|
|
616
|
+
};
|
|
617
|
+
if (includeJson) {
|
|
618
|
+
headers["Content-Type"] = "application/json";
|
|
619
|
+
}
|
|
620
|
+
if (sessionId) {
|
|
621
|
+
headers["x-session-id"] = sessionId;
|
|
622
|
+
}
|
|
623
|
+
if (this.additionalHeaders) {
|
|
624
|
+
Object.assign(headers, this.additionalHeaders);
|
|
625
|
+
}
|
|
626
|
+
return headers;
|
|
627
|
+
}
|
|
628
|
+
async generateJWT(tenantId, userId, scopes) {
|
|
629
|
+
if (!this.cachedPrivateKey) {
|
|
630
|
+
this.cachedPrivateKey = await importPKCS8(this.privateKey, "RS256");
|
|
631
|
+
}
|
|
632
|
+
const payload = {
|
|
633
|
+
organizationId: this.organizationId,
|
|
634
|
+
tenantId
|
|
635
|
+
};
|
|
636
|
+
if (userId) payload.userId = userId;
|
|
637
|
+
if (scopes?.length) payload.scopes = scopes;
|
|
638
|
+
return await new SignJWT(payload).setProtectedHeader({ alg: "RS256" }).setIssuedAt().setExpirationTime("1h").sign(this.cachedPrivateKey);
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/core/query-engine.ts
|
|
643
|
+
var QueryEngine = class {
|
|
644
|
+
databases = /* @__PURE__ */ new Map();
|
|
645
|
+
databaseMetadata = /* @__PURE__ */ new Map();
|
|
646
|
+
defaultDatabase;
|
|
647
|
+
attachDatabase(name, adapter, metadata) {
|
|
648
|
+
this.databases.set(name, adapter);
|
|
649
|
+
this.databaseMetadata.set(name, metadata);
|
|
650
|
+
if (!this.defaultDatabase) {
|
|
651
|
+
this.defaultDatabase = name;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
getDatabase(name) {
|
|
655
|
+
const dbName = name ?? this.defaultDatabase;
|
|
656
|
+
if (!dbName) {
|
|
657
|
+
throw new Error("No database attached.");
|
|
658
|
+
}
|
|
659
|
+
const adapter = this.databases.get(dbName);
|
|
660
|
+
if (!adapter) {
|
|
661
|
+
throw new Error(
|
|
662
|
+
`Database '${dbName}' not found. Attached: ${Array.from(
|
|
663
|
+
this.databases.keys()
|
|
664
|
+
).join(", ")}`
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
return adapter;
|
|
668
|
+
}
|
|
669
|
+
getDatabaseMetadata(name) {
|
|
670
|
+
const dbName = name ?? this.defaultDatabase;
|
|
671
|
+
if (!dbName) return void 0;
|
|
672
|
+
return this.databaseMetadata.get(dbName);
|
|
673
|
+
}
|
|
674
|
+
getDefaultDatabase() {
|
|
675
|
+
return this.defaultDatabase;
|
|
676
|
+
}
|
|
677
|
+
async validateAndExecute(sql, params, databaseName, tenantId) {
|
|
678
|
+
const adapter = this.getDatabase(databaseName);
|
|
679
|
+
const metadata = this.getDatabaseMetadata(databaseName);
|
|
680
|
+
let finalSql = sql;
|
|
681
|
+
if (metadata) {
|
|
682
|
+
finalSql = this.ensureTenantIsolation(sql, params, metadata, tenantId);
|
|
683
|
+
}
|
|
684
|
+
await adapter.validate(finalSql, params);
|
|
685
|
+
const result = await adapter.execute(finalSql, params);
|
|
686
|
+
return {
|
|
687
|
+
rows: result.rows,
|
|
688
|
+
fields: result.fields
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
async execute(sql, params, databaseName) {
|
|
692
|
+
try {
|
|
693
|
+
const adapter = this.getDatabase(databaseName);
|
|
694
|
+
const result = await adapter.execute(sql, params);
|
|
695
|
+
return result.rows;
|
|
696
|
+
} catch (error) {
|
|
697
|
+
console.warn(
|
|
698
|
+
`Failed to execute SQL locally for database '${databaseName}':`,
|
|
699
|
+
error
|
|
700
|
+
);
|
|
701
|
+
return [];
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
mapGeneratedParams(params) {
|
|
705
|
+
const record = {};
|
|
706
|
+
params.forEach((param, index) => {
|
|
707
|
+
const value = param.value;
|
|
708
|
+
if (value === void 0) {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
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);
|
|
712
|
+
const key = nameCandidate.replace(/[{}:$]/g, "").trim();
|
|
713
|
+
record[key] = value;
|
|
714
|
+
});
|
|
715
|
+
return record;
|
|
716
|
+
}
|
|
717
|
+
ensureTenantIsolation(sql, params, metadata, tenantId) {
|
|
718
|
+
if (!metadata.tenantFieldName || metadata.enforceTenantIsolation === false) {
|
|
719
|
+
return sql;
|
|
720
|
+
}
|
|
721
|
+
const tenantField = metadata.tenantFieldName;
|
|
722
|
+
const paramKey = tenantField;
|
|
723
|
+
params[paramKey] = tenantId;
|
|
724
|
+
const normalizedSql = sql.toLowerCase();
|
|
725
|
+
if (normalizedSql.includes(tenantField.toLowerCase())) {
|
|
726
|
+
return sql;
|
|
727
|
+
}
|
|
728
|
+
const tenantPredicate = metadata.dialect === "clickhouse" ? `${tenantField} = {${tenantField}:${metadata.tenantFieldType ?? "String"}}` : `${tenantField} = '${tenantId}'`;
|
|
729
|
+
if (/\bwhere\b/i.test(sql)) {
|
|
730
|
+
return sql.replace(
|
|
731
|
+
/\bwhere\b/i,
|
|
732
|
+
(match) => `${match} ${tenantPredicate} AND `
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
return `${sql} WHERE ${tenantPredicate}`;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
// src/routes/charts.ts
|
|
740
|
+
async function createChart(client, body, options, signal) {
|
|
741
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
742
|
+
return await client.post(
|
|
743
|
+
"/charts",
|
|
744
|
+
body,
|
|
745
|
+
tenantId,
|
|
746
|
+
options?.userId,
|
|
747
|
+
options?.scopes,
|
|
748
|
+
signal
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
async function listCharts(client, queryEngine, options, signal) {
|
|
752
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
753
|
+
const params = new URLSearchParams();
|
|
754
|
+
if (options?.pagination?.page)
|
|
755
|
+
params.set("page", `${options.pagination.page}`);
|
|
756
|
+
if (options?.pagination?.limit)
|
|
757
|
+
params.set("limit", `${options.pagination.limit}`);
|
|
758
|
+
if (options?.sortBy) params.set("sort_by", options.sortBy);
|
|
759
|
+
if (options?.sortDir) params.set("sort_dir", options.sortDir);
|
|
760
|
+
if (options?.title) params.set("title", options.title);
|
|
761
|
+
if (options?.userFilter) params.set("user_id", options.userFilter);
|
|
762
|
+
if (options?.createdFrom) params.set("created_from", options.createdFrom);
|
|
763
|
+
if (options?.createdTo) params.set("created_to", options.createdTo);
|
|
764
|
+
if (options?.updatedFrom) params.set("updated_from", options.updatedFrom);
|
|
765
|
+
if (options?.updatedTo) params.set("updated_to", options.updatedTo);
|
|
766
|
+
const response = await client.get(
|
|
767
|
+
`/charts${params.toString() ? `?${params.toString()}` : ""}`,
|
|
768
|
+
tenantId,
|
|
769
|
+
options?.userId,
|
|
770
|
+
options?.scopes,
|
|
771
|
+
signal
|
|
772
|
+
);
|
|
773
|
+
if (options?.includeData) {
|
|
774
|
+
response.data = await Promise.all(
|
|
775
|
+
response.data.map(async (chart) => ({
|
|
776
|
+
...chart,
|
|
777
|
+
vega_lite_spec: {
|
|
778
|
+
...chart.vega_lite_spec,
|
|
779
|
+
data: {
|
|
780
|
+
values: await queryEngine.execute(
|
|
781
|
+
chart.sql,
|
|
782
|
+
chart.sql_params ?? void 0,
|
|
783
|
+
chart.target_db ?? void 0
|
|
784
|
+
)
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}))
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
return response;
|
|
791
|
+
}
|
|
792
|
+
async function getChart(client, queryEngine, id, options, signal) {
|
|
793
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
794
|
+
const chart = await client.get(
|
|
795
|
+
`/charts/${encodeURIComponent(id)}`,
|
|
796
|
+
tenantId,
|
|
797
|
+
options?.userId,
|
|
798
|
+
options?.scopes,
|
|
799
|
+
signal
|
|
800
|
+
);
|
|
801
|
+
return {
|
|
802
|
+
...chart,
|
|
803
|
+
vega_lite_spec: {
|
|
804
|
+
...chart.vega_lite_spec,
|
|
805
|
+
data: {
|
|
806
|
+
values: await queryEngine.execute(
|
|
807
|
+
chart.sql,
|
|
808
|
+
chart.sql_params ?? void 0,
|
|
809
|
+
chart.target_db ?? void 0
|
|
810
|
+
)
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
async function updateChart(client, id, body, options, signal) {
|
|
816
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
817
|
+
return await client.put(
|
|
818
|
+
`/charts/${encodeURIComponent(id)}`,
|
|
819
|
+
body,
|
|
820
|
+
tenantId,
|
|
821
|
+
options?.userId,
|
|
822
|
+
options?.scopes,
|
|
823
|
+
signal
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
async function deleteChart(client, id, options, signal) {
|
|
827
|
+
const tenantId = resolveTenantId(client, options?.tenantId);
|
|
828
|
+
await client.delete(
|
|
829
|
+
`/charts/${encodeURIComponent(id)}`,
|
|
830
|
+
tenantId,
|
|
831
|
+
options?.userId,
|
|
832
|
+
options?.scopes,
|
|
833
|
+
signal
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
function resolveTenantId(client, tenantId) {
|
|
837
|
+
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
838
|
+
if (!resolved) {
|
|
839
|
+
throw new Error(
|
|
840
|
+
"tenantId is required. Provide it per request or via defaultTenantId option."
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
return resolved;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// src/routes/active-charts.ts
|
|
847
|
+
async function createActiveChart(client, body, options, signal) {
|
|
848
|
+
const tenantId = resolveTenantId2(client, options?.tenantId);
|
|
849
|
+
return await client.post(
|
|
850
|
+
"/active-charts",
|
|
851
|
+
body,
|
|
852
|
+
tenantId,
|
|
853
|
+
options?.userId,
|
|
854
|
+
options?.scopes,
|
|
855
|
+
signal
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
async function listActiveCharts(client, queryEngine, options, signal) {
|
|
859
|
+
const tenantId = resolveTenantId2(client, options?.tenantId);
|
|
860
|
+
const params = new URLSearchParams();
|
|
861
|
+
if (options?.pagination?.page)
|
|
862
|
+
params.set("page", `${options.pagination.page}`);
|
|
863
|
+
if (options?.pagination?.limit)
|
|
864
|
+
params.set("limit", `${options.pagination.limit}`);
|
|
865
|
+
if (options?.sortBy) params.set("sort_by", options.sortBy);
|
|
866
|
+
if (options?.sortDir) params.set("sort_dir", options.sortDir);
|
|
867
|
+
if (options?.title) params.set("name", options.title);
|
|
868
|
+
if (options?.userFilter) params.set("user_id", options.userFilter);
|
|
869
|
+
if (options?.createdFrom) params.set("created_from", options.createdFrom);
|
|
870
|
+
if (options?.createdTo) params.set("created_to", options.createdTo);
|
|
871
|
+
if (options?.updatedFrom) params.set("updated_from", options.updatedFrom);
|
|
872
|
+
if (options?.updatedTo) params.set("updated_to", options.updatedTo);
|
|
873
|
+
const response = await client.get(
|
|
874
|
+
`/active-charts${params.toString() ? `?${params.toString()}` : ""}`,
|
|
875
|
+
tenantId,
|
|
876
|
+
options?.userId,
|
|
877
|
+
options?.scopes,
|
|
878
|
+
signal
|
|
879
|
+
);
|
|
880
|
+
if (options?.withData) {
|
|
881
|
+
response.data = await Promise.all(
|
|
882
|
+
response.data.map(async (active) => ({
|
|
883
|
+
...active,
|
|
884
|
+
chart: active.chart ? await getChart(
|
|
885
|
+
client,
|
|
886
|
+
queryEngine,
|
|
887
|
+
active.chart_id,
|
|
888
|
+
options,
|
|
889
|
+
signal
|
|
890
|
+
) : null
|
|
891
|
+
}))
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
return response;
|
|
895
|
+
}
|
|
896
|
+
async function getActiveChart(client, queryEngine, id, options, signal) {
|
|
897
|
+
const tenantId = resolveTenantId2(client, options?.tenantId);
|
|
898
|
+
const active = await client.get(
|
|
899
|
+
`/active-charts/${encodeURIComponent(id)}`,
|
|
900
|
+
tenantId,
|
|
901
|
+
options?.userId,
|
|
902
|
+
options?.scopes,
|
|
903
|
+
signal
|
|
904
|
+
);
|
|
905
|
+
if (options?.withData && active.chart_id) {
|
|
906
|
+
return {
|
|
907
|
+
...active,
|
|
908
|
+
chart: await getChart(
|
|
909
|
+
client,
|
|
910
|
+
queryEngine,
|
|
911
|
+
active.chart_id,
|
|
912
|
+
options,
|
|
913
|
+
signal
|
|
914
|
+
)
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return active;
|
|
918
|
+
}
|
|
919
|
+
async function updateActiveChart(client, id, body, options, signal) {
|
|
920
|
+
const tenantId = resolveTenantId2(client, options?.tenantId);
|
|
921
|
+
return await client.put(
|
|
922
|
+
`/active-charts/${encodeURIComponent(id)}`,
|
|
923
|
+
body,
|
|
924
|
+
tenantId,
|
|
925
|
+
options?.userId,
|
|
926
|
+
options?.scopes,
|
|
927
|
+
signal
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
async function deleteActiveChart(client, id, options, signal) {
|
|
931
|
+
const tenantId = resolveTenantId2(client, options?.tenantId);
|
|
932
|
+
await client.delete(
|
|
933
|
+
`/active-charts/${encodeURIComponent(id)}`,
|
|
934
|
+
tenantId,
|
|
935
|
+
options?.userId,
|
|
936
|
+
options?.scopes,
|
|
937
|
+
signal
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
function resolveTenantId2(client, tenantId) {
|
|
941
|
+
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
942
|
+
if (!resolved) {
|
|
943
|
+
throw new Error(
|
|
944
|
+
"tenantId is required. Provide it per request or via defaultTenantId option."
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
return resolved;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/routes/ingest.ts
|
|
951
|
+
import { randomUUID } from "crypto";
|
|
952
|
+
async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
953
|
+
const tenantId = resolveTenantId3(client, options.tenantId);
|
|
954
|
+
const adapter = queryEngine.getDatabase(databaseName);
|
|
955
|
+
const introspection = await adapter.introspect(
|
|
956
|
+
options.tables ? { tables: options.tables } : void 0
|
|
957
|
+
);
|
|
958
|
+
const payload = buildSchemaRequest(databaseName, adapter, introspection);
|
|
959
|
+
const sessionId = randomUUID();
|
|
960
|
+
const response = await client.post(
|
|
961
|
+
"/ingest",
|
|
962
|
+
payload,
|
|
963
|
+
tenantId,
|
|
964
|
+
options.userId,
|
|
965
|
+
options.scopes,
|
|
966
|
+
signal,
|
|
967
|
+
sessionId
|
|
968
|
+
);
|
|
969
|
+
return response;
|
|
970
|
+
}
|
|
971
|
+
function resolveTenantId3(client, tenantId) {
|
|
972
|
+
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
973
|
+
if (!resolved) {
|
|
974
|
+
throw new Error(
|
|
975
|
+
"tenantId is required. Provide it per request or via defaultTenantId option."
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
return resolved;
|
|
979
|
+
}
|
|
980
|
+
function buildSchemaRequest(databaseName, adapter, introspection) {
|
|
981
|
+
const dialect = adapter.getDialect();
|
|
982
|
+
const tables = introspection.tables.map((table) => ({
|
|
983
|
+
table_name: table.name,
|
|
984
|
+
description: table.comment ?? `Table ${table.name}`,
|
|
985
|
+
columns: table.columns.map((column) => ({
|
|
986
|
+
name: column.name,
|
|
987
|
+
data_type: column.rawType ?? column.type,
|
|
988
|
+
is_primary_key: Boolean(column.isPrimaryKey),
|
|
989
|
+
description: column.comment ?? ""
|
|
990
|
+
}))
|
|
991
|
+
}));
|
|
992
|
+
return {
|
|
993
|
+
database: databaseName,
|
|
994
|
+
dialect,
|
|
995
|
+
tables
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// src/routes/query.ts
|
|
1000
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1001
|
+
async function ask(client, queryEngine, question, options, signal) {
|
|
1002
|
+
const tenantId = resolveTenantId4(client, options.tenantId);
|
|
1003
|
+
const sessionId = randomUUID2();
|
|
1004
|
+
const maxRetry = options.maxRetry ?? 0;
|
|
1005
|
+
let attempt = 0;
|
|
1006
|
+
let lastError = options.lastError;
|
|
1007
|
+
let previousSql = options.previousSql;
|
|
1008
|
+
while (attempt <= maxRetry) {
|
|
1009
|
+
console.log({ lastError, previousSql });
|
|
1010
|
+
const queryResponse = await client.post(
|
|
1011
|
+
"/query",
|
|
1012
|
+
{
|
|
1013
|
+
question,
|
|
1014
|
+
...lastError ? { last_error: lastError } : {},
|
|
1015
|
+
...previousSql ? { previous_sql: previousSql } : {},
|
|
1016
|
+
...options.maxRetry ? { max_retry: options.maxRetry } : {}
|
|
1017
|
+
},
|
|
1018
|
+
tenantId,
|
|
1019
|
+
options.userId,
|
|
1020
|
+
options.scopes,
|
|
1021
|
+
signal,
|
|
1022
|
+
sessionId
|
|
1023
|
+
);
|
|
1024
|
+
const databaseName = queryResponse.database ?? options.database ?? queryEngine.getDefaultDatabase();
|
|
1025
|
+
if (!databaseName) {
|
|
1026
|
+
throw new Error(
|
|
1027
|
+
"No database attached. Call attachPostgres/attachClickhouse first."
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
const paramMetadata = Array.isArray(queryResponse.params) ? queryResponse.params : [];
|
|
1031
|
+
const paramValues = queryEngine.mapGeneratedParams(paramMetadata);
|
|
1032
|
+
try {
|
|
1033
|
+
const execution = await queryEngine.validateAndExecute(
|
|
1034
|
+
queryResponse.sql,
|
|
1035
|
+
paramValues,
|
|
1036
|
+
databaseName,
|
|
1037
|
+
tenantId
|
|
1038
|
+
);
|
|
1039
|
+
const rows = execution.rows ?? [];
|
|
1040
|
+
let chart = {
|
|
1041
|
+
vegaLiteSpec: null,
|
|
1042
|
+
notes: rows.length === 0 ? "Query returned no rows." : null
|
|
1043
|
+
};
|
|
1044
|
+
if (rows.length > 0) {
|
|
1045
|
+
const chartResponse = await client.post(
|
|
1046
|
+
"/chart",
|
|
1047
|
+
{
|
|
1048
|
+
question,
|
|
1049
|
+
sql: queryResponse.sql,
|
|
1050
|
+
rationale: queryResponse.rationale,
|
|
1051
|
+
fields: execution.fields,
|
|
1052
|
+
rows: anonymizeResults(rows),
|
|
1053
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1054
|
+
query_id: queryResponse.queryId
|
|
1055
|
+
},
|
|
1056
|
+
tenantId,
|
|
1057
|
+
options.userId,
|
|
1058
|
+
options.scopes,
|
|
1059
|
+
signal,
|
|
1060
|
+
sessionId
|
|
1061
|
+
);
|
|
1062
|
+
chart = {
|
|
1063
|
+
vegaLiteSpec: chartResponse.chart ? {
|
|
1064
|
+
...chartResponse.chart,
|
|
1065
|
+
data: { values: rows }
|
|
1066
|
+
} : null,
|
|
1067
|
+
notes: chartResponse.notes
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
return {
|
|
1071
|
+
sql: queryResponse.sql,
|
|
1072
|
+
params: paramValues,
|
|
1073
|
+
paramMetadata,
|
|
1074
|
+
rationale: queryResponse.rationale,
|
|
1075
|
+
dialect: queryResponse.dialect,
|
|
1076
|
+
queryId: queryResponse.queryId,
|
|
1077
|
+
rows,
|
|
1078
|
+
fields: execution.fields,
|
|
1079
|
+
chart,
|
|
1080
|
+
context: queryResponse.context,
|
|
1081
|
+
attempts: attempt + 1
|
|
1082
|
+
};
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
attempt++;
|
|
1085
|
+
if (attempt > maxRetry) {
|
|
1086
|
+
throw error;
|
|
1087
|
+
}
|
|
1088
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
1089
|
+
previousSql = queryResponse.sql;
|
|
1090
|
+
console.warn(
|
|
1091
|
+
`SQL execution failed (attempt ${attempt}/${maxRetry + 1}): ${lastError}. Retrying...`
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
throw new Error("Unexpected error in ask retry loop");
|
|
1096
|
+
}
|
|
1097
|
+
function resolveTenantId4(client, tenantId) {
|
|
1098
|
+
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
1099
|
+
if (!resolved) {
|
|
1100
|
+
throw new Error(
|
|
1101
|
+
"tenantId is required. Provide it per request or via defaultTenantId option."
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
return resolved;
|
|
1105
|
+
}
|
|
1106
|
+
function anonymizeResults(rows) {
|
|
1107
|
+
if (!rows?.length) return [];
|
|
1108
|
+
return rows.map((row) => {
|
|
1109
|
+
const masked = {};
|
|
1110
|
+
Object.entries(row).forEach(([key, value]) => {
|
|
1111
|
+
if (value === null) masked[key] = "null";
|
|
1112
|
+
else if (Array.isArray(value)) masked[key] = "array";
|
|
1113
|
+
else masked[key] = typeof value;
|
|
1114
|
+
});
|
|
1115
|
+
return masked;
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/index.ts
|
|
1120
|
+
var QueryPanelSdkAPI = class {
|
|
1121
|
+
client;
|
|
1122
|
+
queryEngine;
|
|
1123
|
+
constructor(baseUrl, privateKey, organizationId, options) {
|
|
1124
|
+
this.client = new ApiClient(baseUrl, privateKey, organizationId, options);
|
|
1125
|
+
this.queryEngine = new QueryEngine();
|
|
1126
|
+
}
|
|
1127
|
+
// Database attachment methods
|
|
1128
|
+
attachClickhouse(name, clientFn, options) {
|
|
1129
|
+
const adapter = new ClickHouseAdapter(clientFn, options);
|
|
1130
|
+
const metadata = {
|
|
1131
|
+
name,
|
|
1132
|
+
dialect: "clickhouse",
|
|
1133
|
+
description: options?.description,
|
|
1134
|
+
tags: options?.tags,
|
|
1135
|
+
tenantFieldName: options?.tenantFieldName,
|
|
1136
|
+
tenantFieldType: options?.tenantFieldType ?? "String",
|
|
1137
|
+
enforceTenantIsolation: options?.tenantFieldName ? options?.enforceTenantIsolation ?? true : void 0
|
|
1138
|
+
};
|
|
1139
|
+
this.queryEngine.attachDatabase(name, adapter, metadata);
|
|
1140
|
+
}
|
|
1141
|
+
attachPostgres(name, clientFn, options) {
|
|
1142
|
+
const adapter = new PostgresAdapter(clientFn, options);
|
|
1143
|
+
const metadata = {
|
|
1144
|
+
name,
|
|
1145
|
+
dialect: "postgres",
|
|
1146
|
+
description: options?.description,
|
|
1147
|
+
tags: options?.tags,
|
|
1148
|
+
tenantFieldName: options?.tenantFieldName,
|
|
1149
|
+
enforceTenantIsolation: options?.tenantFieldName ? options?.enforceTenantIsolation ?? true : void 0
|
|
1150
|
+
};
|
|
1151
|
+
this.queryEngine.attachDatabase(name, adapter, metadata);
|
|
1152
|
+
}
|
|
1153
|
+
attachDatabase(name, adapter) {
|
|
1154
|
+
const metadata = {
|
|
1155
|
+
name,
|
|
1156
|
+
dialect: adapter.getDialect()
|
|
1157
|
+
};
|
|
1158
|
+
this.queryEngine.attachDatabase(name, adapter, metadata);
|
|
1159
|
+
}
|
|
1160
|
+
// Schema introspection and sync
|
|
1161
|
+
async introspect(databaseName, tables) {
|
|
1162
|
+
const adapter = this.queryEngine.getDatabase(databaseName);
|
|
1163
|
+
return await adapter.introspect(tables ? { tables } : void 0);
|
|
1164
|
+
}
|
|
1165
|
+
async syncSchema(databaseName, options, signal) {
|
|
1166
|
+
return await syncSchema(
|
|
1167
|
+
this.client,
|
|
1168
|
+
this.queryEngine,
|
|
1169
|
+
databaseName,
|
|
1170
|
+
options,
|
|
1171
|
+
signal
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
// Natural language query
|
|
1175
|
+
async ask(question, options, signal) {
|
|
1176
|
+
return await ask(
|
|
1177
|
+
this.client,
|
|
1178
|
+
this.queryEngine,
|
|
1179
|
+
question,
|
|
1180
|
+
options,
|
|
1181
|
+
signal
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
// Chart CRUD operations
|
|
1185
|
+
async createChart(body, options, signal) {
|
|
1186
|
+
return await createChart(this.client, body, options, signal);
|
|
1187
|
+
}
|
|
1188
|
+
async listCharts(options, signal) {
|
|
1189
|
+
return await listCharts(
|
|
1190
|
+
this.client,
|
|
1191
|
+
this.queryEngine,
|
|
1192
|
+
options,
|
|
1193
|
+
signal
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
async getChart(id, options, signal) {
|
|
1197
|
+
return await getChart(
|
|
1198
|
+
this.client,
|
|
1199
|
+
this.queryEngine,
|
|
1200
|
+
id,
|
|
1201
|
+
options,
|
|
1202
|
+
signal
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
async updateChart(id, body, options, signal) {
|
|
1206
|
+
return await updateChart(
|
|
1207
|
+
this.client,
|
|
1208
|
+
id,
|
|
1209
|
+
body,
|
|
1210
|
+
options,
|
|
1211
|
+
signal
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
async deleteChart(id, options, signal) {
|
|
1215
|
+
await deleteChart(this.client, id, options, signal);
|
|
1216
|
+
}
|
|
1217
|
+
// Active Chart CRUD operations
|
|
1218
|
+
async createActiveChart(body, options, signal) {
|
|
1219
|
+
return await createActiveChart(
|
|
1220
|
+
this.client,
|
|
1221
|
+
body,
|
|
1222
|
+
options,
|
|
1223
|
+
signal
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
async listActiveCharts(options, signal) {
|
|
1227
|
+
return await listActiveCharts(
|
|
1228
|
+
this.client,
|
|
1229
|
+
this.queryEngine,
|
|
1230
|
+
options,
|
|
1231
|
+
signal
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
async getActiveChart(id, options, signal) {
|
|
1235
|
+
return await getActiveChart(
|
|
1236
|
+
this.client,
|
|
1237
|
+
this.queryEngine,
|
|
1238
|
+
id,
|
|
1239
|
+
options,
|
|
1240
|
+
signal
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
async updateActiveChart(id, body, options, signal) {
|
|
1244
|
+
return await updateActiveChart(
|
|
1245
|
+
this.client,
|
|
1246
|
+
id,
|
|
1247
|
+
body,
|
|
1248
|
+
options,
|
|
1249
|
+
signal
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
async deleteActiveChart(id, options, signal) {
|
|
1253
|
+
await deleteActiveChart(this.client, id, options, signal);
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
export {
|
|
1257
|
+
ClickHouseAdapter,
|
|
1258
|
+
PostgresAdapter,
|
|
1259
|
+
QueryPanelSdkAPI,
|
|
1260
|
+
anonymizeResults
|
|
1261
|
+
};
|
|
1262
|
+
//# sourceMappingURL=index.js.map
|