drizzle-cube 0.4.31 → 0.4.32
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/adapters/express/index.cjs +1 -1
- package/dist/adapters/express/index.d.ts +1 -1
- package/dist/adapters/express/index.js +3 -3
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.d.ts +1 -1
- package/dist/adapters/fastify/index.js +3 -3
- package/dist/adapters/{handler-GLMhjuwG.cjs → handler-ClgB__a-.cjs} +2 -2
- package/dist/adapters/{handler-BiVT5Sa4.js → handler-rPpxuopb.js} +2 -2
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.d.ts +1 -1
- package/dist/adapters/hono/index.js +3 -3
- package/dist/adapters/mcp-transport-DPpei63d.cjs +255 -0
- package/dist/adapters/{mcp-transport-Cs6gEFCi.js → mcp-transport-DWSNkwUY.js} +581 -261
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.d.ts +1 -1
- package/dist/adapters/nextjs/index.js +3 -3
- package/dist/adapters/{openai-C5Brybjm.cjs → openai-Bc8qwEKW.cjs} +1 -1
- package/dist/{server/openai-CucrxPHM.cjs → adapters/openai-C96O8M75.cjs} +1 -1
- package/dist/adapters/{openai-DPuFtYsB.js → openai-Ckpe7iU7.js} +1 -1
- package/dist/adapters/{openai-wU05wYGL.js → openai-DxeVtl8X.js} +1 -1
- package/dist/adapters/{utils-Dj1adfDc.js → utils-B7VkyzMv.js} +2 -1
- package/dist/adapters/{utils-cb6OWP7J.cjs → utils-BLFzzCI9.cjs} +1 -1
- package/dist/adapters/utils.cjs +1 -1
- package/dist/adapters/utils.d.ts +1 -1
- package/dist/adapters/utils.js +1 -1
- package/dist/server/index.cjs +42 -41
- package/dist/server/index.d.ts +43 -9
- package/dist/server/index.js +1452 -1131
- package/dist/server/{openai-DiyuZ3ds.cjs → openai-0HbLlZq6.cjs} +1 -1
- package/dist/{adapters/openai-D1zCEi6A.cjs → server/openai-DKpZPCay.cjs} +1 -1
- package/dist/server/{openai-owPdq1yN.js → openai-DnGeU9PT.js} +1 -1
- package/dist/server/{openai-nZJcAzON.js → openai-DqCEogm0.js} +1 -1
- package/package.json +11 -1
- package/dist/adapters/mcp-transport-nyTtswLM.cjs +0 -254
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as e, d as t, h as n, p as r, s as i } from "./utils-
|
|
1
|
+
import { c as e, d as t, h as n, p as r, s as i } from "./utils-B7VkyzMv.js";
|
|
2
2
|
import { a } from "./mcp-prompts-BAutSQYA.js";
|
|
3
3
|
//#region node_modules/drizzle-orm/entity.js
|
|
4
4
|
var o = Symbol.for("drizzle:entityKind");
|
|
@@ -196,7 +196,7 @@ var y = class extends l {
|
|
|
196
196
|
foreignKeyConfigs = [];
|
|
197
197
|
static [o] = "PgColumnBuilder";
|
|
198
198
|
array(e) {
|
|
199
|
-
return new
|
|
199
|
+
return new ee(this.config.name, this, e);
|
|
200
200
|
}
|
|
201
201
|
references(e, t = {}) {
|
|
202
202
|
return this.foreignKeyConfigs.push({
|
|
@@ -264,16 +264,16 @@ var y = class extends l {
|
|
|
264
264
|
op(e) {
|
|
265
265
|
return this.indexConfig.opClass = e, this;
|
|
266
266
|
}
|
|
267
|
-
},
|
|
267
|
+
}, ee = class extends y {
|
|
268
268
|
static [o] = "PgArrayBuilder";
|
|
269
269
|
constructor(e, t, n) {
|
|
270
270
|
super(e, "array", "PgArray"), this.config.baseBuilder = t, this.config.size = n;
|
|
271
271
|
}
|
|
272
272
|
build(e) {
|
|
273
273
|
let t = this.config.baseBuilder.build(e);
|
|
274
|
-
return new
|
|
274
|
+
return new S(e, this.config, t);
|
|
275
275
|
}
|
|
276
|
-
},
|
|
276
|
+
}, S = class e extends b {
|
|
277
277
|
constructor(e, t, n, r) {
|
|
278
278
|
super(e, t), this.baseColumn = n, this.range = r, this.size = t.size;
|
|
279
279
|
}
|
|
@@ -835,7 +835,8 @@ var U = class {
|
|
|
835
835
|
supportsFrameClause: !0,
|
|
836
836
|
supportsLateralJoins: !0,
|
|
837
837
|
supportsPercentileSubqueries: !0,
|
|
838
|
-
supportsDerivedTablesInCTE: !0
|
|
838
|
+
supportsDerivedTablesInCTE: !0,
|
|
839
|
+
supportsLateralSubqueriesInCTE: !0
|
|
839
840
|
};
|
|
840
841
|
}
|
|
841
842
|
buildStddev(e, t = !1) {
|
|
@@ -981,7 +982,8 @@ var U = class {
|
|
|
981
982
|
supportsFrameClause: !0,
|
|
982
983
|
supportsLateralJoins: !0,
|
|
983
984
|
supportsPercentileSubqueries: !1,
|
|
984
|
-
supportsDerivedTablesInCTE: !0
|
|
985
|
+
supportsDerivedTablesInCTE: !0,
|
|
986
|
+
supportsLateralSubqueriesInCTE: !0
|
|
985
987
|
};
|
|
986
988
|
}
|
|
987
989
|
buildStddev(e, t = !1) {
|
|
@@ -1134,7 +1136,8 @@ var U = class {
|
|
|
1134
1136
|
supportsFrameClause: !0,
|
|
1135
1137
|
supportsLateralJoins: !1,
|
|
1136
1138
|
supportsPercentileSubqueries: !1,
|
|
1137
|
-
supportsDerivedTablesInCTE: !0
|
|
1139
|
+
supportsDerivedTablesInCTE: !0,
|
|
1140
|
+
supportsLateralSubqueriesInCTE: !1
|
|
1138
1141
|
};
|
|
1139
1142
|
}
|
|
1140
1143
|
buildStddev(e, t = !1) {
|
|
@@ -1268,7 +1271,8 @@ var U = class {
|
|
|
1268
1271
|
supportsFrameClause: !0,
|
|
1269
1272
|
supportsLateralJoins: !1,
|
|
1270
1273
|
supportsPercentileSubqueries: !1,
|
|
1271
|
-
supportsDerivedTablesInCTE: !0
|
|
1274
|
+
supportsDerivedTablesInCTE: !0,
|
|
1275
|
+
supportsLateralSubqueriesInCTE: !1
|
|
1272
1276
|
};
|
|
1273
1277
|
}
|
|
1274
1278
|
buildStddev(e, t = !1) {
|
|
@@ -1401,7 +1405,8 @@ var U = class {
|
|
|
1401
1405
|
supportsFrameClause: !0,
|
|
1402
1406
|
supportsLateralJoins: !1,
|
|
1403
1407
|
supportsPercentileSubqueries: !1,
|
|
1404
|
-
supportsDerivedTablesInCTE: !1
|
|
1408
|
+
supportsDerivedTablesInCTE: !1,
|
|
1409
|
+
supportsLateralSubqueriesInCTE: !1
|
|
1405
1410
|
};
|
|
1406
1411
|
}
|
|
1407
1412
|
buildStddev(e, t = !1) {
|
|
@@ -1438,10 +1443,143 @@ var U = class {
|
|
|
1438
1443
|
default: throw Error(`Unsupported window function: ${e}`);
|
|
1439
1444
|
}
|
|
1440
1445
|
}
|
|
1446
|
+
}, Le = class extends U {
|
|
1447
|
+
getEngineType() {
|
|
1448
|
+
return "snowflake";
|
|
1449
|
+
}
|
|
1450
|
+
supportsLateralJoins() {
|
|
1451
|
+
return !0;
|
|
1452
|
+
}
|
|
1453
|
+
buildIntervalFromISO(e) {
|
|
1454
|
+
return F`${this.durationToSeconds(e)}`;
|
|
1455
|
+
}
|
|
1456
|
+
buildTimeDifferenceSeconds(e, t) {
|
|
1457
|
+
return F`DATEDIFF('SECOND', ${t}, ${e})`;
|
|
1458
|
+
}
|
|
1459
|
+
buildDateAddInterval(e, t) {
|
|
1460
|
+
let n = this.parseISODuration(t), r = e;
|
|
1461
|
+
return n.years && (r = F`DATEADD('YEAR', ${n.years}, ${r})`), n.months && (r = F`DATEADD('MONTH', ${n.months}, ${r})`), n.days && (r = F`DATEADD('DAY', ${n.days}, ${r})`), n.hours && (r = F`DATEADD('HOUR', ${n.hours}, ${r})`), n.minutes && (r = F`DATEADD('MINUTE', ${n.minutes}, ${r})`), n.seconds && (r = F`DATEADD('SECOND', ${n.seconds}, ${r})`), r;
|
|
1462
|
+
}
|
|
1463
|
+
buildConditionalAggregation(e, t, n) {
|
|
1464
|
+
let r = e.toUpperCase();
|
|
1465
|
+
return e === "count" && !t ? F`${F.raw(r)}(CASE WHEN ${n} THEN 1 END)` : F`${F.raw(r)}(CASE WHEN ${n} THEN ${t} END)`;
|
|
1466
|
+
}
|
|
1467
|
+
buildDateDiffPeriods(e, t, n) {
|
|
1468
|
+
let r = n.toUpperCase();
|
|
1469
|
+
return F`DATEDIFF('${F.raw(r)}', ${e}::TIMESTAMP, ${t}::TIMESTAMP)`;
|
|
1470
|
+
}
|
|
1471
|
+
buildPeriodSeriesSubquery(e) {
|
|
1472
|
+
return F`(SELECT ROW_NUMBER() OVER (ORDER BY 1) - 1 AS period_number FROM TABLE(GENERATOR(ROWCOUNT => ${e + 1}))) p`;
|
|
1473
|
+
}
|
|
1474
|
+
buildTimeDimension(e, t) {
|
|
1475
|
+
switch (e) {
|
|
1476
|
+
case "year": return F`DATE_TRUNC('YEAR', ${t}::TIMESTAMP)`;
|
|
1477
|
+
case "quarter": return F`DATE_TRUNC('QUARTER', ${t}::TIMESTAMP)`;
|
|
1478
|
+
case "month": return F`DATE_TRUNC('MONTH', ${t}::TIMESTAMP)`;
|
|
1479
|
+
case "week": return F`DATE_TRUNC('WEEK', ${t}::TIMESTAMP)`;
|
|
1480
|
+
case "day": return F`DATE_TRUNC('DAY', ${t}::TIMESTAMP)::TIMESTAMP`;
|
|
1481
|
+
case "hour": return F`DATE_TRUNC('HOUR', ${t}::TIMESTAMP)`;
|
|
1482
|
+
case "minute": return F`DATE_TRUNC('MINUTE', ${t}::TIMESTAMP)`;
|
|
1483
|
+
case "second": return F`DATE_TRUNC('SECOND', ${t}::TIMESTAMP)`;
|
|
1484
|
+
default: return t;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
buildStringCondition(e, t, n) {
|
|
1488
|
+
switch (t) {
|
|
1489
|
+
case "contains": return F`${e} ILIKE ${`%${n}%`}`;
|
|
1490
|
+
case "notContains": return F`${e} NOT ILIKE ${`%${n}%`}`;
|
|
1491
|
+
case "startsWith": return F`${e} ILIKE ${`${n}%`}`;
|
|
1492
|
+
case "endsWith": return F`${e} ILIKE ${`%${n}`}`;
|
|
1493
|
+
case "like": return F`${e} LIKE ${n}`;
|
|
1494
|
+
case "notLike": return F`${e} NOT LIKE ${n}`;
|
|
1495
|
+
case "ilike": return F`${e} ILIKE ${n}`;
|
|
1496
|
+
case "regex": return F`REGEXP_LIKE(${e}, ${n})`;
|
|
1497
|
+
case "notRegex": return F`NOT REGEXP_LIKE(${e}, ${n})`;
|
|
1498
|
+
default: throw Error(`Unsupported string operator: ${t}`);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
castToType(e, t) {
|
|
1502
|
+
switch (t) {
|
|
1503
|
+
case "timestamp": return F`${e}::TIMESTAMP`;
|
|
1504
|
+
case "decimal": return F`${e}::DECIMAL`;
|
|
1505
|
+
case "integer": return F`${e}::INTEGER`;
|
|
1506
|
+
default: throw Error(`Unsupported cast type: ${t}`);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
buildAvg(e) {
|
|
1510
|
+
return F`COALESCE(AVG(${e}), 0)`;
|
|
1511
|
+
}
|
|
1512
|
+
buildCaseWhen(e, t) {
|
|
1513
|
+
let n = e.map((e) => F`WHEN ${e.when} THEN ${e.then}`).reduce((e, t) => F`${e} ${t}`);
|
|
1514
|
+
return t === void 0 ? F`CASE ${n} END` : F`CASE ${n} ELSE ${t} END`;
|
|
1515
|
+
}
|
|
1516
|
+
buildBooleanLiteral(e) {
|
|
1517
|
+
return e ? F`TRUE` : F`FALSE`;
|
|
1518
|
+
}
|
|
1519
|
+
convertFilterValue(e) {
|
|
1520
|
+
return e;
|
|
1521
|
+
}
|
|
1522
|
+
prepareDateValue(e) {
|
|
1523
|
+
return e;
|
|
1524
|
+
}
|
|
1525
|
+
isTimestampInteger() {
|
|
1526
|
+
return !1;
|
|
1527
|
+
}
|
|
1528
|
+
convertTimeDimensionResult(e) {
|
|
1529
|
+
return e;
|
|
1530
|
+
}
|
|
1531
|
+
getCapabilities() {
|
|
1532
|
+
return {
|
|
1533
|
+
supportsStddev: !0,
|
|
1534
|
+
supportsVariance: !0,
|
|
1535
|
+
supportsPercentile: !0,
|
|
1536
|
+
supportsWindowFunctions: !0,
|
|
1537
|
+
supportsFrameClause: !0,
|
|
1538
|
+
supportsLateralJoins: !0,
|
|
1539
|
+
supportsPercentileSubqueries: !0,
|
|
1540
|
+
supportsDerivedTablesInCTE: !0,
|
|
1541
|
+
supportsLateralSubqueriesInCTE: !1
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
buildStddev(e, t = !1) {
|
|
1545
|
+
let n = t ? "STDDEV_SAMP" : "STDDEV_POP";
|
|
1546
|
+
return F`COALESCE(${F.raw(n)}(${e}), 0)`;
|
|
1547
|
+
}
|
|
1548
|
+
buildVariance(e, t = !1) {
|
|
1549
|
+
let n = t ? "VAR_SAMP" : "VAR_POP";
|
|
1550
|
+
return F`COALESCE(${F.raw(n)}(${e}), 0)`;
|
|
1551
|
+
}
|
|
1552
|
+
buildPercentile(e, t) {
|
|
1553
|
+
let n = (t / 100).toString();
|
|
1554
|
+
return F`PERCENTILE_CONT(${F.raw(n)}) WITHIN GROUP (ORDER BY ${e})`;
|
|
1555
|
+
}
|
|
1556
|
+
buildWindowFunction(e, t, n, r, i) {
|
|
1557
|
+
let a = n && n.length > 0 ? F`PARTITION BY ${F.join(n, F`, `)}` : F``, o = r && r.length > 0 ? F`ORDER BY ${F.join(r.map((e) => e.direction === "desc" ? F`${e.field} DESC` : F`${e.field} ASC`), F`, `)}` : F``, s = F``;
|
|
1558
|
+
if (i?.frame) {
|
|
1559
|
+
let { type: e, start: t, end: n } = i.frame, r = e.toUpperCase(), a = t === "unbounded" ? "UNBOUNDED PRECEDING" : typeof t == "number" ? `${t} PRECEDING` : "CURRENT ROW", o = n === "unbounded" ? "UNBOUNDED FOLLOWING" : n === "current" ? "CURRENT ROW" : typeof n == "number" ? `${n} FOLLOWING` : "CURRENT ROW";
|
|
1560
|
+
s = F`${F.raw(r)} BETWEEN ${F.raw(a)} AND ${F.raw(o)}`;
|
|
1561
|
+
}
|
|
1562
|
+
let c = [];
|
|
1563
|
+
n && n.length > 0 && c.push(a), r && r.length > 0 && c.push(o), i?.frame && c.push(s);
|
|
1564
|
+
let l = F`OVER (${c.length > 0 ? F.join(c, F` `) : F``})`;
|
|
1565
|
+
switch (e) {
|
|
1566
|
+
case "lag": return F`LAG(${t}, ${i?.offset ?? 1}${i?.defaultValue === void 0 ? F`` : F`, ${i.defaultValue}`}) ${l}`;
|
|
1567
|
+
case "lead": return F`LEAD(${t}, ${i?.offset ?? 1}${i?.defaultValue === void 0 ? F`` : F`, ${i.defaultValue}`}) ${l}`;
|
|
1568
|
+
case "rank": return F`RANK() ${l}`;
|
|
1569
|
+
case "denseRank": return F`DENSE_RANK() ${l}`;
|
|
1570
|
+
case "rowNumber": return F`ROW_NUMBER() ${l}`;
|
|
1571
|
+
case "ntile": return F`NTILE(${i?.nTile ?? 4}) ${l}`;
|
|
1572
|
+
case "firstValue": return F`FIRST_VALUE(${t}) ${l}`;
|
|
1573
|
+
case "lastValue": return F`LAST_VALUE(${t}) ${l}`;
|
|
1574
|
+
case "movingAvg": return F`AVG(${t}) ${l}`;
|
|
1575
|
+
case "movingSum": return F`SUM(${t}) ${l}`;
|
|
1576
|
+
default: throw Error(`Unsupported window function: ${e}`);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1441
1579
|
};
|
|
1442
1580
|
//#endregion
|
|
1443
1581
|
//#region src/server/database-utils.ts
|
|
1444
|
-
function
|
|
1582
|
+
function Re(e) {
|
|
1445
1583
|
switch (e) {
|
|
1446
1584
|
case "postgres": return new je();
|
|
1447
1585
|
case "mysql": return new Me();
|
|
@@ -1449,6 +1587,7 @@ function Le(e) {
|
|
|
1449
1587
|
case "singlestore": return new Pe();
|
|
1450
1588
|
case "duckdb": return new Fe();
|
|
1451
1589
|
case "databend": return new Ie();
|
|
1590
|
+
case "snowflake": return new Le();
|
|
1452
1591
|
default: throw Error(`Unsupported database engine: ${e}`);
|
|
1453
1592
|
}
|
|
1454
1593
|
}
|
|
@@ -1457,12 +1596,12 @@ function Le(e) {
|
|
|
1457
1596
|
var W = class {
|
|
1458
1597
|
databaseAdapter;
|
|
1459
1598
|
constructor(e, t, n) {
|
|
1460
|
-
this.db = e, this.schema = t, this.databaseAdapter =
|
|
1599
|
+
this.db = e, this.schema = t, this.databaseAdapter = Re(n || this.getEngineType());
|
|
1461
1600
|
}
|
|
1462
1601
|
};
|
|
1463
1602
|
//#endregion
|
|
1464
1603
|
//#region src/server/explain/postgres-parser.ts
|
|
1465
|
-
function
|
|
1604
|
+
function ze(e, t) {
|
|
1466
1605
|
let n = [], r = [], i = !1, a, o, s, c = [];
|
|
1467
1606
|
for (let t of e) {
|
|
1468
1607
|
let e = t.match(/Planning Time:\s*([\d.]+)\s*ms/i);
|
|
@@ -1475,7 +1614,7 @@ function Re(e, t) {
|
|
|
1475
1614
|
o = parseFloat(l[1]);
|
|
1476
1615
|
continue;
|
|
1477
1616
|
}
|
|
1478
|
-
let u =
|
|
1617
|
+
let u = Be(t);
|
|
1479
1618
|
if (u) {
|
|
1480
1619
|
u.type.includes("Seq Scan") && (i = !0), u.index && r.push(u.index), n.length === 0 && u.estimatedCost !== void 0 && (s = u.estimatedCost);
|
|
1481
1620
|
let e = t.search(/\S/);
|
|
@@ -1505,7 +1644,7 @@ function Re(e, t) {
|
|
|
1505
1644
|
sql: t
|
|
1506
1645
|
};
|
|
1507
1646
|
}
|
|
1508
|
-
function
|
|
1647
|
+
function Be(e) {
|
|
1509
1648
|
let t = e.replace(/^[\s->]+/, "").trim();
|
|
1510
1649
|
if (!t) return null;
|
|
1511
1650
|
let n = t.match(/^([A-Za-z][A-Za-z0-9 ]+?)(?:\s+using\s+(\S+))?(?:\s+on\s+(\S+))?(?:\s+\w+)?(?:\s+\(cost=([\d.]+)\.\.([\d.]+)\s+rows=(\d+)(?:\s+width=\d+)?\))?(?:\s+\(actual time=([\d.]+)\.\.([\d.]+)\s+rows=(\d+)\s+loops=(\d+)\))?/i);
|
|
@@ -1523,7 +1662,7 @@ function ze(e) {
|
|
|
1523
1662
|
}
|
|
1524
1663
|
//#endregion
|
|
1525
1664
|
//#region src/server/executors/postgres-executor.ts
|
|
1526
|
-
var
|
|
1665
|
+
var Ve = class extends W {
|
|
1527
1666
|
async execute(e, t) {
|
|
1528
1667
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1529
1668
|
let n = await e.execute();
|
|
@@ -1575,7 +1714,7 @@ var Be = class extends W {
|
|
|
1575
1714
|
typeof t == "string" && a.push(t);
|
|
1576
1715
|
}
|
|
1577
1716
|
}
|
|
1578
|
-
return
|
|
1717
|
+
return ze(a, {
|
|
1579
1718
|
sql: e,
|
|
1580
1719
|
params: t
|
|
1581
1720
|
});
|
|
@@ -1614,12 +1753,12 @@ var Be = class extends W {
|
|
|
1614
1753
|
}
|
|
1615
1754
|
}
|
|
1616
1755
|
};
|
|
1617
|
-
function
|
|
1618
|
-
return new
|
|
1756
|
+
function He(e, t) {
|
|
1757
|
+
return new Ve(e, t, "postgres");
|
|
1619
1758
|
}
|
|
1620
1759
|
//#endregion
|
|
1621
1760
|
//#region src/server/explain/mysql-parser.ts
|
|
1622
|
-
function
|
|
1761
|
+
function Ue(e, t) {
|
|
1623
1762
|
let n = t?.toLowerCase() || "";
|
|
1624
1763
|
switch (e.toLowerCase()) {
|
|
1625
1764
|
case "all": return "Seq Scan";
|
|
@@ -1633,10 +1772,10 @@ function He(e, t) {
|
|
|
1633
1772
|
default: return `MySQL ${e}`;
|
|
1634
1773
|
}
|
|
1635
1774
|
}
|
|
1636
|
-
function
|
|
1775
|
+
function We(e, t) {
|
|
1637
1776
|
let n = [], r = [], i = !1, a = 0;
|
|
1638
1777
|
for (let t of e) {
|
|
1639
|
-
let e =
|
|
1778
|
+
let e = Ue(t.type, t.Extra);
|
|
1640
1779
|
t.type.toLowerCase() === "all" && (i = !0), t.key && r.push(t.key);
|
|
1641
1780
|
let o = {
|
|
1642
1781
|
type: e,
|
|
@@ -1667,7 +1806,7 @@ function Ue(e, t) {
|
|
|
1667
1806
|
}
|
|
1668
1807
|
//#endregion
|
|
1669
1808
|
//#region src/server/executors/mysql-executor.ts
|
|
1670
|
-
var
|
|
1809
|
+
var Ge = class extends W {
|
|
1671
1810
|
async execute(e, t) {
|
|
1672
1811
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1673
1812
|
let n = await e.execute();
|
|
@@ -1717,7 +1856,7 @@ var We = class extends W {
|
|
|
1717
1856
|
filtered: Number(e.filtered) || 100,
|
|
1718
1857
|
Extra: e.Extra || null
|
|
1719
1858
|
});
|
|
1720
|
-
return
|
|
1859
|
+
return We(s, {
|
|
1721
1860
|
sql: e,
|
|
1722
1861
|
params: t
|
|
1723
1862
|
});
|
|
@@ -1751,12 +1890,12 @@ var We = class extends W {
|
|
|
1751
1890
|
}
|
|
1752
1891
|
}
|
|
1753
1892
|
};
|
|
1754
|
-
function
|
|
1755
|
-
return new
|
|
1893
|
+
function Ke(e, t) {
|
|
1894
|
+
return new Ge(e, t, "mysql");
|
|
1756
1895
|
}
|
|
1757
1896
|
//#endregion
|
|
1758
1897
|
//#region src/server/explain/sqlite-parser.ts
|
|
1759
|
-
function
|
|
1898
|
+
function qe(e) {
|
|
1760
1899
|
let t = e.toLowerCase(), n = e.match(/^SCAN\s+(\S+)/i);
|
|
1761
1900
|
if (n) return {
|
|
1762
1901
|
type: "Seq Scan",
|
|
@@ -1781,10 +1920,10 @@ function Ke(e) {
|
|
|
1781
1920
|
table: a[1]
|
|
1782
1921
|
} : t.includes("temp b-tree") ? t.includes("order by") ? { type: "Sort" } : t.includes("group by") ? { type: "Group" } : t.includes("distinct") ? { type: "Distinct" } : { type: "Temp B-Tree" } : t.includes("compound") ? { type: "Compound Query" } : t.includes("subquery") ? { type: "Subquery" } : t.includes("co-routine") ? { type: "Coroutine" } : { type: e };
|
|
1783
1922
|
}
|
|
1784
|
-
function
|
|
1923
|
+
function Je(e, t) {
|
|
1785
1924
|
let n = [], r = [], i = !1, a = /* @__PURE__ */ new Map();
|
|
1786
1925
|
for (let t of e) {
|
|
1787
|
-
let e =
|
|
1926
|
+
let e = qe(t.detail);
|
|
1788
1927
|
e.type === "Seq Scan" && (i = !0), e.index && r.push(e.index);
|
|
1789
1928
|
let o = {
|
|
1790
1929
|
type: e.type,
|
|
@@ -1815,7 +1954,7 @@ function qe(e, t) {
|
|
|
1815
1954
|
}
|
|
1816
1955
|
//#endregion
|
|
1817
1956
|
//#region src/server/executors/sqlite-executor.ts
|
|
1818
|
-
var
|
|
1957
|
+
var Ye = class extends W {
|
|
1819
1958
|
async execute(e, t) {
|
|
1820
1959
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1821
1960
|
let n = await e.execute();
|
|
@@ -1864,7 +2003,7 @@ var Je = class extends W {
|
|
|
1864
2003
|
notused: Number(e.notused) || 0,
|
|
1865
2004
|
detail: String(e.detail || "")
|
|
1866
2005
|
});
|
|
1867
|
-
return
|
|
2006
|
+
return Je(s, {
|
|
1868
2007
|
sql: e,
|
|
1869
2008
|
params: t
|
|
1870
2009
|
});
|
|
@@ -1897,29 +2036,29 @@ var Je = class extends W {
|
|
|
1897
2036
|
}
|
|
1898
2037
|
}
|
|
1899
2038
|
};
|
|
1900
|
-
function
|
|
1901
|
-
return new
|
|
2039
|
+
function Xe(e, t) {
|
|
2040
|
+
return new Ye(e, t, "sqlite");
|
|
1902
2041
|
}
|
|
1903
2042
|
//#endregion
|
|
1904
2043
|
//#region src/server/executors/singlestore-executor.ts
|
|
1905
|
-
var
|
|
2044
|
+
var Ze = class extends Ge {
|
|
1906
2045
|
getEngineType() {
|
|
1907
2046
|
return "singlestore";
|
|
1908
2047
|
}
|
|
1909
2048
|
};
|
|
1910
|
-
function
|
|
1911
|
-
return new
|
|
2049
|
+
function Qe(e, t) {
|
|
2050
|
+
return new Ze(e, t);
|
|
1912
2051
|
}
|
|
1913
2052
|
//#endregion
|
|
1914
2053
|
//#region src/server/explain/duckdb-parser.ts
|
|
1915
|
-
function
|
|
2054
|
+
function $e(e, t) {
|
|
1916
2055
|
let n = [], r = [], i = !1, a, o = [];
|
|
1917
2056
|
for (let t of e) {
|
|
1918
2057
|
if (/^[┌├└│─┐┤┘]+$/.test(t.trim()) || /EXPLANATION|QUERY PLAN/i.test(t)) continue;
|
|
1919
|
-
let e =
|
|
2058
|
+
let e = tt(t);
|
|
1920
2059
|
if (e) {
|
|
1921
2060
|
(e.type.includes("SEQ_SCAN") || e.type.includes("TABLE_SCAN")) && (i = !0), e.type.includes("INDEX_SCAN") && e.index && r.push(e.index), n.length === 0 && e.estimatedCost !== void 0 && (a = e.estimatedCost);
|
|
1922
|
-
let s =
|
|
2061
|
+
let s = et(t);
|
|
1923
2062
|
for (; o.length > 0 && o[o.length - 1].indent >= s;) o.pop();
|
|
1924
2063
|
if (o.length === 0) n.push(e);
|
|
1925
2064
|
else {
|
|
@@ -1946,13 +2085,13 @@ function Qe(e, t) {
|
|
|
1946
2085
|
sql: t
|
|
1947
2086
|
};
|
|
1948
2087
|
}
|
|
1949
|
-
function
|
|
2088
|
+
function et(e) {
|
|
1950
2089
|
let t = 0;
|
|
1951
2090
|
for (let n of e) if (n === " " || n === "│" || n === "├" || n === "└" || n === "─") t++;
|
|
1952
2091
|
else break;
|
|
1953
2092
|
return t;
|
|
1954
2093
|
}
|
|
1955
|
-
function
|
|
2094
|
+
function tt(e) {
|
|
1956
2095
|
let t = e.replace(/[┌├└│─┐┤┘]/g, "").replace(/^\s*/, "").trim();
|
|
1957
2096
|
if (!t || t.match(/^\(cost=([\d.]+)\s+rows=(\d+)\)$/i)) return null;
|
|
1958
2097
|
let n = t.match(/^([A-Z_]+)(?:\s+(\S+))?(?:\s+on\s+(\S+))?(?:\s+\(cost=([\d.]+)\s+rows=(\d+)\))?/i);
|
|
@@ -1978,7 +2117,7 @@ function et(e) {
|
|
|
1978
2117
|
}
|
|
1979
2118
|
//#endregion
|
|
1980
2119
|
//#region src/server/executors/duckdb-executor.ts
|
|
1981
|
-
var
|
|
2120
|
+
var nt = class extends W {
|
|
1982
2121
|
async execute(e, t) {
|
|
1983
2122
|
if (e && typeof e == "object" && typeof e.execute == "function") try {
|
|
1984
2123
|
let n = await e.execute();
|
|
@@ -2072,7 +2211,7 @@ var tt = class extends W {
|
|
|
2072
2211
|
typeof t == "string" && a.push(t);
|
|
2073
2212
|
}
|
|
2074
2213
|
}
|
|
2075
|
-
return
|
|
2214
|
+
return $e(a, {
|
|
2076
2215
|
sql: e,
|
|
2077
2216
|
params: t
|
|
2078
2217
|
});
|
|
@@ -2105,19 +2244,19 @@ var tt = class extends W {
|
|
|
2105
2244
|
}
|
|
2106
2245
|
}
|
|
2107
2246
|
};
|
|
2108
|
-
function
|
|
2109
|
-
return new
|
|
2247
|
+
function rt(e, t) {
|
|
2248
|
+
return new nt(e, t, "duckdb");
|
|
2110
2249
|
}
|
|
2111
2250
|
//#endregion
|
|
2112
2251
|
//#region src/server/explain/databend-parser.ts
|
|
2113
|
-
function
|
|
2252
|
+
function it(e, t) {
|
|
2114
2253
|
let n = [], r = [], i = !1, a, o = [];
|
|
2115
2254
|
for (let t of e) {
|
|
2116
2255
|
if (!t.trim()) continue;
|
|
2117
|
-
let e =
|
|
2256
|
+
let e = ot(t);
|
|
2118
2257
|
if (e) {
|
|
2119
2258
|
(e.type.includes("TableScan") || e.type.includes("SCAN")) && (i = !0), e.type.includes("IndexScan") && e.index && r.push(e.index), n.length === 0 && e.estimatedCost !== void 0 && (a = e.estimatedCost);
|
|
2120
|
-
let s =
|
|
2259
|
+
let s = at(t);
|
|
2121
2260
|
for (; o.length > 0 && o[o.length - 1].indent >= s;) o.pop();
|
|
2122
2261
|
if (o.length === 0) n.push(e);
|
|
2123
2262
|
else {
|
|
@@ -2144,13 +2283,13 @@ function rt(e, t) {
|
|
|
2144
2283
|
sql: t
|
|
2145
2284
|
};
|
|
2146
2285
|
}
|
|
2147
|
-
function
|
|
2286
|
+
function at(e) {
|
|
2148
2287
|
let t = 0;
|
|
2149
2288
|
for (let n of e) if (n === " " || n === "│" || n === "├" || n === "└" || n === "─") t++;
|
|
2150
2289
|
else break;
|
|
2151
2290
|
return t;
|
|
2152
2291
|
}
|
|
2153
|
-
function
|
|
2292
|
+
function ot(e) {
|
|
2154
2293
|
let t = e.replace(/[┌├└│─┐┤┘]/g, "").replace(/^\s*/, "").trim();
|
|
2155
2294
|
if (!t || /^(filters|table|estimated rows|output columns|push downs):/.test(t)) return null;
|
|
2156
2295
|
let n = t.match(/^([A-Z][A-Za-z_]+(?:\s+[A-Z][A-Za-z_]+)*)(?:\s+(\S+))?/);
|
|
@@ -2164,7 +2303,7 @@ function at(e) {
|
|
|
2164
2303
|
}
|
|
2165
2304
|
//#endregion
|
|
2166
2305
|
//#region src/server/executors/databend-executor.ts
|
|
2167
|
-
var
|
|
2306
|
+
var st = class extends W {
|
|
2168
2307
|
async execute(e, t) {
|
|
2169
2308
|
if (e && typeof e == "object" && typeof e.execute == "function") try {
|
|
2170
2309
|
let n = await e.execute();
|
|
@@ -2258,7 +2397,7 @@ var ot = class extends W {
|
|
|
2258
2397
|
typeof t == "string" && a.push(t);
|
|
2259
2398
|
}
|
|
2260
2399
|
}
|
|
2261
|
-
return
|
|
2400
|
+
return it(a, {
|
|
2262
2401
|
sql: e,
|
|
2263
2402
|
params: t
|
|
2264
2403
|
});
|
|
@@ -2267,22 +2406,184 @@ var ot = class extends W {
|
|
|
2267
2406
|
return !e || e.length, [];
|
|
2268
2407
|
}
|
|
2269
2408
|
};
|
|
2270
|
-
function
|
|
2271
|
-
return new
|
|
2409
|
+
function ct(e, t) {
|
|
2410
|
+
return new st(e, t, "databend");
|
|
2411
|
+
}
|
|
2412
|
+
//#endregion
|
|
2413
|
+
//#region src/server/explain/snowflake-parser.ts
|
|
2414
|
+
function lt(e, t) {
|
|
2415
|
+
let n = [], r = [], i = !1, a, o = [];
|
|
2416
|
+
for (let t of e) {
|
|
2417
|
+
if (!t.trim()) continue;
|
|
2418
|
+
let e = dt(t);
|
|
2419
|
+
if (e) {
|
|
2420
|
+
(e.type.includes("TableScan") || e.type.includes("SCAN")) && (i = !0), n.length === 0 && e.estimatedCost !== void 0 && (a = e.estimatedCost);
|
|
2421
|
+
let r = ut(t);
|
|
2422
|
+
for (; o.length > 0 && o[o.length - 1].indent >= r;) o.pop();
|
|
2423
|
+
if (o.length === 0) n.push(e);
|
|
2424
|
+
else {
|
|
2425
|
+
let t = o[o.length - 1].op;
|
|
2426
|
+
t.children ||= [], t.children.push(e);
|
|
2427
|
+
}
|
|
2428
|
+
o.push({
|
|
2429
|
+
indent: r,
|
|
2430
|
+
op: e
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
return {
|
|
2435
|
+
operations: n,
|
|
2436
|
+
summary: {
|
|
2437
|
+
database: "snowflake",
|
|
2438
|
+
planningTime: void 0,
|
|
2439
|
+
executionTime: void 0,
|
|
2440
|
+
totalCost: a,
|
|
2441
|
+
hasSequentialScans: i,
|
|
2442
|
+
usedIndexes: [...new Set(r)]
|
|
2443
|
+
},
|
|
2444
|
+
raw: e.join("\n"),
|
|
2445
|
+
sql: t
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
function ut(e) {
|
|
2449
|
+
let t = 0;
|
|
2450
|
+
for (let n of e) if (n === " " || n === "-" || n === ">") t++;
|
|
2451
|
+
else break;
|
|
2452
|
+
return t;
|
|
2453
|
+
}
|
|
2454
|
+
function dt(e) {
|
|
2455
|
+
let t = e.replace(/^[\s\d:]*->/, "").trim();
|
|
2456
|
+
if (!t || /^(GlobalStats|partitions|bytes):/i.test(t) || /^\w+=\d+/.test(t)) return null;
|
|
2457
|
+
let n = t.match(/^([A-Z][A-Za-z_]+(?:\s+[A-Z][A-Za-z_]+)*)(?:\s+(\S+))?/);
|
|
2458
|
+
if (!n) return null;
|
|
2459
|
+
let r = n[1], i = n[2] || void 0, a = t.match(/estimated rows:\s*(\d+)/i);
|
|
2460
|
+
return {
|
|
2461
|
+
type: r,
|
|
2462
|
+
table: i,
|
|
2463
|
+
estimatedRows: a ? parseInt(a[1], 10) : void 0
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
//#endregion
|
|
2467
|
+
//#region src/server/executors/snowflake-executor.ts
|
|
2468
|
+
var ft = class extends W {
|
|
2469
|
+
async execute(e, t) {
|
|
2470
|
+
if (e && typeof e == "object" && typeof e.execute == "function") try {
|
|
2471
|
+
let n = await e.execute();
|
|
2472
|
+
return Array.isArray(n) ? n.map((e) => this.convertNumericFields(e, t)) : n;
|
|
2473
|
+
} catch (t) {
|
|
2474
|
+
let n = this.extractSqlFromQuery(e);
|
|
2475
|
+
throw console.error("[Snowflake] Query execution failed:", {
|
|
2476
|
+
error: t instanceof Error ? t.message : String(t),
|
|
2477
|
+
sql: n.sql,
|
|
2478
|
+
params: n.params
|
|
2479
|
+
}), t;
|
|
2480
|
+
}
|
|
2481
|
+
if (!this.db.execute) throw Error("Snowflake database instance must have an execute method");
|
|
2482
|
+
try {
|
|
2483
|
+
let n = await this.db.execute(e);
|
|
2484
|
+
return Array.isArray(n) ? n.map((e) => this.convertNumericFields(e, t)) : n;
|
|
2485
|
+
} catch (t) {
|
|
2486
|
+
let n = this.extractSqlFromQuery(e);
|
|
2487
|
+
throw console.error("[Snowflake] Query execution failed:", {
|
|
2488
|
+
error: t instanceof Error ? t.message : String(t),
|
|
2489
|
+
sql: n.sql,
|
|
2490
|
+
params: n.params
|
|
2491
|
+
}), t;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
extractSqlFromQuery(e) {
|
|
2495
|
+
try {
|
|
2496
|
+
if (e && typeof e.toSQL == "function") {
|
|
2497
|
+
let { sql: t, params: n } = e.toSQL();
|
|
2498
|
+
return {
|
|
2499
|
+
sql: t,
|
|
2500
|
+
params: n
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
if (e && typeof e.getSQL == "function") {
|
|
2504
|
+
let t = e.getSQL();
|
|
2505
|
+
if (t && typeof t.toSQL == "function") {
|
|
2506
|
+
let { sql: e, params: n } = t.toSQL();
|
|
2507
|
+
return {
|
|
2508
|
+
sql: e,
|
|
2509
|
+
params: n
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
return {
|
|
2514
|
+
sql: String(e),
|
|
2515
|
+
params: []
|
|
2516
|
+
};
|
|
2517
|
+
} catch {
|
|
2518
|
+
return {
|
|
2519
|
+
sql: "[unable to extract SQL]",
|
|
2520
|
+
params: []
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
convertNumericFields(e, t) {
|
|
2525
|
+
if (!e || typeof e != "object") return e;
|
|
2526
|
+
let n = {};
|
|
2527
|
+
for (let [r, i] of Object.entries(e)) t && t.includes(r) ? n[r] = this.coerceToNumber(i) : n[r] = i;
|
|
2528
|
+
return n;
|
|
2529
|
+
}
|
|
2530
|
+
coerceToNumber(e) {
|
|
2531
|
+
if (e == null || typeof e == "number") return e;
|
|
2532
|
+
if (typeof e == "bigint") return Number(e);
|
|
2533
|
+
if (e && typeof e == "object") {
|
|
2534
|
+
if (typeof e.toString == "function") {
|
|
2535
|
+
let t = e.toString();
|
|
2536
|
+
if (/^-?\d+(\.\d+)?$/.test(t)) return t.includes(".") ? parseFloat(t) : parseInt(t, 10);
|
|
2537
|
+
}
|
|
2538
|
+
return e;
|
|
2539
|
+
}
|
|
2540
|
+
if (typeof e == "string") {
|
|
2541
|
+
if (/^-?\d+(\.\d+)?$/.test(e)) return e.includes(".") ? parseFloat(e) : parseInt(e, 10);
|
|
2542
|
+
if (!isNaN(parseFloat(e)) && isFinite(parseFloat(e))) return parseFloat(e);
|
|
2543
|
+
}
|
|
2544
|
+
return e;
|
|
2545
|
+
}
|
|
2546
|
+
getEngineType() {
|
|
2547
|
+
return "snowflake";
|
|
2548
|
+
}
|
|
2549
|
+
async explainQuery(e, t, n) {
|
|
2550
|
+
if (n?.analyze, !this.db.execute) throw Error("Snowflake database instance must have an execute method");
|
|
2551
|
+
let r = await this.db.execute(F`${F.raw("EXPLAIN")} ${F.raw(e.replace(/\?/g, () => {
|
|
2552
|
+
let e = t.shift();
|
|
2553
|
+
return e === null ? "NULL" : typeof e == "number" ? String(e) : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? `'${e.toISOString()}'` : `'${String(e).replace(/'/g, "''")}'`;
|
|
2554
|
+
}))}`), i = [];
|
|
2555
|
+
if (Array.isArray(r)) {
|
|
2556
|
+
for (let e of r) if (e && typeof e == "object") {
|
|
2557
|
+
let t = e.content || e["QUERY PLAN"] || e.plan || Object.values(e)[0];
|
|
2558
|
+
typeof t == "string" && i.push(t);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
return lt(i, {
|
|
2562
|
+
sql: e,
|
|
2563
|
+
params: t
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
async getTableIndexes(e) {
|
|
2567
|
+
return [];
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
function pt(e, t) {
|
|
2571
|
+
return new ft(e, t, "snowflake");
|
|
2272
2572
|
}
|
|
2273
2573
|
//#endregion
|
|
2274
2574
|
//#region src/server/executors/index.ts
|
|
2275
|
-
function
|
|
2575
|
+
function mt(e, t, n) {
|
|
2276
2576
|
if (n) switch (n) {
|
|
2277
|
-
case "postgres": return
|
|
2278
|
-
case "mysql": return
|
|
2279
|
-
case "sqlite": return
|
|
2280
|
-
case "singlestore": return
|
|
2281
|
-
case "duckdb": return
|
|
2282
|
-
case "databend": return
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
if (e.
|
|
2577
|
+
case "postgres": return He(e, t);
|
|
2578
|
+
case "mysql": return Ke(e, t);
|
|
2579
|
+
case "sqlite": return Xe(e, t);
|
|
2580
|
+
case "singlestore": return Qe(e, t);
|
|
2581
|
+
case "duckdb": return rt(e, t);
|
|
2582
|
+
case "databend": return ct(e, t);
|
|
2583
|
+
case "snowflake": return pt(e, t);
|
|
2584
|
+
}
|
|
2585
|
+
if (e.all && e.run) return Xe(e, t);
|
|
2586
|
+
if (e.execute) return He(e, t);
|
|
2286
2587
|
throw Error("Unable to determine database engine type. Please specify engineType parameter.");
|
|
2287
2588
|
}
|
|
2288
2589
|
//#endregion
|
|
@@ -2290,7 +2591,7 @@ function ct(e, t, n) {
|
|
|
2290
2591
|
function G(e, t) {
|
|
2291
2592
|
return typeof e == "string" ? t ? t.get(e) || (console.warn(`[drizzle-cube] Cannot resolve cube reference '${e}': no cube with that name is registered. Registered cubes: ${Array.from(t.keys()).join(", ") || "(none)"}. Join will be skipped.`), null) : (console.warn(`[drizzle-cube] Cannot resolve string cube reference '${e}': no cube registry provided. Join will be skipped.`), null) : typeof e == "function" ? e() : e;
|
|
2292
2593
|
}
|
|
2293
|
-
function
|
|
2594
|
+
function ht(e) {
|
|
2294
2595
|
switch (e) {
|
|
2295
2596
|
case "belongsTo": return "hasMany";
|
|
2296
2597
|
case "hasMany": return "belongsTo";
|
|
@@ -2299,7 +2600,7 @@ function lt(e) {
|
|
|
2299
2600
|
default: return e;
|
|
2300
2601
|
}
|
|
2301
2602
|
}
|
|
2302
|
-
function
|
|
2603
|
+
function gt(e, t) {
|
|
2303
2604
|
if (t) return t;
|
|
2304
2605
|
switch (e) {
|
|
2305
2606
|
case "belongsTo": return "inner";
|
|
@@ -2309,17 +2610,17 @@ function ut(e, t) {
|
|
|
2309
2610
|
default: return "left";
|
|
2310
2611
|
}
|
|
2311
2612
|
}
|
|
2312
|
-
function
|
|
2613
|
+
function _t(e) {
|
|
2313
2614
|
return e && typeof e == "object" ? F`${F`${e}`}` : e;
|
|
2314
2615
|
}
|
|
2315
|
-
function
|
|
2616
|
+
function vt(e) {
|
|
2316
2617
|
if (e === "__proto__" || e === "constructor" || e === "prototype") throw Error(`Unsafe property key: ${e}`);
|
|
2317
2618
|
return e;
|
|
2318
2619
|
}
|
|
2319
2620
|
function K(e, t) {
|
|
2320
|
-
return
|
|
2621
|
+
return _t(typeof e == "function" ? e(t) : e);
|
|
2321
2622
|
}
|
|
2322
|
-
function
|
|
2623
|
+
function yt(e, t) {
|
|
2323
2624
|
if (e.relationship !== "belongsToMany" || !e.through) throw Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
|
|
2324
2625
|
let { table: n, sourceKey: r, targetKey: i, securitySql: a } = e.through, o = [];
|
|
2325
2626
|
for (let e of r) {
|
|
@@ -2336,7 +2637,7 @@ function pt(e, t) {
|
|
|
2336
2637
|
let e = a(t);
|
|
2337
2638
|
c = Array.isArray(e) ? e : [e];
|
|
2338
2639
|
}
|
|
2339
|
-
let l =
|
|
2640
|
+
let l = gt("belongsToMany", e.sqlJoinType);
|
|
2340
2641
|
return {
|
|
2341
2642
|
junctionJoins: [{
|
|
2342
2643
|
joinType: l,
|
|
@@ -2352,13 +2653,13 @@ function pt(e, t) {
|
|
|
2352
2653
|
}
|
|
2353
2654
|
//#endregion
|
|
2354
2655
|
//#region src/server/filter-cache.ts
|
|
2355
|
-
function
|
|
2356
|
-
if ("and" in e) return `and:[${e.and.map(
|
|
2357
|
-
if ("or" in e) return `or:[${e.or.map(
|
|
2656
|
+
function bt(e) {
|
|
2657
|
+
if ("and" in e) return `and:[${e.and.map(bt).sort().join(",")}]`;
|
|
2658
|
+
if ("or" in e) return `or:[${e.or.map(bt).sort().join(",")}]`;
|
|
2358
2659
|
let t = e, n = JSON.stringify(Array.isArray(t.values) ? [...t.values].sort() : t.values), r = t.dateRange ? `:dr:${JSON.stringify(t.dateRange)}` : "";
|
|
2359
2660
|
return `${t.member}:${t.operator}:${n}${r}`;
|
|
2360
2661
|
}
|
|
2361
|
-
function
|
|
2662
|
+
function xt(e, t) {
|
|
2362
2663
|
return `timeDim:${e}:${JSON.stringify(t)}`;
|
|
2363
2664
|
}
|
|
2364
2665
|
var q = class {
|
|
@@ -2399,37 +2700,37 @@ var q = class {
|
|
|
2399
2700
|
};
|
|
2400
2701
|
}
|
|
2401
2702
|
};
|
|
2402
|
-
function
|
|
2703
|
+
function St(e) {
|
|
2403
2704
|
let t = [];
|
|
2404
|
-
for (let n of e) "and" in n && n.and ? t.push(...
|
|
2705
|
+
for (let n of e) "and" in n && n.and ? t.push(...St(n.and)) : "or" in n && n.or ? t.push(...St(n.or)) : "member" in n && t.push(n);
|
|
2405
2706
|
return t;
|
|
2406
2707
|
}
|
|
2407
2708
|
//#endregion
|
|
2408
2709
|
//#region src/server/cache-utils.ts
|
|
2409
|
-
function
|
|
2410
|
-
let r = n.keyPrefix ?? "drizzle-cube:", i =
|
|
2710
|
+
function Ct(e, t, n = {}) {
|
|
2711
|
+
let r = n.keyPrefix ?? "drizzle-cube:", i = wt(e), a = `${r}query:${At(JSON.stringify(i))}`;
|
|
2411
2712
|
if (n.includeSecurityContext !== !1) {
|
|
2412
|
-
let e =
|
|
2713
|
+
let e = At(n.securityContextSerializer ? n.securityContextSerializer(t) : JSON.stringify(kt(t)));
|
|
2413
2714
|
a += `:ctx:${e}`;
|
|
2414
2715
|
}
|
|
2415
2716
|
return a;
|
|
2416
2717
|
}
|
|
2417
|
-
function
|
|
2718
|
+
function wt(e) {
|
|
2418
2719
|
return {
|
|
2419
2720
|
measures: e.measures ? [...e.measures].sort() : void 0,
|
|
2420
2721
|
dimensions: e.dimensions ? [...e.dimensions].sort() : void 0,
|
|
2421
2722
|
filters: e.filters ? J(e.filters) : void 0,
|
|
2422
|
-
timeDimensions: e.timeDimensions ?
|
|
2723
|
+
timeDimensions: e.timeDimensions ? Ot(e.timeDimensions) : void 0,
|
|
2423
2724
|
limit: e.limit,
|
|
2424
2725
|
offset: e.offset,
|
|
2425
|
-
order: e.order ?
|
|
2726
|
+
order: e.order ? kt(e.order) : void 0,
|
|
2426
2727
|
fillMissingDatesValue: e.fillMissingDatesValue,
|
|
2427
|
-
funnel: e.funnel ?
|
|
2428
|
-
flow: e.flow ?
|
|
2429
|
-
retention: e.retention ?
|
|
2728
|
+
funnel: e.funnel ? Tt(e.funnel) : void 0,
|
|
2729
|
+
flow: e.flow ? Et(e.flow) : void 0,
|
|
2730
|
+
retention: e.retention ? Dt(e.retention) : void 0
|
|
2430
2731
|
};
|
|
2431
2732
|
}
|
|
2432
|
-
function
|
|
2733
|
+
function Tt(e) {
|
|
2433
2734
|
return {
|
|
2434
2735
|
bindingKey: e.bindingKey,
|
|
2435
2736
|
timeDimension: e.timeDimension,
|
|
@@ -2445,7 +2746,7 @@ function yt(e) {
|
|
|
2445
2746
|
globalTimeWindow: e.globalTimeWindow
|
|
2446
2747
|
};
|
|
2447
2748
|
}
|
|
2448
|
-
function
|
|
2749
|
+
function Et(e) {
|
|
2449
2750
|
return {
|
|
2450
2751
|
bindingKey: e.bindingKey,
|
|
2451
2752
|
timeDimension: e.timeDimension,
|
|
@@ -2461,7 +2762,7 @@ function bt(e) {
|
|
|
2461
2762
|
joinStrategy: e.joinStrategy
|
|
2462
2763
|
};
|
|
2463
2764
|
}
|
|
2464
|
-
function
|
|
2765
|
+
function Dt(e) {
|
|
2465
2766
|
return {
|
|
2466
2767
|
timeDimension: e.timeDimension,
|
|
2467
2768
|
bindingKey: e.bindingKey,
|
|
@@ -2485,7 +2786,7 @@ function J(e) {
|
|
|
2485
2786
|
};
|
|
2486
2787
|
}).sort((e, t) => JSON.stringify(e).localeCompare(JSON.stringify(t)));
|
|
2487
2788
|
}
|
|
2488
|
-
function
|
|
2789
|
+
function Ot(e) {
|
|
2489
2790
|
return [...e].map((e) => ({
|
|
2490
2791
|
dimension: e.dimension,
|
|
2491
2792
|
granularity: e.granularity,
|
|
@@ -2497,10 +2798,10 @@ function St(e) {
|
|
|
2497
2798
|
}) : void 0
|
|
2498
2799
|
})).sort((e, t) => e.dimension.localeCompare(t.dimension));
|
|
2499
2800
|
}
|
|
2500
|
-
function
|
|
2501
|
-
return typeof e != "object" || !e ? e : Array.isArray(e) ? e.map(
|
|
2801
|
+
function kt(e) {
|
|
2802
|
+
return typeof e != "object" || !e ? e : Array.isArray(e) ? e.map(kt) : Object.keys(e).sort().reduce((t, n) => (t[n] = kt(e[n]), t), {});
|
|
2502
2803
|
}
|
|
2503
|
-
function
|
|
2804
|
+
function At(e) {
|
|
2504
2805
|
let t = 2166136261, n = Math.min(e.length, 65536);
|
|
2505
2806
|
for (let r = 0; r < n; r++) t ^= e.charCodeAt(r), t = t * 16777619 >>> 0;
|
|
2506
2807
|
return t.toString(16).padStart(8, "0");
|
|
@@ -2674,7 +2975,7 @@ var Y = class {
|
|
|
2674
2975
|
let t = new Date(e);
|
|
2675
2976
|
return isNaN(t.getTime()) ? null : this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(t.getTime() / 1e3) : t.getTime() : t.toISOString();
|
|
2676
2977
|
}
|
|
2677
|
-
},
|
|
2978
|
+
}, jt = class {
|
|
2678
2979
|
constructor(e, t) {
|
|
2679
2980
|
this.databaseAdapter = e, this.dateTimeBuilder = t;
|
|
2680
2981
|
}
|
|
@@ -2887,8 +3188,8 @@ var Y = class {
|
|
|
2887
3188
|
};
|
|
2888
3189
|
//#endregion
|
|
2889
3190
|
//#region src/server/template-substitution.ts
|
|
2890
|
-
function
|
|
2891
|
-
let { cube: n, allCubes: r, resolvedMeasures: i } = t, a =
|
|
3191
|
+
function Mt(e, t) {
|
|
3192
|
+
let { cube: n, allCubes: r, resolvedMeasures: i } = t, a = Nt(e), o = /* @__PURE__ */ new Map();
|
|
2892
3193
|
for (let e of a) {
|
|
2893
3194
|
let { originalRef: t, cubeName: a, fieldName: s } = e, c = a || n.name;
|
|
2894
3195
|
if (!r.get(c)) throw Error(`Cannot substitute {${t}}: cube '${c}' not found`);
|
|
@@ -2911,7 +3212,7 @@ function Et(e, t) {
|
|
|
2911
3212
|
for (let e = 0; e < s.length; e++) s[e] && u.push(new M(s[e])), e < c.length && u.push(c[e]);
|
|
2912
3213
|
return F.join(u, F.raw(""));
|
|
2913
3214
|
}
|
|
2914
|
-
function
|
|
3215
|
+
function Nt(e) {
|
|
2915
3216
|
if (e.length > 1e3) return [];
|
|
2916
3217
|
let t = e.matchAll(/\{([^}]+)\}/g), n = [];
|
|
2917
3218
|
for (let e of t) {
|
|
@@ -2931,7 +3232,7 @@ function Dt(e) {
|
|
|
2931
3232
|
}
|
|
2932
3233
|
return n;
|
|
2933
3234
|
}
|
|
2934
|
-
function
|
|
3235
|
+
function Pt(e) {
|
|
2935
3236
|
let t = [], n = 0;
|
|
2936
3237
|
for (let r = 0; r < e.length; r++) if (e[r] === "{") n++;
|
|
2937
3238
|
else if (e[r] === "}" && (n--, n < 0)) {
|
|
@@ -2939,7 +3240,7 @@ function Ot(e) {
|
|
|
2939
3240
|
break;
|
|
2940
3241
|
}
|
|
2941
3242
|
n > 0 && t.push("Unmatched opening brace in template"), /\{\s*\}/.test(e) && t.push("Empty member reference {} found in template"), /\{[^}]*\{/.test(e) && t.push("Nested braces are not allowed in member references");
|
|
2942
|
-
let r =
|
|
3243
|
+
let r = Nt(e);
|
|
2943
3244
|
for (let e of r) {
|
|
2944
3245
|
let n = e.cubeName ? `${e.cubeName}.${e.fieldName}` : e.fieldName;
|
|
2945
3246
|
/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(n) || t.push(`Invalid member reference {${e.originalRef}}: must start with letter or underscore, and contain only letters, numbers, underscores, and dots`), n.split(".").length > 2 && t.push(`Invalid member reference {${e.originalRef}}: only one dot allowed (Cube.measure format)`);
|
|
@@ -2949,8 +3250,8 @@ function Ot(e) {
|
|
|
2949
3250
|
errors: t
|
|
2950
3251
|
};
|
|
2951
3252
|
}
|
|
2952
|
-
function
|
|
2953
|
-
let n =
|
|
3253
|
+
function Ft(e, t) {
|
|
3254
|
+
let n = Nt(e), r = /* @__PURE__ */ new Set();
|
|
2954
3255
|
for (let e of n) {
|
|
2955
3256
|
let n = `${e.cubeName || t}.${e.fieldName}`;
|
|
2956
3257
|
r.add(n);
|
|
@@ -2977,11 +3278,11 @@ var Z = class e {
|
|
|
2977
3278
|
n && c.add(n);
|
|
2978
3279
|
continue;
|
|
2979
3280
|
}
|
|
2980
|
-
X.isCalculatedMeasure(d) ? (s.push(r),
|
|
3281
|
+
X.isCalculatedMeasure(d) ? (s.push(r), Ft(d.calculatedSql, t).forEach((e) => c.add(e)), l.getAllDependencies(r).forEach((e) => {
|
|
2981
3282
|
let [t, r] = e.split("."), i = n.get(t);
|
|
2982
3283
|
if (i && i.measures[r]) {
|
|
2983
3284
|
let e = i.measures[r];
|
|
2984
|
-
X.isCalculatedMeasure(e) &&
|
|
3285
|
+
X.isCalculatedMeasure(e) && Ft(e.calculatedSql, t).forEach((e) => c.add(e));
|
|
2985
3286
|
}
|
|
2986
3287
|
})) : o.push(r);
|
|
2987
3288
|
}
|
|
@@ -3012,7 +3313,7 @@ var Z = class e {
|
|
|
3012
3313
|
}
|
|
3013
3314
|
buildCalculatedMeasure(e, t, n, r, i) {
|
|
3014
3315
|
if (!e.calculatedSql) throw Error(`Calculated measure '${t.name}.${e.name}' missing calculatedSql property`);
|
|
3015
|
-
return
|
|
3316
|
+
return Mt(this.databaseAdapter.preprocessCalculatedTemplate(e.calculatedSql), {
|
|
3016
3317
|
cube: t,
|
|
3017
3318
|
allCubes: n,
|
|
3018
3319
|
resolvedMeasures: r,
|
|
@@ -3021,7 +3322,7 @@ var Z = class e {
|
|
|
3021
3322
|
}
|
|
3022
3323
|
buildCTECalculatedMeasure(e, t, n, r, i) {
|
|
3023
3324
|
if (!e.calculatedSql) throw Error(`Calculated measure '${t.name}.${e.name || "unknown"}' missing calculatedSql property`);
|
|
3024
|
-
let a = /* @__PURE__ */ new Map(), o =
|
|
3325
|
+
let a = /* @__PURE__ */ new Map(), o = Ft(e.calculatedSql, t.name);
|
|
3025
3326
|
for (let e of o) {
|
|
3026
3327
|
let [t, i] = e.split("."), o = r.get(t);
|
|
3027
3328
|
if (o && o.measures[i]) {
|
|
@@ -3255,7 +3556,7 @@ var Z = class e {
|
|
|
3255
3556
|
let { postAggWindowMeasures: r } = e.categorizeForPostAggregation(t, n);
|
|
3256
3557
|
return r.length > 0;
|
|
3257
3558
|
}
|
|
3258
|
-
},
|
|
3559
|
+
}, It = class {
|
|
3259
3560
|
constructor(e) {
|
|
3260
3561
|
this.dateTimeBuilder = e;
|
|
3261
3562
|
}
|
|
@@ -3353,13 +3654,13 @@ var Z = class e {
|
|
|
3353
3654
|
}
|
|
3354
3655
|
return i;
|
|
3355
3656
|
}
|
|
3356
|
-
},
|
|
3657
|
+
}, Lt = class {
|
|
3357
3658
|
dateTimeBuilder;
|
|
3358
3659
|
filterBuilder;
|
|
3359
3660
|
groupByBuilder;
|
|
3360
3661
|
measureBuilder;
|
|
3361
3662
|
constructor(e) {
|
|
3362
|
-
this.dateTimeBuilder = new Y(e), this.filterBuilder = new
|
|
3663
|
+
this.dateTimeBuilder = new Y(e), this.filterBuilder = new jt(e, this.dateTimeBuilder), this.groupByBuilder = new It(this.dateTimeBuilder), this.measureBuilder = new Z(e);
|
|
3363
3664
|
}
|
|
3364
3665
|
buildResolvedMeasures(e, t, n, r) {
|
|
3365
3666
|
return this.measureBuilder.buildResolvedMeasures(e, t, n, r);
|
|
@@ -3423,7 +3724,7 @@ var Z = class e {
|
|
|
3423
3724
|
if (s && s.dimensions[i] && e.dateRange) {
|
|
3424
3725
|
if (r?.preAggregationCTEs && r.preAggregationCTEs.some((e) => e.cube.name === t)) continue;
|
|
3425
3726
|
if (n.filterCache) {
|
|
3426
|
-
let t =
|
|
3727
|
+
let t = xt(e.dimension, e.dateRange), r = n.filterCache.get(t);
|
|
3427
3728
|
if (r) {
|
|
3428
3729
|
a.push(r);
|
|
3429
3730
|
continue;
|
|
@@ -3463,7 +3764,7 @@ var Z = class e {
|
|
|
3463
3764
|
if (i?.preAggregationCTEs && i.preAggregationCTEs.some((e) => e.cube.name === o)) return null;
|
|
3464
3765
|
let t = l.type === "time";
|
|
3465
3766
|
if (n.filterCache) {
|
|
3466
|
-
let t =
|
|
3767
|
+
let t = bt(e), r = n.filterCache.get(t);
|
|
3467
3768
|
if (r) return r;
|
|
3468
3769
|
}
|
|
3469
3770
|
let r = t ? K(l.sql, n) : typeof l.sql == "function" ? l.sql(n) : l.sql;
|
|
@@ -3532,7 +3833,7 @@ var Z = class e {
|
|
|
3532
3833
|
buildLogicalFilter(e, t, n) {
|
|
3533
3834
|
return this.filterBuilder.buildLogicalFilter(e, t, n);
|
|
3534
3835
|
}
|
|
3535
|
-
},
|
|
3836
|
+
}, Rt = class {
|
|
3536
3837
|
cubes;
|
|
3537
3838
|
connectivityCache = /* @__PURE__ */ new Map();
|
|
3538
3839
|
reverseIndex;
|
|
@@ -3739,7 +4040,7 @@ var Z = class e {
|
|
|
3739
4040
|
buildJoinCondition(e, t, n) {
|
|
3740
4041
|
let r = [];
|
|
3741
4042
|
for (let i of e.on) {
|
|
3742
|
-
let e = t ? F`${F.identifier(t)}.${F.identifier(i.source.name)}` :
|
|
4043
|
+
let e = t ? F`${F.identifier(t)}.${F.identifier(i.source.name)}` : _t(i.source), a = n ? F`${F.identifier(n)}.${F.identifier(i.target.name)}` : _t(i.target), o = i.as || L;
|
|
3743
4044
|
r.push(o(e, a));
|
|
3744
4045
|
}
|
|
3745
4046
|
return R(...r);
|
|
@@ -3769,11 +4070,11 @@ var Z = class e {
|
|
|
3769
4070
|
setInCache(e, t) {
|
|
3770
4071
|
this.connectivityCache.set(e, { path: t });
|
|
3771
4072
|
}
|
|
3772
|
-
},
|
|
4073
|
+
}, zt = class {
|
|
3773
4074
|
resolverCache = /* @__PURE__ */ new WeakMap();
|
|
3774
4075
|
getResolver(e) {
|
|
3775
4076
|
let t = this.resolverCache.get(e);
|
|
3776
|
-
return t || (t = new
|
|
4077
|
+
return t || (t = new Rt(e), this.resolverCache.set(e, t)), t;
|
|
3777
4078
|
}
|
|
3778
4079
|
analyzeCubeUsage(e) {
|
|
3779
4080
|
let t = /* @__PURE__ */ new Set();
|
|
@@ -3862,9 +4163,9 @@ var Z = class e {
|
|
|
3862
4163
|
if (s.has(n)) continue;
|
|
3863
4164
|
let c = e.get(n);
|
|
3864
4165
|
if (!c) throw Error(`Cube '${n}' not found`);
|
|
3865
|
-
let u = l ?
|
|
4166
|
+
let u = l ? ht(i.relationship) : i.relationship;
|
|
3866
4167
|
if (u === "belongsToMany" && i.through) {
|
|
3867
|
-
let e =
|
|
4168
|
+
let e = yt(i, r.securityContext);
|
|
3868
4169
|
o.push({
|
|
3869
4170
|
cube: c,
|
|
3870
4171
|
alias: `${n.toLowerCase()}_cube`,
|
|
@@ -3881,7 +4182,7 @@ var Z = class e {
|
|
|
3881
4182
|
}
|
|
3882
4183
|
});
|
|
3883
4184
|
} else {
|
|
3884
|
-
let e = a.buildJoinCondition(i, null, null), t =
|
|
4185
|
+
let e = a.buildJoinCondition(i, null, null), t = gt(u, i.sqlJoinType);
|
|
3885
4186
|
o.push({
|
|
3886
4187
|
cube: c,
|
|
3887
4188
|
alias: `${n.toLowerCase()}_cube`,
|
|
@@ -3977,7 +4278,7 @@ var Z = class e {
|
|
|
3977
4278
|
joinDef: e.joinDef,
|
|
3978
4279
|
reversed: e.reversed
|
|
3979
4280
|
}));
|
|
3980
|
-
if (!c.slice(0, -1).some((e) => (e.reversed ?
|
|
4281
|
+
if (!c.slice(0, -1).some((e) => (e.reversed ? ht(e.joinDef.relationship) : e.joinDef.relationship) === "hasMany")) return {
|
|
3981
4282
|
path: c,
|
|
3982
4283
|
hasIntermediateHasMany: !1,
|
|
3983
4284
|
intermediateJoins: [],
|
|
@@ -4281,7 +4582,7 @@ var Z = class e {
|
|
|
4281
4582
|
}
|
|
4282
4583
|
convertInternalPathToJoinPathSteps(e) {
|
|
4283
4584
|
return e.map((e) => {
|
|
4284
|
-
let t = e.reversed ?
|
|
4585
|
+
let t = e.reversed ? ht(e.joinDef.relationship) : e.joinDef.relationship, n = gt(t, e.joinDef.sqlJoinType), r = e.joinDef.on.map((e) => ({
|
|
4285
4586
|
sourceColumn: e.source.name,
|
|
4286
4587
|
targetColumn: e.target.name
|
|
4287
4588
|
})), i = {
|
|
@@ -4346,7 +4647,7 @@ var Z = class e {
|
|
|
4346
4647
|
suggestion: "Add a dimension to see per-group breakdowns, or add a time dimension with granularity."
|
|
4347
4648
|
};
|
|
4348
4649
|
}
|
|
4349
|
-
},
|
|
4650
|
+
}, Bt = class {
|
|
4350
4651
|
constructor(e) {
|
|
4351
4652
|
this.queryBuilder = e;
|
|
4352
4653
|
}
|
|
@@ -4499,12 +4800,12 @@ var Z = class e {
|
|
|
4499
4800
|
};
|
|
4500
4801
|
//#endregion
|
|
4501
4802
|
//#region src/server/gap-filler.ts
|
|
4502
|
-
function
|
|
4503
|
-
let r = [], i =
|
|
4504
|
-
for (; i <= a && r.length < 1e4;) r.push(new Date(i)), i =
|
|
4803
|
+
function Vt(e, t, n) {
|
|
4804
|
+
let r = [], i = Ht(new Date(e), n), a = Ht(new Date(t), n);
|
|
4805
|
+
for (; i <= a && r.length < 1e4;) r.push(new Date(i)), i = Ut(i, n);
|
|
4505
4806
|
return r;
|
|
4506
4807
|
}
|
|
4507
|
-
function
|
|
4808
|
+
function Ht(e, t) {
|
|
4508
4809
|
let n = new Date(e);
|
|
4509
4810
|
switch (t) {
|
|
4510
4811
|
case "second":
|
|
@@ -4538,7 +4839,7 @@ function It(e, t) {
|
|
|
4538
4839
|
}
|
|
4539
4840
|
return n;
|
|
4540
4841
|
}
|
|
4541
|
-
function
|
|
4842
|
+
function Ut(e, t) {
|
|
4542
4843
|
let n = new Date(e);
|
|
4543
4844
|
switch (t) {
|
|
4544
4845
|
case "second":
|
|
@@ -4568,7 +4869,7 @@ function Lt(e, t) {
|
|
|
4568
4869
|
}
|
|
4569
4870
|
return n;
|
|
4570
4871
|
}
|
|
4571
|
-
function
|
|
4872
|
+
function Wt(e) {
|
|
4572
4873
|
if (e instanceof Date) return e.toISOString();
|
|
4573
4874
|
if (typeof e == "string") {
|
|
4574
4875
|
let t = new Date(e);
|
|
@@ -4576,15 +4877,15 @@ function Rt(e) {
|
|
|
4576
4877
|
}
|
|
4577
4878
|
return String(e);
|
|
4578
4879
|
}
|
|
4579
|
-
function
|
|
4880
|
+
function Gt(e, t) {
|
|
4580
4881
|
return t.length === 0 ? "__all__" : t.map((t) => String(e[t] ?? "")).join("|||");
|
|
4581
4882
|
}
|
|
4582
|
-
function
|
|
4583
|
-
let { timeDimensionKey: n, granularity: r, dateRange: i, fillValue: a, measures: o, dimensions: s } = t, c =
|
|
4883
|
+
function Kt(e, t) {
|
|
4884
|
+
let { timeDimensionKey: n, granularity: r, dateRange: i, fillValue: a, measures: o, dimensions: s } = t, c = Vt(i[0], i[1], r);
|
|
4584
4885
|
if (c.length === 0) return e;
|
|
4585
4886
|
let l = /* @__PURE__ */ new Map();
|
|
4586
4887
|
for (let t of e) {
|
|
4587
|
-
let e =
|
|
4888
|
+
let e = Gt(t, s), r = Wt(t[n]);
|
|
4588
4889
|
l.has(e) || l.set(e, /* @__PURE__ */ new Map()), l.get(e).set(r, t);
|
|
4589
4890
|
}
|
|
4590
4891
|
l.size === 0 && s.length === 0 && l.set("__all__", /* @__PURE__ */ new Map());
|
|
@@ -4604,7 +4905,7 @@ function Bt(e, t) {
|
|
|
4604
4905
|
}
|
|
4605
4906
|
return u;
|
|
4606
4907
|
}
|
|
4607
|
-
function
|
|
4908
|
+
function qt(e) {
|
|
4608
4909
|
if (!e) return null;
|
|
4609
4910
|
if (Array.isArray(e)) {
|
|
4610
4911
|
if (e.length < 2) return null;
|
|
@@ -4614,7 +4915,7 @@ function Vt(e) {
|
|
|
4614
4915
|
let t = new Date(e);
|
|
4615
4916
|
return isNaN(t.getTime()) ? null : [t, t];
|
|
4616
4917
|
}
|
|
4617
|
-
function
|
|
4918
|
+
function Jt(e, t, n) {
|
|
4618
4919
|
if (!t.timeDimensions || t.timeDimensions.length === 0) return e;
|
|
4619
4920
|
let r = t.timeDimensions.filter((e) => {
|
|
4620
4921
|
let t = e.fillMissingDates !== !1, n = e.granularity && e.dateRange;
|
|
@@ -4623,7 +4924,7 @@ function Ht(e, t, n) {
|
|
|
4623
4924
|
if (r.length === 0) return e;
|
|
4624
4925
|
let i = t.fillMissingDatesValue === void 0 ? 0 : t.fillMissingDatesValue, a = new Set(t.timeDimensions.map((e) => e.dimension)), o = (t.dimensions || []).filter((e) => !a.has(e)), s = e;
|
|
4625
4926
|
for (let e of r) {
|
|
4626
|
-
let t =
|
|
4927
|
+
let t = qt(e.dateRange);
|
|
4627
4928
|
if (!t) continue;
|
|
4628
4929
|
let r = {
|
|
4629
4930
|
timeDimensionKey: e.dimension,
|
|
@@ -4633,13 +4934,13 @@ function Ht(e, t, n) {
|
|
|
4633
4934
|
measures: n,
|
|
4634
4935
|
dimensions: o
|
|
4635
4936
|
};
|
|
4636
|
-
s =
|
|
4937
|
+
s = Kt(s, r);
|
|
4637
4938
|
}
|
|
4638
4939
|
return s;
|
|
4639
4940
|
}
|
|
4640
4941
|
//#endregion
|
|
4641
4942
|
//#region src/server/builders/comparison-query-builder.ts
|
|
4642
|
-
var
|
|
4943
|
+
var Yt = class {
|
|
4643
4944
|
dateTimeBuilder;
|
|
4644
4945
|
constructor(e) {
|
|
4645
4946
|
this.dateTimeBuilder = new Y(e);
|
|
@@ -4770,11 +5071,11 @@ var Ut = class {
|
|
|
4770
5071
|
return typeof i == "string" && typeof a == "string" ? new Date(i).getTime() - new Date(a).getTime() : 0;
|
|
4771
5072
|
});
|
|
4772
5073
|
}
|
|
4773
|
-
},
|
|
5074
|
+
}, Xt = class {
|
|
4774
5075
|
filterBuilder;
|
|
4775
5076
|
dateTimeBuilder;
|
|
4776
5077
|
constructor(e) {
|
|
4777
|
-
this.databaseAdapter = e, this.dateTimeBuilder = new Y(e), this.filterBuilder = new
|
|
5078
|
+
this.databaseAdapter = e, this.dateTimeBuilder = new Y(e), this.filterBuilder = new jt(e, this.dateTimeBuilder);
|
|
4778
5079
|
}
|
|
4779
5080
|
hasFunnel(e) {
|
|
4780
5081
|
return e.funnel !== void 0 && e.funnel.steps.length >= 2;
|
|
@@ -4809,7 +5110,7 @@ var Ut = class {
|
|
|
4809
5110
|
if (i.name || n.push(`Step ${r} must have a name`), "cube" in i && i.cube && (t.get(i.cube) || n.push(`Step ${r} cube not found: ${i.cube}`)), i.filter) {
|
|
4810
5111
|
let a;
|
|
4811
5112
|
"cube" in i && i.cube ? a = i.cube : typeof e.bindingKey == "string" && ([a] = e.bindingKey.split("."));
|
|
4812
|
-
let o = a ? new
|
|
5113
|
+
let o = a ? new Rt(t) : null, s = Array.isArray(i.filter) ? i.filter : [i.filter];
|
|
4813
5114
|
for (let e of s) if ("member" in e) {
|
|
4814
5115
|
let [i, s] = e.member.split("."), c = t.get(i);
|
|
4815
5116
|
if (!c) n.push(`Step ${r} filter cube not found: ${i}`);
|
|
@@ -4872,7 +5173,7 @@ var Ut = class {
|
|
|
4872
5173
|
return t;
|
|
4873
5174
|
}
|
|
4874
5175
|
resolveSteps(e, t, n) {
|
|
4875
|
-
let r = new
|
|
5176
|
+
let r = new Rt(t);
|
|
4876
5177
|
return e.steps.map((i, a) => {
|
|
4877
5178
|
let o = this.resolveCubeForStep(i, e, t), s = this.resolveBindingKey(e, o, n), c = this.resolveTimeDimension(e, o, n), l = this.buildStepFilters(i, o, t, n), u = this.extractFilterCubeNames(i), d = [];
|
|
4878
5179
|
for (let e of u) if (e !== o.name) {
|
|
@@ -4970,7 +5271,7 @@ var Ut = class {
|
|
|
4970
5271
|
let u = n.get(s);
|
|
4971
5272
|
if (!u) return null;
|
|
4972
5273
|
if (s !== t.name) {
|
|
4973
|
-
let e = new
|
|
5274
|
+
let e = new Rt(n).findPath(t.name, s);
|
|
4974
5275
|
if (!e || e.length === 0) return console.warn(`Funnel filter: Cannot filter by '${String(s).replace(/\n|\r/g, "")}.${String(c).replace(/\n|\r/g, "")}' in step using '${String(t.name).replace(/\n|\r/g, "")}'. No join path found. Filter will be skipped.`), null;
|
|
4975
5276
|
}
|
|
4976
5277
|
let d = u.dimensions?.[c];
|
|
@@ -5051,18 +5352,18 @@ var Ut = class {
|
|
|
5051
5352
|
let o = i.db.select(a).from(e);
|
|
5052
5353
|
return i.db.$with("funnel_metrics").as(o);
|
|
5053
5354
|
}
|
|
5054
|
-
},
|
|
5355
|
+
}, Zt = class {
|
|
5055
5356
|
filterBuilder;
|
|
5056
5357
|
dateTimeBuilder;
|
|
5057
5358
|
databaseAdapter;
|
|
5058
5359
|
constructor(e) {
|
|
5059
|
-
this.databaseAdapter = e, this.dateTimeBuilder = new Y(e), this.filterBuilder = new
|
|
5360
|
+
this.databaseAdapter = e, this.dateTimeBuilder = new Y(e), this.filterBuilder = new jt(e, this.dateTimeBuilder);
|
|
5060
5361
|
}
|
|
5061
5362
|
hasFlow(e) {
|
|
5062
5363
|
return e.flow !== void 0 && e.flow.startingStep !== void 0 && e.flow.eventDimension !== void 0;
|
|
5063
5364
|
}
|
|
5064
5365
|
validateConfig(e, t) {
|
|
5065
|
-
let n = [], r = [], i = this.databaseAdapter.getEngineType(), a = this.databaseAdapter.
|
|
5366
|
+
let n = [], r = [], i = this.databaseAdapter.getEngineType(), a = this.databaseAdapter.getCapabilities().supportsLateralSubqueriesInCTE;
|
|
5066
5367
|
if (i === "sqlite") return n.push("Flow queries are not supported on SQLite. Use PostgreSQL or MySQL for flow analysis."), {
|
|
5067
5368
|
isValid: !1,
|
|
5068
5369
|
errors: n,
|
|
@@ -5111,8 +5412,8 @@ var Ut = class {
|
|
|
5111
5412
|
}
|
|
5112
5413
|
buildFlowQuery(e, t, n) {
|
|
5113
5414
|
if (this.databaseAdapter.getEngineType() === "sqlite") throw Error("Flow queries are not supported on SQLite. Use PostgreSQL or MySQL for flow analysis.");
|
|
5114
|
-
let r = this.databaseAdapter.
|
|
5115
|
-
if (i === "lateral" && !r) throw Error("Lateral joins are not supported on this database");
|
|
5415
|
+
let r = this.databaseAdapter.getCapabilities().supportsLateralSubqueriesInCTE, i = e.joinStrategy ?? "auto", a = i === "lateral" || i === "auto" && r;
|
|
5416
|
+
if (i === "lateral" && !r) throw Error("Lateral joins with CTE references are not supported on this database");
|
|
5116
5417
|
let o = {
|
|
5117
5418
|
...e,
|
|
5118
5419
|
stepsBefore: e.outputMode === "sunburst" ? 0 : e.stepsBefore
|
|
@@ -5515,31 +5816,31 @@ var Ut = class {
|
|
|
5515
5816
|
};
|
|
5516
5817
|
//#endregion
|
|
5517
5818
|
//#region src/server/types/retention.ts
|
|
5518
|
-
function
|
|
5819
|
+
function Qt(e) {
|
|
5519
5820
|
return Array.isArray(e);
|
|
5520
5821
|
}
|
|
5521
|
-
function
|
|
5822
|
+
function $t(e) {
|
|
5522
5823
|
return typeof e == "object" && !!e && "cube" in e;
|
|
5523
5824
|
}
|
|
5524
|
-
function
|
|
5525
|
-
if (
|
|
5825
|
+
function en(e) {
|
|
5826
|
+
if ($t(e)) return e.cube;
|
|
5526
5827
|
let t = e.indexOf(".");
|
|
5527
5828
|
if (t === -1) throw Error(`Invalid time dimension format: ${e}. Expected 'CubeName.dimensionName'`);
|
|
5528
5829
|
return e.substring(0, t);
|
|
5529
5830
|
}
|
|
5530
|
-
function
|
|
5531
|
-
if (
|
|
5831
|
+
function tn(e) {
|
|
5832
|
+
if ($t(e)) return e.dimension;
|
|
5532
5833
|
let t = e.indexOf(".");
|
|
5533
5834
|
if (t === -1) throw Error(`Invalid time dimension format: ${e}. Expected 'CubeName.dimensionName'`);
|
|
5534
5835
|
return e.substring(t + 1);
|
|
5535
5836
|
}
|
|
5536
5837
|
//#endregion
|
|
5537
5838
|
//#region src/server/builders/retention-query-builder.ts
|
|
5538
|
-
var
|
|
5839
|
+
var nn = class {
|
|
5539
5840
|
filterBuilder;
|
|
5540
5841
|
dateTimeBuilder;
|
|
5541
5842
|
constructor(e) {
|
|
5542
|
-
this.databaseAdapter = e, this.dateTimeBuilder = new Y(e), this.filterBuilder = new
|
|
5843
|
+
this.databaseAdapter = e, this.dateTimeBuilder = new Y(e), this.filterBuilder = new jt(e, this.dateTimeBuilder);
|
|
5543
5844
|
}
|
|
5544
5845
|
hasRetention(e) {
|
|
5545
5846
|
return e.retention !== void 0 && e.retention.timeDimension != null && e.retention.bindingKey != null;
|
|
@@ -5547,12 +5848,12 @@ var Xt = class {
|
|
|
5547
5848
|
validateConfig(e, t) {
|
|
5548
5849
|
let n = [];
|
|
5549
5850
|
try {
|
|
5550
|
-
let r =
|
|
5851
|
+
let r = en(e.timeDimension), i = tn(e.timeDimension), a = t.get(r);
|
|
5551
5852
|
a ? a.dimensions?.[i] || n.push(`Time dimension not found: ${i} in cube ${r}`) : n.push(`Cube not found: ${r}`);
|
|
5552
5853
|
} catch {
|
|
5553
5854
|
n.push(`Invalid time dimension format: ${e.timeDimension}`);
|
|
5554
5855
|
}
|
|
5555
|
-
if (
|
|
5856
|
+
if (Qt(e.bindingKey)) for (let r of e.bindingKey) {
|
|
5556
5857
|
let e = t.get(r.cube);
|
|
5557
5858
|
if (!e) n.push(`Binding key mapping cube not found: ${r.cube}`);
|
|
5558
5859
|
else {
|
|
@@ -5640,7 +5941,7 @@ var Xt = class {
|
|
|
5640
5941
|
});
|
|
5641
5942
|
}
|
|
5642
5943
|
resolveConfig(e, t, n) {
|
|
5643
|
-
let r =
|
|
5944
|
+
let r = en(e.timeDimension), i = tn(e.timeDimension), a = t.get(r);
|
|
5644
5945
|
if (!a) throw Error(`Cube not found: ${r}`);
|
|
5645
5946
|
let o = a.dimensions?.[i];
|
|
5646
5947
|
if (!o) throw Error(`Time dimension not found: ${i}`);
|
|
@@ -5665,7 +5966,7 @@ var Xt = class {
|
|
|
5665
5966
|
};
|
|
5666
5967
|
}
|
|
5667
5968
|
resolveBindingKey(e, t, n, r) {
|
|
5668
|
-
if (
|
|
5969
|
+
if (Qt(e)) {
|
|
5669
5970
|
let i = e.find((e) => e.cube === t.name);
|
|
5670
5971
|
if (!i) throw Error(`No binding key mapping found for cube: ${t.name}`);
|
|
5671
5972
|
let a = this.extractDimensionName(i.dimension), o = n.get(i.cube);
|
|
@@ -5804,7 +6105,7 @@ var Xt = class {
|
|
|
5804
6105
|
let t = e.split(".");
|
|
5805
6106
|
return t.length > 1 ? t[1] : t[0];
|
|
5806
6107
|
}
|
|
5807
|
-
},
|
|
6108
|
+
}, rn = class {
|
|
5808
6109
|
constructor(e) {
|
|
5809
6110
|
this.queryPlanner = e;
|
|
5810
6111
|
}
|
|
@@ -6239,7 +6540,7 @@ var Xt = class {
|
|
|
6239
6540
|
timeDimensions: []
|
|
6240
6541
|
};
|
|
6241
6542
|
}
|
|
6242
|
-
},
|
|
6543
|
+
}, an = class {
|
|
6243
6544
|
name = "identity";
|
|
6244
6545
|
optimise(e) {
|
|
6245
6546
|
return e;
|
|
@@ -6247,7 +6548,7 @@ var Xt = class {
|
|
|
6247
6548
|
};
|
|
6248
6549
|
//#endregion
|
|
6249
6550
|
//#region src/server/physical-plan/processors/cte-processor.ts
|
|
6250
|
-
function
|
|
6551
|
+
function on(e, t, n, r) {
|
|
6251
6552
|
let i = /* @__PURE__ */ new Map();
|
|
6252
6553
|
if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0) {
|
|
6253
6554
|
for (let t of e.preAggregationCTEs) if (t.propagatingFilters && t.propagatingFilters.length > 0) for (let e of t.propagatingFilters) {
|
|
@@ -6277,7 +6578,7 @@ function $t(e, t, n, r) {
|
|
|
6277
6578
|
}
|
|
6278
6579
|
//#endregion
|
|
6279
6580
|
//#region src/server/physical-plan/processors/window-processor.ts
|
|
6280
|
-
function
|
|
6581
|
+
function sn(e, t, n, r, i, a) {
|
|
6281
6582
|
if (n.measures) for (let o of n.measures) {
|
|
6282
6583
|
let [s, c] = o.split("."), l = i.get(s);
|
|
6283
6584
|
if (!l?.measures?.[c]) continue;
|
|
@@ -6289,11 +6590,11 @@ function en(e, t, n, r, i, a) {
|
|
|
6289
6590
|
if (!m?.measures?.[p]) continue;
|
|
6290
6591
|
let h = m.measures[p], g = t.preAggregationCTEs?.find((e) => e.cube?.name === f && e.measures?.includes(d)), _;
|
|
6291
6592
|
_ = g ? F`sum(${F`${F.identifier(g.cteAlias)}.${F.identifier(p)}`})` : a.queryBuilder.buildMeasureExpression(h, r, m), e[d] || (e[d] = F`${_}`.as(d));
|
|
6292
|
-
let v =
|
|
6593
|
+
let v = cn(u, _, n, r, l, t, a);
|
|
6293
6594
|
v && (e[o] = F`${v}`.as(o));
|
|
6294
6595
|
}
|
|
6295
6596
|
}
|
|
6296
|
-
function
|
|
6597
|
+
function cn(e, t, n, r, i, a, o) {
|
|
6297
6598
|
let s = e.windowConfig || {}, c = (e, t) => {
|
|
6298
6599
|
if (!a.preAggregationCTEs) return null;
|
|
6299
6600
|
let n = a.preAggregationCTEs.find((t) => t.cube?.name === e);
|
|
@@ -6363,7 +6664,7 @@ function tn(e, t, n, r, i, a, o) {
|
|
|
6363
6664
|
}
|
|
6364
6665
|
//#endregion
|
|
6365
6666
|
//#region src/server/physical-plan/processors/selection-processor.ts
|
|
6366
|
-
function
|
|
6667
|
+
function ln(e, t, n, r, i) {
|
|
6367
6668
|
let a = { ...i.queryBuilder.buildSelections(e.joinCubes.length > 0 ? r : e.primaryCube, t, n) };
|
|
6368
6669
|
if (e.preAggregationCTEs) for (let o of e.preAggregationCTEs) {
|
|
6369
6670
|
let e = o.cube.name;
|
|
@@ -6374,7 +6675,7 @@ function nn(e, t, n, r, i) {
|
|
|
6374
6675
|
let u = l.measures[c], d = F`${F.identifier(o.cteAlias)}.${F.identifier(c)}`, f;
|
|
6375
6676
|
if (u.type === "calculated" && u.calculatedSql) f = i.queryBuilder.buildCTECalculatedMeasure(u, l, o, r, n);
|
|
6376
6677
|
else {
|
|
6377
|
-
let e = o.cteReason === "fanOutPrevention", n =
|
|
6678
|
+
let e = o.cteReason === "fanOutPrevention", n = un(o, t, r), a = e || n;
|
|
6378
6679
|
switch (u.type) {
|
|
6379
6680
|
case "count":
|
|
6380
6681
|
case "countDistinct":
|
|
@@ -6411,12 +6712,12 @@ function nn(e, t, n, r, i) {
|
|
|
6411
6712
|
(u || l && s?.dimensions?.[i]) && (a[t] = F`${F.identifier(o.cteAlias)}.${F.identifier(i)}`.as(t));
|
|
6412
6713
|
}
|
|
6413
6714
|
}
|
|
6414
|
-
return
|
|
6715
|
+
return sn(a, e, t, n, r, i), a;
|
|
6415
6716
|
}
|
|
6416
|
-
function
|
|
6417
|
-
return e.cteReason !== "hasMany" || e.downstreamJoinKeys && e.downstreamJoinKeys.length > 0 || e.intermediateJoins && e.intermediateJoins.length > 0 || !(t.dimensions && t.dimensions.length > 0 || t.timeDimensions && t.timeDimensions.length > 0) || t.dimensions?.some((t) => t.startsWith(`${e.cube.name}.`)) || t.timeDimensions?.some((t) => t.dimension.startsWith(`${e.cube.name}.`)) ? !1 : e.joinKeys.length > 0 && e.joinKeys.every((e) => !!e.sourceColumnObj &&
|
|
6717
|
+
function un(e, t, n) {
|
|
6718
|
+
return e.cteReason !== "hasMany" || e.downstreamJoinKeys && e.downstreamJoinKeys.length > 0 || e.intermediateJoins && e.intermediateJoins.length > 0 || !(t.dimensions && t.dimensions.length > 0 || t.timeDimensions && t.timeDimensions.length > 0) || t.dimensions?.some((t) => t.startsWith(`${e.cube.name}.`)) || t.timeDimensions?.some((t) => t.dimension.startsWith(`${e.cube.name}.`)) ? !1 : e.joinKeys.length > 0 && e.joinKeys.every((e) => !!e.sourceColumnObj && dn(e.sourceColumnObj, t, n));
|
|
6418
6719
|
}
|
|
6419
|
-
function
|
|
6720
|
+
function dn(e, t, n) {
|
|
6420
6721
|
if (t.dimensions) for (let r of t.dimensions) {
|
|
6421
6722
|
let [t, i] = r.split(".");
|
|
6422
6723
|
if (n.get(t)?.dimensions?.[i]?.sql === e) return !0;
|
|
@@ -6430,7 +6731,7 @@ function an(e, t, n) {
|
|
|
6430
6731
|
}
|
|
6431
6732
|
//#endregion
|
|
6432
6733
|
//#region src/server/physical-plan/processors/joins-processor.ts
|
|
6433
|
-
function
|
|
6734
|
+
function fn(e, t, n, r, i, a) {
|
|
6434
6735
|
let o = [], s = t.db.select(r).from(n.from);
|
|
6435
6736
|
if (i.ctes.length > 0 && (s = t.db.with(...i.ctes).select(r).from(n.from)), n.joins) for (let e of n.joins) switch (e.type || "left") {
|
|
6436
6737
|
case "left":
|
|
@@ -6530,7 +6831,7 @@ function on(e, t, n, r, i, a) {
|
|
|
6530
6831
|
}
|
|
6531
6832
|
//#endregion
|
|
6532
6833
|
//#region src/server/physical-plan/processors/predicates-processor.ts
|
|
6533
|
-
function
|
|
6834
|
+
function pn(e, t, n, r, i, a, o, s) {
|
|
6534
6835
|
let c = [...o.allWhereConditions];
|
|
6535
6836
|
if (i.where && c.push(i.where), e.joinCubes && e.joinCubes.length > 0) for (let t of e.joinCubes) {
|
|
6536
6837
|
let e = t.cube.name;
|
|
@@ -6557,14 +6858,14 @@ function sn(e, t, n, r, i, a, o, s) {
|
|
|
6557
6858
|
}
|
|
6558
6859
|
//#endregion
|
|
6559
6860
|
//#region src/server/physical-plan/processors/shared.ts
|
|
6560
|
-
function
|
|
6861
|
+
function mn(e) {
|
|
6561
6862
|
let t = /* @__PURE__ */ new Map();
|
|
6562
6863
|
if (t.set(e.primaryCube.name, e.primaryCube), e.joinCubes) for (let n of e.joinCubes) t.set(n.cube.name, n.cube);
|
|
6563
6864
|
return t;
|
|
6564
6865
|
}
|
|
6565
6866
|
//#endregion
|
|
6566
6867
|
//#region src/server/physical-plan/drizzle-plan-builder.ts
|
|
6567
|
-
var
|
|
6868
|
+
var hn = class {
|
|
6568
6869
|
constructor(e, t, n) {
|
|
6569
6870
|
this.queryBuilder = e, this.cteBuilder = t, this.databaseAdapter = n;
|
|
6570
6871
|
}
|
|
@@ -6704,13 +7005,13 @@ var ln = class {
|
|
|
6704
7005
|
if (i) return i;
|
|
6705
7006
|
let a = this.tryBuildKeysDeduplicationQuery(e, t, n, r);
|
|
6706
7007
|
if (a) return a;
|
|
6707
|
-
let o =
|
|
6708
|
-
return
|
|
7008
|
+
let o = on(e, t, n, r), s = e.primaryCube.sql(n), c = e.joinCubes.length > 0 ? mn(e) : new Map([[e.primaryCube.name, e.primaryCube]]);
|
|
7009
|
+
return pn(e, t, n, c, s, o, fn(e, n, s, ln(e, t, n, c, r), o, r), r);
|
|
6709
7010
|
}
|
|
6710
7011
|
tryBuildKeysDeduplicationQuery(e, t, n, r) {
|
|
6711
7012
|
let i = e.keysDeduplication;
|
|
6712
7013
|
if (!i?.multipliedCubeName || !t.measures?.length) return null;
|
|
6713
|
-
let a = e.joinCubes.length > 0 ?
|
|
7014
|
+
let a = e.joinCubes.length > 0 ? mn(e) : new Map([[e.primaryCube.name, e.primaryCube]]), o = a.get(i.multipliedCubeName);
|
|
6714
7015
|
if (!o || !this.canExecuteKeysDeduplication(t, o, i.multipliedCubeName)) return null;
|
|
6715
7016
|
let s = i.primaryKeyDimensions.length > 0 ? i.primaryKeyDimensions : this.getPrimaryKeyDimensions(o);
|
|
6716
7017
|
if (s.length === 0) return null;
|
|
@@ -6757,21 +7058,21 @@ var ln = class {
|
|
|
6757
7058
|
v = this.applyJoinByType(v, t.joinType ?? "left", e.from, t.joinCondition), e.where && _.push(e.where);
|
|
6758
7059
|
}
|
|
6759
7060
|
_.push(...r.queryBuilder.buildWhereConditions(a, t, n)), _.length > 0 && (v = v.where(_.length === 1 ? _[0] : R(..._))), d.length > 0 && (v = v.groupBy(...d));
|
|
6760
|
-
let y = n.db.$with(c).as(v), b = o.sql(n), x = {},
|
|
7061
|
+
let y = n.db.$with(c).as(v), b = o.sql(n), x = {}, ee = [];
|
|
6761
7062
|
for (let e of s) {
|
|
6762
7063
|
let t = o.dimensions?.[e];
|
|
6763
7064
|
if (!t) return null;
|
|
6764
7065
|
let r = K(t.sql, n);
|
|
6765
|
-
x[e] = F`${r}`.as(e),
|
|
7066
|
+
x[e] = F`${r}`.as(e), ee.push(r);
|
|
6766
7067
|
}
|
|
6767
|
-
let
|
|
7068
|
+
let S = /* @__PURE__ */ new Set();
|
|
6768
7069
|
for (let e of h) {
|
|
6769
7070
|
let [, t] = e.split(".");
|
|
6770
|
-
o.measures?.[t]?.type === "avg" &&
|
|
7071
|
+
o.measures?.[t]?.type === "avg" && S.add(t);
|
|
6771
7072
|
}
|
|
6772
7073
|
let C = h.filter((e) => {
|
|
6773
7074
|
let [, t] = e.split(".");
|
|
6774
|
-
return !
|
|
7075
|
+
return !S.has(t);
|
|
6775
7076
|
});
|
|
6776
7077
|
if (C.length > 0) {
|
|
6777
7078
|
let e = r.queryBuilder.buildResolvedMeasures(C, new Map([[o.name, o]]), n);
|
|
@@ -6783,14 +7084,14 @@ var ln = class {
|
|
|
6783
7084
|
}
|
|
6784
7085
|
for (let e of h) {
|
|
6785
7086
|
let [, t] = e.split(".");
|
|
6786
|
-
if (!
|
|
7087
|
+
if (!S.has(t)) continue;
|
|
6787
7088
|
let r = o.measures?.[t];
|
|
6788
7089
|
if (!r?.sql) return null;
|
|
6789
7090
|
let i = K(r.sql, n), a = `__avg_sum__${t}`, s = `__avg_count__${t}`;
|
|
6790
7091
|
x[a] = F`sum(${i})`.as(a), x[s] = F`count(${i})`.as(s);
|
|
6791
7092
|
}
|
|
6792
7093
|
let w = n.db.select(x).from(b.from), T = [];
|
|
6793
|
-
b.where && T.push(b.where), T.push(...r.queryBuilder.buildWhereConditions(o, t, n)), T.length > 0 && (w = w.where(T.length === 1 ? T[0] : R(...T))),
|
|
7094
|
+
b.where && T.push(b.where), T.push(...r.queryBuilder.buildWhereConditions(o, t, n)), T.length > 0 && (w = w.where(T.length === 1 ? T[0] : R(...T))), ee.length > 0 && (w = w.groupBy(...ee));
|
|
6794
7095
|
let te = n.db.$with(l).as(w), E = {};
|
|
6795
7096
|
for (let e of t.dimensions ?? []) E[e] = F`${F.identifier(c)}.${F.identifier(e)}`.as(e);
|
|
6796
7097
|
for (let e of t.timeDimensions ?? []) E[e.dimension] = F`${F.identifier(c)}.${F.identifier(e.dimension)}`.as(e.dimension);
|
|
@@ -6920,7 +7221,16 @@ var ln = class {
|
|
|
6920
7221
|
default: return e.leftJoin(n, r);
|
|
6921
7222
|
}
|
|
6922
7223
|
}
|
|
6923
|
-
}
|
|
7224
|
+
};
|
|
7225
|
+
//#endregion
|
|
7226
|
+
//#region src/server/executor.ts
|
|
7227
|
+
function Q(e, t) {
|
|
7228
|
+
if (process.env.DC_DEBUG) try {
|
|
7229
|
+
let { sql: n, params: r } = t.toSQL();
|
|
7230
|
+
console.log(`\n[DC_DEBUG] ${e}`), console.log(n), r.length > 0 && console.log("params:", r), console.log();
|
|
7231
|
+
} catch {}
|
|
7232
|
+
}
|
|
7233
|
+
var gn = class {
|
|
6924
7234
|
queryBuilder;
|
|
6925
7235
|
drizzlePlanBuilder;
|
|
6926
7236
|
databaseAdapter;
|
|
@@ -6933,16 +7243,16 @@ var ln = class {
|
|
|
6933
7243
|
planOptimiser;
|
|
6934
7244
|
constructor(e, t) {
|
|
6935
7245
|
if (this.dbExecutor = e, this.databaseAdapter = e.databaseAdapter, !this.databaseAdapter) throw Error("DatabaseExecutor must have a databaseAdapter property");
|
|
6936
|
-
this.queryBuilder = new
|
|
6937
|
-
let n = new
|
|
6938
|
-
this.drizzlePlanBuilder = new
|
|
7246
|
+
this.queryBuilder = new Lt(this.databaseAdapter);
|
|
7247
|
+
let n = new zt(), r = new Bt(this.queryBuilder);
|
|
7248
|
+
this.drizzlePlanBuilder = new hn(this.queryBuilder, r, this.databaseAdapter), this.comparisonQueryBuilder = new Yt(this.databaseAdapter), this.funnelQueryBuilder = new Xt(this.databaseAdapter), this.flowQueryBuilder = new Zt(this.databaseAdapter), this.retentionQueryBuilder = new nn(this.databaseAdapter), this.logicalPlanBuilder = new rn(n), this.planOptimiser = new an(), this.cacheConfig = t;
|
|
6939
7249
|
}
|
|
6940
7250
|
async execute(e, t, n, r) {
|
|
6941
7251
|
try {
|
|
6942
7252
|
let i = this.resolveQueryMode(t);
|
|
6943
7253
|
this.validateQueryForMode(i, e, t);
|
|
6944
7254
|
let a;
|
|
6945
|
-
if (this.cacheConfig?.enabled !== !1 && this.cacheConfig?.provider) if (a =
|
|
7255
|
+
if (this.cacheConfig?.enabled !== !1 && this.cacheConfig?.provider) if (a = Ct(t, n, this.cacheConfig), r?.skipCache) this.cacheConfig.onCacheEvent?.({
|
|
6946
7256
|
type: "miss",
|
|
6947
7257
|
key: a,
|
|
6948
7258
|
durationMs: 0
|
|
@@ -7036,13 +7346,15 @@ var ln = class {
|
|
|
7036
7346
|
db: this.dbExecutor.db,
|
|
7037
7347
|
schema: this.dbExecutor.schema,
|
|
7038
7348
|
securityContext: n
|
|
7039
|
-
}, o =
|
|
7349
|
+
}, o = this.funnelQueryBuilder.buildFunnelQuery(r, e, a);
|
|
7350
|
+
Q("funnel query", o);
|
|
7351
|
+
let s = await o, c = this.funnelQueryBuilder.transformResult(s, r), l = {
|
|
7040
7352
|
measures: {},
|
|
7041
7353
|
dimensions: {},
|
|
7042
7354
|
segments: {},
|
|
7043
7355
|
timeDimensions: {}
|
|
7044
7356
|
};
|
|
7045
|
-
return
|
|
7357
|
+
return l.funnel = {
|
|
7046
7358
|
config: r,
|
|
7047
7359
|
steps: r.steps.map((e, t) => ({
|
|
7048
7360
|
name: e.name,
|
|
@@ -7050,8 +7362,8 @@ var ln = class {
|
|
|
7050
7362
|
timeToConvert: e.timeToConvert
|
|
7051
7363
|
}))
|
|
7052
7364
|
}, {
|
|
7053
|
-
data:
|
|
7054
|
-
annotation:
|
|
7365
|
+
data: c,
|
|
7366
|
+
annotation: l
|
|
7055
7367
|
};
|
|
7056
7368
|
}
|
|
7057
7369
|
async executeFlowQueryWithCache(e, t, n, r) {
|
|
@@ -7068,20 +7380,22 @@ var ln = class {
|
|
|
7068
7380
|
db: this.dbExecutor.db,
|
|
7069
7381
|
schema: this.dbExecutor.schema,
|
|
7070
7382
|
securityContext: n
|
|
7071
|
-
}, o =
|
|
7383
|
+
}, o = this.flowQueryBuilder.buildFlowQuery(r, e, a);
|
|
7384
|
+
Q("flow query", o);
|
|
7385
|
+
let s = await o, c = this.flowQueryBuilder.transformResult(s), l = {
|
|
7072
7386
|
measures: {},
|
|
7073
7387
|
dimensions: {},
|
|
7074
7388
|
segments: {},
|
|
7075
7389
|
timeDimensions: {}
|
|
7076
7390
|
};
|
|
7077
|
-
return
|
|
7391
|
+
return l.flow = {
|
|
7078
7392
|
config: r,
|
|
7079
7393
|
startingStep: { name: r.startingStep.name },
|
|
7080
7394
|
stepsBefore: r.stepsBefore,
|
|
7081
7395
|
stepsAfter: r.stepsAfter
|
|
7082
7396
|
}, {
|
|
7083
|
-
data: [
|
|
7084
|
-
annotation:
|
|
7397
|
+
data: [c],
|
|
7398
|
+
annotation: l
|
|
7085
7399
|
};
|
|
7086
7400
|
}
|
|
7087
7401
|
async executeRetentionQueryWithCache(e, t, n, r) {
|
|
@@ -7098,29 +7412,33 @@ var ln = class {
|
|
|
7098
7412
|
db: this.dbExecutor.db,
|
|
7099
7413
|
schema: this.dbExecutor.schema,
|
|
7100
7414
|
securityContext: n
|
|
7101
|
-
}, o =
|
|
7415
|
+
}, o = this.retentionQueryBuilder.buildRetentionQuery(r, e, a);
|
|
7416
|
+
Q("retention query", o);
|
|
7417
|
+
let s = await o, c = this.retentionQueryBuilder.transformResult(s, r), l = {
|
|
7102
7418
|
measures: {},
|
|
7103
7419
|
dimensions: {},
|
|
7104
7420
|
segments: {},
|
|
7105
7421
|
timeDimensions: {}
|
|
7106
7422
|
};
|
|
7107
|
-
return
|
|
7423
|
+
return l.retention = {
|
|
7108
7424
|
config: r,
|
|
7109
7425
|
granularity: r.granularity,
|
|
7110
7426
|
periods: r.periods,
|
|
7111
7427
|
retentionType: r.retentionType,
|
|
7112
7428
|
breakdownDimensions: r.breakdownDimensions
|
|
7113
7429
|
}, {
|
|
7114
|
-
data:
|
|
7115
|
-
annotation:
|
|
7430
|
+
data: c,
|
|
7431
|
+
annotation: l
|
|
7116
7432
|
};
|
|
7117
7433
|
}
|
|
7118
7434
|
async executeStandardQuery(e, t, n) {
|
|
7119
7435
|
let r = new q(), i = this.createQueryContext(n, r);
|
|
7120
7436
|
this.preloadFilterCache(t, r, e, i);
|
|
7121
|
-
let { optimisedPlan: a } = this.buildRegularQueryArtifacts(e, t, i), o = this.drizzlePlanBuilder.derivePhysicalPlanContext(a), s = this.drizzlePlanBuilder.build(o, t, i)
|
|
7437
|
+
let { optimisedPlan: a } = this.buildRegularQueryArtifacts(e, t, i), o = this.drizzlePlanBuilder.derivePhysicalPlanContext(a), s = this.drizzlePlanBuilder.build(o, t, i);
|
|
7438
|
+
Q("query", s);
|
|
7439
|
+
let c = this.queryBuilder.collectNumericFields(e, t), l = await this.dbExecutor.execute(s, c);
|
|
7122
7440
|
return {
|
|
7123
|
-
data:
|
|
7441
|
+
data: Jt(Array.isArray(l) ? l.map((e) => {
|
|
7124
7442
|
let n = { ...e };
|
|
7125
7443
|
if (t.timeDimensions) {
|
|
7126
7444
|
for (let e of t.timeDimensions) if (e.dimension in n) {
|
|
@@ -7246,7 +7564,7 @@ var ln = class {
|
|
|
7246
7564
|
}
|
|
7247
7565
|
validateQueryForMode(e, t, n) {
|
|
7248
7566
|
let r = () => {
|
|
7249
|
-
let e =
|
|
7567
|
+
let e = yn(t, n);
|
|
7250
7568
|
if (!e.isValid) throw Error(`Query validation failed: ${e.errors.join(", ")}`);
|
|
7251
7569
|
};
|
|
7252
7570
|
({
|
|
@@ -7264,7 +7582,7 @@ var ln = class {
|
|
|
7264
7582
|
let e = this.retentionQueryBuilder.validateConfig(n.retention, t);
|
|
7265
7583
|
if (!e.isValid) throw Error(`Retention validation failed: ${e.errors.join(", ")}`);
|
|
7266
7584
|
}
|
|
7267
|
-
})[
|
|
7585
|
+
})[vt(e)]();
|
|
7268
7586
|
}
|
|
7269
7587
|
async executeQueryByModeWithCache(e, t, n, r, i) {
|
|
7270
7588
|
return {
|
|
@@ -7273,15 +7591,17 @@ var ln = class {
|
|
|
7273
7591
|
funnel: () => this.executeFunnelQueryWithCache(t, n, r, i),
|
|
7274
7592
|
flow: () => this.executeFlowQueryWithCache(t, n, r, i),
|
|
7275
7593
|
retention: () => this.executeRetentionQueryWithCache(t, n, r, i)
|
|
7276
|
-
}[
|
|
7594
|
+
}[vt(e)]();
|
|
7277
7595
|
}
|
|
7278
7596
|
async executeRegularQueryWithCache(e, t, n, r) {
|
|
7279
7597
|
let i = new q(), a = this.createQueryContext(n, i);
|
|
7280
7598
|
this.preloadFilterCache(t, i, e, a);
|
|
7281
7599
|
let { optimisedPlan: o } = this.buildRegularQueryArtifacts(e, t, a), s = this.drizzlePlanBuilder.derivePhysicalPlanContext(o);
|
|
7282
7600
|
this.validateSecurityContext(s, a);
|
|
7283
|
-
let c = this.drizzlePlanBuilder.build(s, t, a)
|
|
7284
|
-
|
|
7601
|
+
let c = this.drizzlePlanBuilder.build(s, t, a);
|
|
7602
|
+
Q("query", c);
|
|
7603
|
+
let l = this.queryBuilder.collectNumericFields(e, t), u = await this.dbExecutor.execute(c, l), d = {
|
|
7604
|
+
data: Jt(Array.isArray(u) ? u.map((e) => {
|
|
7285
7605
|
let n = { ...e };
|
|
7286
7606
|
if (t.timeDimensions) {
|
|
7287
7607
|
for (let e of t.timeDimensions) if (e.dimension in n) {
|
|
@@ -7319,7 +7639,7 @@ var ln = class {
|
|
|
7319
7639
|
funnel: () => this.dryRunFunnel(t, n, r),
|
|
7320
7640
|
flow: () => this.dryRunFlow(t, n, r),
|
|
7321
7641
|
retention: () => this.dryRunRetention(t, n, r)
|
|
7322
|
-
}[
|
|
7642
|
+
}[vt(e)]();
|
|
7323
7643
|
}
|
|
7324
7644
|
async generateComparisonSQL(e, t, n) {
|
|
7325
7645
|
let r = this.buildComparisonExecutionPlan(t).periodQueries[0];
|
|
@@ -7371,9 +7691,9 @@ var ln = class {
|
|
|
7371
7691
|
}
|
|
7372
7692
|
preloadFilterCache(e, t, n, r) {
|
|
7373
7693
|
if (e.filters && e.filters.length > 0) {
|
|
7374
|
-
let i =
|
|
7694
|
+
let i = St(e.filters);
|
|
7375
7695
|
for (let e of i) {
|
|
7376
|
-
let i =
|
|
7696
|
+
let i = bt(e);
|
|
7377
7697
|
if (t.has(i)) continue;
|
|
7378
7698
|
let [a, o] = e.member.split("."), s = n.get(a);
|
|
7379
7699
|
if (!s) continue;
|
|
@@ -7389,7 +7709,7 @@ var ln = class {
|
|
|
7389
7709
|
}
|
|
7390
7710
|
if (e.timeDimensions) {
|
|
7391
7711
|
for (let i of e.timeDimensions) if (i.dateRange) {
|
|
7392
|
-
let e =
|
|
7712
|
+
let e = xt(i.dimension, i.dateRange);
|
|
7393
7713
|
if (t.has(e)) continue;
|
|
7394
7714
|
let [a, o] = i.dimension.split("."), s = n.get(a);
|
|
7395
7715
|
if (!s) continue;
|
|
@@ -7400,13 +7720,13 @@ var ln = class {
|
|
|
7400
7720
|
}
|
|
7401
7721
|
}
|
|
7402
7722
|
}
|
|
7403
|
-
},
|
|
7723
|
+
}, _n = class e {
|
|
7404
7724
|
cubes = /* @__PURE__ */ new Map();
|
|
7405
7725
|
dbExecutor;
|
|
7406
7726
|
metadataCache;
|
|
7407
7727
|
cacheConfig;
|
|
7408
7728
|
constructor(e) {
|
|
7409
|
-
e?.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e?.drizzle && (this.dbExecutor =
|
|
7729
|
+
e?.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e?.drizzle && (this.dbExecutor = mt(e.drizzle, e.schema, e.engineType)), this.cacheConfig = e?.cache;
|
|
7410
7730
|
}
|
|
7411
7731
|
setDatabaseExecutor(e) {
|
|
7412
7732
|
this.dbExecutor = e;
|
|
@@ -7415,7 +7735,7 @@ var ln = class {
|
|
|
7415
7735
|
return this.dbExecutor?.getEngineType();
|
|
7416
7736
|
}
|
|
7417
7737
|
setDrizzle(e, t, n) {
|
|
7418
|
-
this.dbExecutor =
|
|
7738
|
+
this.dbExecutor = mt(e, t, n);
|
|
7419
7739
|
}
|
|
7420
7740
|
hasExecutor() {
|
|
7421
7741
|
return !!this.dbExecutor;
|
|
@@ -7425,7 +7745,7 @@ var ln = class {
|
|
|
7425
7745
|
return this.dbExecutor;
|
|
7426
7746
|
}
|
|
7427
7747
|
createQueryExecutor(e = !1) {
|
|
7428
|
-
return new
|
|
7748
|
+
return new gn(this.requireExecutor(), e ? this.cacheConfig : void 0);
|
|
7429
7749
|
}
|
|
7430
7750
|
formatSqlResult(e) {
|
|
7431
7751
|
let t = this.requireExecutor().getEngineType();
|
|
@@ -7449,7 +7769,7 @@ var ln = class {
|
|
|
7449
7769
|
t.push(`Calculated measure '${e.name}.${n}' must have calculatedSql property`);
|
|
7450
7770
|
continue;
|
|
7451
7771
|
}
|
|
7452
|
-
let i =
|
|
7772
|
+
let i = Pt(r.calculatedSql);
|
|
7453
7773
|
if (!i.isValid) {
|
|
7454
7774
|
t.push(`Invalid calculatedSql syntax in '${e.name}.${n}': ${i.errors.join(", ")}`);
|
|
7455
7775
|
continue;
|
|
@@ -7619,18 +7939,18 @@ var ln = class {
|
|
|
7619
7939
|
return Array.from(this.cubes.keys());
|
|
7620
7940
|
}
|
|
7621
7941
|
validateQuery(e) {
|
|
7622
|
-
return
|
|
7942
|
+
return yn(this.cubes, e);
|
|
7623
7943
|
}
|
|
7624
7944
|
analyzeQuery(e, t) {
|
|
7625
7945
|
return this.createQueryExecutor(!0).analyzeQuery(this.cubes, e, t);
|
|
7626
7946
|
}
|
|
7627
7947
|
};
|
|
7628
|
-
function
|
|
7948
|
+
function vn(e) {
|
|
7629
7949
|
let t = [];
|
|
7630
7950
|
return e.timeDimensions?.some((e) => e.compareDateRange && e.compareDateRange.length >= 2) && t.push("comparison"), e.funnel !== void 0 && e.funnel.steps?.length >= 2 && t.push("funnel"), e.flow !== void 0 && e.flow.startingStep !== void 0 && e.flow.eventDimension !== void 0 && t.push("flow"), e.retention !== void 0 && e.retention.timeDimension != null && e.retention.bindingKey != null && t.push("retention"), t.length === 0 ? [] : t;
|
|
7631
7951
|
}
|
|
7632
|
-
function
|
|
7633
|
-
let n = [], r =
|
|
7952
|
+
function yn(e, t) {
|
|
7953
|
+
let n = [], r = vn(t);
|
|
7634
7954
|
if (r.length > 1) return n.push(`Query contains multiple query modes: ${r.join(", ")}`), {
|
|
7635
7955
|
isValid: !1,
|
|
7636
7956
|
errors: n
|
|
@@ -7651,7 +7971,7 @@ function pn(e, t) {
|
|
|
7651
7971
|
}
|
|
7652
7972
|
},
|
|
7653
7973
|
retention: () => {
|
|
7654
|
-
let r = t.retention, i =
|
|
7974
|
+
let r = t.retention, i = xn(r.timeDimension);
|
|
7655
7975
|
i && !e.has(i) && n.push(`Retention cube not found: ${i}`);
|
|
7656
7976
|
let a = r.bindingKey;
|
|
7657
7977
|
if (typeof a == "string") {
|
|
@@ -7717,16 +8037,16 @@ function pn(e, t) {
|
|
|
7717
8037
|
}
|
|
7718
8038
|
o.dimensions[i] || n.push(`TimeDimension '${i}' not found on cube '${t}' (must be a dimension with time type)`);
|
|
7719
8039
|
}
|
|
7720
|
-
if (t.filters) for (let r of t.filters)
|
|
8040
|
+
if (t.filters) for (let r of t.filters) bn(r, e, n, a);
|
|
7721
8041
|
return a.size === 0 && n.push("Query must reference at least one cube through measures, dimensions, or filters"), {
|
|
7722
8042
|
isValid: n.length === 0,
|
|
7723
8043
|
errors: n
|
|
7724
8044
|
};
|
|
7725
8045
|
}
|
|
7726
|
-
function
|
|
8046
|
+
function bn(e, t, n, r) {
|
|
7727
8047
|
if ("and" in e || "or" in e) {
|
|
7728
8048
|
let i = e.and || e.or || [];
|
|
7729
|
-
for (let e of i)
|
|
8049
|
+
for (let e of i) bn(e, t, n, r);
|
|
7730
8050
|
return;
|
|
7731
8051
|
}
|
|
7732
8052
|
if (!("member" in e)) {
|
|
@@ -7749,7 +8069,7 @@ function mn(e, t, n, r) {
|
|
|
7749
8069
|
n.push(`Filter field '${a}' not found on cube '${i}' (must be a dimension or measure)${e}`);
|
|
7750
8070
|
}
|
|
7751
8071
|
}
|
|
7752
|
-
function
|
|
8072
|
+
function xn(e) {
|
|
7753
8073
|
if (typeof e == "string") {
|
|
7754
8074
|
let [t] = e.split(".");
|
|
7755
8075
|
return t || null;
|
|
@@ -7758,31 +8078,31 @@ function hn(e) {
|
|
|
7758
8078
|
}
|
|
7759
8079
|
//#endregion
|
|
7760
8080
|
//#region src/adapters/mcp-transport.ts
|
|
7761
|
-
var
|
|
8081
|
+
var Sn = [
|
|
7762
8082
|
"2025-11-25",
|
|
7763
8083
|
"2025-06-18",
|
|
7764
8084
|
"2025-03-26"
|
|
7765
|
-
],
|
|
7766
|
-
function
|
|
7767
|
-
let t =
|
|
8085
|
+
], Cn = "2025-11-25";
|
|
8086
|
+
function wn(e) {
|
|
8087
|
+
let t = Pn(e["mcp-protocol-version"]) || "2025-11-25";
|
|
7768
8088
|
return {
|
|
7769
|
-
ok:
|
|
7770
|
-
negotiated:
|
|
7771
|
-
supported:
|
|
8089
|
+
ok: Sn.includes(t),
|
|
8090
|
+
negotiated: Sn.includes(t) ? t : null,
|
|
8091
|
+
supported: Sn
|
|
7772
8092
|
};
|
|
7773
8093
|
}
|
|
7774
|
-
function
|
|
8094
|
+
function Tn(e) {
|
|
7775
8095
|
if (!e) return !1;
|
|
7776
8096
|
let t = e.split(",").map((e) => e.trim().toLowerCase()), n = t.includes("text/event-stream"), r = t.includes("application/json");
|
|
7777
8097
|
return n && !r;
|
|
7778
8098
|
}
|
|
7779
|
-
var
|
|
7780
|
-
function
|
|
8099
|
+
var En = "mcp-session-id";
|
|
8100
|
+
function Dn(e) {
|
|
7781
8101
|
if (!e) return !1;
|
|
7782
8102
|
let t = e.split(",").map((e) => e.trim().toLowerCase().split(";")[0]), n = t.some((e) => e === "application/json"), r = t.some((e) => e === "text/event-stream");
|
|
7783
8103
|
return n && r;
|
|
7784
8104
|
}
|
|
7785
|
-
function
|
|
8105
|
+
function On(e, t = {}) {
|
|
7786
8106
|
let { allowMissingOrigin: n = !0, allowedOrigins: r } = t;
|
|
7787
8107
|
if (!e) return n ? { valid: !0 } : {
|
|
7788
8108
|
valid: !1,
|
|
@@ -7809,11 +8129,11 @@ function xn(e, t = {}) {
|
|
|
7809
8129
|
reason: "Origin not in allowed list"
|
|
7810
8130
|
};
|
|
7811
8131
|
}
|
|
7812
|
-
function
|
|
8132
|
+
function kn(e, t, n) {
|
|
7813
8133
|
let r = [];
|
|
7814
8134
|
return t && r.push(`id: ${t}`), n && n > 0 && r.push(`retry: ${n}`), r.push("event: message"), r.push(`data: ${JSON.stringify(e)}`), r.push(""), r.join("\n");
|
|
7815
8135
|
}
|
|
7816
|
-
function
|
|
8136
|
+
function An(e, t, n, r) {
|
|
7817
8137
|
return {
|
|
7818
8138
|
jsonrpc: "2.0",
|
|
7819
8139
|
id: e ?? null,
|
|
@@ -7824,14 +8144,14 @@ function Cn(e, t, n, r) {
|
|
|
7824
8144
|
}
|
|
7825
8145
|
};
|
|
7826
8146
|
}
|
|
7827
|
-
function
|
|
8147
|
+
function jn(e, t) {
|
|
7828
8148
|
return {
|
|
7829
8149
|
jsonrpc: "2.0",
|
|
7830
8150
|
id: e ?? null,
|
|
7831
8151
|
result: t
|
|
7832
8152
|
};
|
|
7833
8153
|
}
|
|
7834
|
-
function
|
|
8154
|
+
function Mn(e) {
|
|
7835
8155
|
if (!e || typeof e != "object") return null;
|
|
7836
8156
|
let t = e;
|
|
7837
8157
|
return t.jsonrpc !== "2.0" || typeof t.method != "string" ? null : {
|
|
@@ -7841,12 +8161,12 @@ function Tn(e) {
|
|
|
7841
8161
|
params: t.params
|
|
7842
8162
|
};
|
|
7843
8163
|
}
|
|
7844
|
-
async function
|
|
7845
|
-
let { semanticLayer: o, extractSecurityContext: s, rawRequest: c, rawResponse: l } = a, u = a.prompts ??
|
|
8164
|
+
async function Nn(e, i, a) {
|
|
8165
|
+
let { semanticLayer: o, extractSecurityContext: s, rawRequest: c, rawResponse: l } = a, u = a.prompts ?? Bn, d = a.resources ?? Vn;
|
|
7846
8166
|
switch (e) {
|
|
7847
8167
|
case "initialize": {
|
|
7848
8168
|
let e = i?.protocolVersion, t;
|
|
7849
|
-
return t = e &&
|
|
8169
|
+
return t = e && Sn.includes(e) ? e : Cn, {
|
|
7850
8170
|
protocolVersion: t,
|
|
7851
8171
|
capabilities: {
|
|
7852
8172
|
tools: { listChanged: !1 },
|
|
@@ -7854,7 +8174,7 @@ async function En(e, i, a) {
|
|
|
7854
8174
|
prompts: { listChanged: !1 },
|
|
7855
8175
|
sampling: {}
|
|
7856
8176
|
},
|
|
7857
|
-
sessionId:
|
|
8177
|
+
sessionId: In(),
|
|
7858
8178
|
serverInfo: {
|
|
7859
8179
|
name: "drizzle-cube",
|
|
7860
8180
|
version: typeof process < "u" ? process.env?.npm_package_version || "dev" : "worker"
|
|
@@ -7863,11 +8183,11 @@ async function En(e, i, a) {
|
|
|
7863
8183
|
}
|
|
7864
8184
|
case "list_tools":
|
|
7865
8185
|
case "tools/list": return {
|
|
7866
|
-
tools:
|
|
8186
|
+
tools: Ln(),
|
|
7867
8187
|
nextCursor: ""
|
|
7868
8188
|
};
|
|
7869
8189
|
case "call_tool":
|
|
7870
|
-
case "tools/call": return
|
|
8190
|
+
case "tools/call": return Rn(i, a);
|
|
7871
8191
|
case "resources/list": return {
|
|
7872
8192
|
resources: d.map(({ uri: e, name: t, description: n, mimeType: r }) => ({
|
|
7873
8193
|
uri: e,
|
|
@@ -7926,16 +8246,16 @@ function $(e, t, n) {
|
|
|
7926
8246
|
let r = Error(t);
|
|
7927
8247
|
return r.code = e, n !== void 0 && (r.data = n), r;
|
|
7928
8248
|
}
|
|
7929
|
-
function
|
|
8249
|
+
function Pn(e) {
|
|
7930
8250
|
return e ? Array.isArray(e) ? e[0] || null : e : null;
|
|
7931
8251
|
}
|
|
7932
|
-
function
|
|
8252
|
+
function Fn(e) {
|
|
7933
8253
|
return e.id === void 0 || e.id === null;
|
|
7934
8254
|
}
|
|
7935
|
-
function
|
|
8255
|
+
function In() {
|
|
7936
8256
|
return `evt-${e()}`;
|
|
7937
8257
|
}
|
|
7938
|
-
function
|
|
8258
|
+
function Ln() {
|
|
7939
8259
|
return [
|
|
7940
8260
|
{
|
|
7941
8261
|
name: "discover",
|
|
@@ -7988,26 +8308,26 @@ function An() {
|
|
|
7988
8308
|
}
|
|
7989
8309
|
];
|
|
7990
8310
|
}
|
|
7991
|
-
async function
|
|
8311
|
+
async function Rn(e, i) {
|
|
7992
8312
|
let { semanticLayer: a, extractSecurityContext: o, rawRequest: s, rawResponse: c } = i, l = e || {};
|
|
7993
8313
|
if (!l.name) throw $(-32602, "name is required for tools/call");
|
|
7994
8314
|
let u = l.arguments;
|
|
7995
8315
|
switch (l.name) {
|
|
7996
|
-
case "discover": return
|
|
8316
|
+
case "discover": return zn(await t(a, u || {}));
|
|
7997
8317
|
case "validate": {
|
|
7998
8318
|
let e = u || {};
|
|
7999
8319
|
if (!e.query) throw $(-32602, "query is required");
|
|
8000
|
-
return
|
|
8320
|
+
return zn(await n(a, e));
|
|
8001
8321
|
}
|
|
8002
8322
|
case "load": {
|
|
8003
8323
|
let e = u || {};
|
|
8004
8324
|
if (!e.query) throw $(-32602, "query is required");
|
|
8005
|
-
return
|
|
8325
|
+
return zn(await r(a, await o(s, c), e));
|
|
8006
8326
|
}
|
|
8007
8327
|
default: throw $(-32601, `Unknown tool: ${l.name}`);
|
|
8008
8328
|
}
|
|
8009
8329
|
}
|
|
8010
|
-
function
|
|
8330
|
+
function zn(e) {
|
|
8011
8331
|
return {
|
|
8012
8332
|
content: [{
|
|
8013
8333
|
type: "text",
|
|
@@ -8016,7 +8336,7 @@ function Mn(e) {
|
|
|
8016
8336
|
isError: !1
|
|
8017
8337
|
};
|
|
8018
8338
|
}
|
|
8019
|
-
var
|
|
8339
|
+
var Bn = a(), Vn = [{
|
|
8020
8340
|
uri: "drizzle-cube://quickstart",
|
|
8021
8341
|
name: "Drizzle Cube MCP Quickstart",
|
|
8022
8342
|
description: "Minimal guide for using discover/suggest/validate/load",
|
|
@@ -8117,11 +8437,11 @@ var Nn = a(), Pn = [{
|
|
|
8117
8437
|
"- Both can be combined: inDateRange filter + timeDimensions granularity."
|
|
8118
8438
|
].join("\n")
|
|
8119
8439
|
}];
|
|
8120
|
-
function
|
|
8121
|
-
return
|
|
8440
|
+
function Hn() {
|
|
8441
|
+
return Vn;
|
|
8122
8442
|
}
|
|
8123
|
-
function
|
|
8124
|
-
return
|
|
8443
|
+
function Un() {
|
|
8444
|
+
return Bn;
|
|
8125
8445
|
}
|
|
8126
8446
|
//#endregion
|
|
8127
|
-
export {
|
|
8447
|
+
export { Un as a, wn as c, kn as d, Dn as f, _n as h, Nn as i, Mn as l, Tn as m, An as n, Hn as o, On as p, jn as r, Fn as s, En as t, In as u };
|