drizzle-cube 0.4.51 → 0.4.53
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/{compiler-CPE-YZfe.cjs → compiler-CRgLzmSn.cjs} +14 -14
- package/dist/adapters/{compiler-BXfrvebp.js → compiler-S6KHiOY6.js} +349 -201
- package/dist/adapters/express/index.cjs +1 -1
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +1 -1
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/server/index.cjs +37 -37
- package/dist/server/index.js +1170 -1022
- package/package.json +1 -1
|
@@ -1422,15 +1422,18 @@ function Ce(e) {
|
|
|
1422
1422
|
}
|
|
1423
1423
|
//#endregion
|
|
1424
1424
|
//#region src/server/executors/postgres-executor.ts
|
|
1425
|
-
|
|
1425
|
+
function we(e) {
|
|
1426
|
+
return Array.isArray(e) ? e : e && typeof e == "object" && "rows" in e && Array.isArray(e.rows) ? e.rows : [];
|
|
1427
|
+
}
|
|
1428
|
+
var Te = class extends H {
|
|
1426
1429
|
async execute(e, t) {
|
|
1427
1430
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1428
1431
|
let n = await e.execute();
|
|
1429
1432
|
return Array.isArray(n) ? n.map((e) => this.convertNumericFields(e, t)) : n;
|
|
1430
1433
|
}
|
|
1431
1434
|
if (!this.db.execute) throw Error("PostgreSQL database instance must have an execute method");
|
|
1432
|
-
let n = await this.db.execute(e);
|
|
1433
|
-
return
|
|
1435
|
+
let n = await this.db.execute(e), r = we(n);
|
|
1436
|
+
return r.length > 0 ? r.map((e) => this.convertNumericFields(e, t)) : n;
|
|
1434
1437
|
}
|
|
1435
1438
|
convertNumericFields(e, t) {
|
|
1436
1439
|
if (!e || typeof e != "object") return e;
|
|
@@ -1468,11 +1471,9 @@ var we = class extends H {
|
|
|
1468
1471
|
let r = t[parseInt(n, 10) - 1];
|
|
1469
1472
|
return r === null ? "NULL" : typeof r == "number" ? String(r) : typeof r == "boolean" ? r ? "TRUE" : "FALSE" : r instanceof Date ? `'${r.toISOString()}'` : `'${String(r).replace(/'/g, "''")}'`;
|
|
1470
1473
|
}))}`), a = [];
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
typeof t == "string" && a.push(t);
|
|
1475
|
-
}
|
|
1474
|
+
for (let e of we(i)) if (e && typeof e == "object") {
|
|
1475
|
+
let t = e["QUERY PLAN"] || e["query plan"] || e.queryplan;
|
|
1476
|
+
typeof t == "string" && a.push(t);
|
|
1476
1477
|
}
|
|
1477
1478
|
return Se(a, {
|
|
1478
1479
|
sql: e,
|
|
@@ -1483,7 +1484,7 @@ var we = class extends H {
|
|
|
1483
1484
|
if (!e || e.length === 0) return [];
|
|
1484
1485
|
if (!this.db.execute) throw Error("PostgreSQL database instance must have an execute method");
|
|
1485
1486
|
try {
|
|
1486
|
-
let t = e.map((e) => `'${e.toLowerCase()}'`).join(","), n = await this.db.execute(D`
|
|
1487
|
+
let t = e.map((e) => `'${e.toLowerCase()}'`).join(","), n = we(await this.db.execute(D`
|
|
1487
1488
|
SELECT
|
|
1488
1489
|
t.relname as table_name,
|
|
1489
1490
|
i.relname as index_name,
|
|
@@ -1500,25 +1501,25 @@ var we = class extends H {
|
|
|
1500
1501
|
AND t.relname IN (${D.raw(t)})
|
|
1501
1502
|
GROUP BY t.relname, i.relname, ix.indisunique, ix.indisprimary
|
|
1502
1503
|
ORDER BY t.relname, i.relname
|
|
1503
|
-
`);
|
|
1504
|
-
return
|
|
1504
|
+
`));
|
|
1505
|
+
return n.length === 0 ? [] : n.map((e) => ({
|
|
1505
1506
|
table_name: e.table_name,
|
|
1506
1507
|
index_name: e.index_name,
|
|
1507
1508
|
columns: e.columns.split(","),
|
|
1508
1509
|
is_unique: e.is_unique,
|
|
1509
1510
|
is_primary: e.is_primary
|
|
1510
|
-
}))
|
|
1511
|
+
}));
|
|
1511
1512
|
} catch (e) {
|
|
1512
1513
|
return console.warn("Failed to get table indexes:", e), [];
|
|
1513
1514
|
}
|
|
1514
1515
|
}
|
|
1515
1516
|
};
|
|
1516
|
-
function
|
|
1517
|
-
return new
|
|
1517
|
+
function Ee(e, t) {
|
|
1518
|
+
return new Te(e, t, "postgres");
|
|
1518
1519
|
}
|
|
1519
1520
|
//#endregion
|
|
1520
1521
|
//#region src/server/explain/mysql-parser.ts
|
|
1521
|
-
function
|
|
1522
|
+
function De(e, t) {
|
|
1522
1523
|
let n = t?.toLowerCase() || "";
|
|
1523
1524
|
switch (e.toLowerCase()) {
|
|
1524
1525
|
case "all": return "Seq Scan";
|
|
@@ -1532,10 +1533,10 @@ function Ee(e, t) {
|
|
|
1532
1533
|
default: return `MySQL ${e}`;
|
|
1533
1534
|
}
|
|
1534
1535
|
}
|
|
1535
|
-
function
|
|
1536
|
+
function Oe(e, t) {
|
|
1536
1537
|
let n = [], r = [], i = !1, a = 0;
|
|
1537
1538
|
for (let t of e) {
|
|
1538
|
-
let e =
|
|
1539
|
+
let e = De(t.type, t.Extra);
|
|
1539
1540
|
t.type.toLowerCase() === "all" && (i = !0), t.key && r.push(t.key);
|
|
1540
1541
|
let o = {
|
|
1541
1542
|
type: e,
|
|
@@ -1566,7 +1567,7 @@ function De(e, t) {
|
|
|
1566
1567
|
}
|
|
1567
1568
|
//#endregion
|
|
1568
1569
|
//#region src/server/executors/mysql-executor.ts
|
|
1569
|
-
var
|
|
1570
|
+
var ke = class extends H {
|
|
1570
1571
|
async execute(e, t) {
|
|
1571
1572
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1572
1573
|
let n = await e.execute();
|
|
@@ -1616,7 +1617,7 @@ var Oe = class extends H {
|
|
|
1616
1617
|
filtered: Number(e.filtered) || 100,
|
|
1617
1618
|
Extra: e.Extra || null
|
|
1618
1619
|
});
|
|
1619
|
-
return
|
|
1620
|
+
return Oe(s, {
|
|
1620
1621
|
sql: e,
|
|
1621
1622
|
params: t
|
|
1622
1623
|
});
|
|
@@ -1650,12 +1651,12 @@ var Oe = class extends H {
|
|
|
1650
1651
|
}
|
|
1651
1652
|
}
|
|
1652
1653
|
};
|
|
1653
|
-
function
|
|
1654
|
-
return new
|
|
1654
|
+
function Ae(e, t) {
|
|
1655
|
+
return new ke(e, t, "mysql");
|
|
1655
1656
|
}
|
|
1656
1657
|
//#endregion
|
|
1657
1658
|
//#region src/server/explain/sqlite-parser.ts
|
|
1658
|
-
function
|
|
1659
|
+
function je(e) {
|
|
1659
1660
|
let t = e.toLowerCase(), n = e.match(/^SCAN\s+(\S+)/i);
|
|
1660
1661
|
if (n) return {
|
|
1661
1662
|
type: "Seq Scan",
|
|
@@ -1680,10 +1681,10 @@ function Ae(e) {
|
|
|
1680
1681
|
table: a[1]
|
|
1681
1682
|
} : 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 };
|
|
1682
1683
|
}
|
|
1683
|
-
function
|
|
1684
|
+
function Me(e, t) {
|
|
1684
1685
|
let n = [], r = [], i = !1, a = /* @__PURE__ */ new Map();
|
|
1685
1686
|
for (let t of e) {
|
|
1686
|
-
let e =
|
|
1687
|
+
let e = je(t.detail);
|
|
1687
1688
|
e.type === "Seq Scan" && (i = !0), e.index && r.push(e.index);
|
|
1688
1689
|
let o = {
|
|
1689
1690
|
type: e.type,
|
|
@@ -1714,7 +1715,7 @@ function je(e, t) {
|
|
|
1714
1715
|
}
|
|
1715
1716
|
//#endregion
|
|
1716
1717
|
//#region src/server/executors/sqlite-executor.ts
|
|
1717
|
-
var
|
|
1718
|
+
var Ne = class extends H {
|
|
1718
1719
|
async execute(e, t) {
|
|
1719
1720
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1720
1721
|
let n = await e.execute();
|
|
@@ -1763,7 +1764,7 @@ var Me = class extends H {
|
|
|
1763
1764
|
notused: Number(e.notused) || 0,
|
|
1764
1765
|
detail: String(e.detail || "")
|
|
1765
1766
|
});
|
|
1766
|
-
return
|
|
1767
|
+
return Me(s, {
|
|
1767
1768
|
sql: e,
|
|
1768
1769
|
params: t
|
|
1769
1770
|
});
|
|
@@ -1796,29 +1797,29 @@ var Me = class extends H {
|
|
|
1796
1797
|
}
|
|
1797
1798
|
}
|
|
1798
1799
|
};
|
|
1799
|
-
function
|
|
1800
|
-
return new
|
|
1800
|
+
function Pe(e, t) {
|
|
1801
|
+
return new Ne(e, t, "sqlite");
|
|
1801
1802
|
}
|
|
1802
1803
|
//#endregion
|
|
1803
1804
|
//#region src/server/executors/singlestore-executor.ts
|
|
1804
|
-
var
|
|
1805
|
+
var Fe = class extends ke {
|
|
1805
1806
|
getEngineType() {
|
|
1806
1807
|
return "singlestore";
|
|
1807
1808
|
}
|
|
1808
1809
|
};
|
|
1809
|
-
function
|
|
1810
|
-
return new
|
|
1810
|
+
function Ie(e, t) {
|
|
1811
|
+
return new Fe(e, t);
|
|
1811
1812
|
}
|
|
1812
1813
|
//#endregion
|
|
1813
1814
|
//#region src/server/explain/duckdb-parser.ts
|
|
1814
|
-
function
|
|
1815
|
+
function Le(e, t) {
|
|
1815
1816
|
let n = [], r = [], i = !1, a, o = [];
|
|
1816
1817
|
for (let t of e) {
|
|
1817
1818
|
if (/^[┌├└│─┐┤┘]+$/.test(t.trim()) || /EXPLANATION|QUERY PLAN/i.test(t)) continue;
|
|
1818
|
-
let e =
|
|
1819
|
+
let e = ze(t);
|
|
1819
1820
|
if (e) {
|
|
1820
1821
|
(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);
|
|
1821
|
-
let s =
|
|
1822
|
+
let s = Re(t);
|
|
1822
1823
|
for (; o.length > 0 && o[o.length - 1].indent >= s;) o.pop();
|
|
1823
1824
|
if (o.length === 0) n.push(e);
|
|
1824
1825
|
else {
|
|
@@ -1845,13 +1846,13 @@ function Ie(e, t) {
|
|
|
1845
1846
|
sql: t
|
|
1846
1847
|
};
|
|
1847
1848
|
}
|
|
1848
|
-
function
|
|
1849
|
+
function Re(e) {
|
|
1849
1850
|
let t = 0;
|
|
1850
1851
|
for (let n of e) if (n === " " || n === "│" || n === "├" || n === "└" || n === "─") t++;
|
|
1851
1852
|
else break;
|
|
1852
1853
|
return t;
|
|
1853
1854
|
}
|
|
1854
|
-
function
|
|
1855
|
+
function ze(e) {
|
|
1855
1856
|
let t = e.replace(/[┌├└│─┐┤┘]/g, "").replace(/^\s*/, "").trim();
|
|
1856
1857
|
if (!t || t.match(/^\(cost=([\d.]+)\s+rows=(\d+)\)$/i)) return null;
|
|
1857
1858
|
let n = t.match(/^([A-Z_]+)(?:\s+(\S+))?(?:\s+on\s+(\S+))?(?:\s+\(cost=([\d.]+)\s+rows=(\d+)\))?/i);
|
|
@@ -1877,7 +1878,7 @@ function Re(e) {
|
|
|
1877
1878
|
}
|
|
1878
1879
|
//#endregion
|
|
1879
1880
|
//#region src/server/executors/duckdb-executor.ts
|
|
1880
|
-
var
|
|
1881
|
+
var Be = class extends H {
|
|
1881
1882
|
async execute(e, t) {
|
|
1882
1883
|
if (e && typeof e == "object" && typeof e.execute == "function") try {
|
|
1883
1884
|
let n = await e.execute();
|
|
@@ -1971,7 +1972,7 @@ var ze = class extends H {
|
|
|
1971
1972
|
typeof t == "string" && a.push(t);
|
|
1972
1973
|
}
|
|
1973
1974
|
}
|
|
1974
|
-
return
|
|
1975
|
+
return Le(a, {
|
|
1975
1976
|
sql: e,
|
|
1976
1977
|
params: t
|
|
1977
1978
|
});
|
|
@@ -2004,19 +2005,19 @@ var ze = class extends H {
|
|
|
2004
2005
|
}
|
|
2005
2006
|
}
|
|
2006
2007
|
};
|
|
2007
|
-
function
|
|
2008
|
-
return new
|
|
2008
|
+
function Ve(e, t) {
|
|
2009
|
+
return new Be(e, t, "duckdb");
|
|
2009
2010
|
}
|
|
2010
2011
|
//#endregion
|
|
2011
2012
|
//#region src/server/explain/databend-parser.ts
|
|
2012
|
-
function
|
|
2013
|
+
function He(e, t) {
|
|
2013
2014
|
let n = [], r = [], i = !1, a, o = [];
|
|
2014
2015
|
for (let t of e) {
|
|
2015
2016
|
if (!t.trim()) continue;
|
|
2016
|
-
let e =
|
|
2017
|
+
let e = We(t);
|
|
2017
2018
|
if (e) {
|
|
2018
2019
|
(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);
|
|
2019
|
-
let s =
|
|
2020
|
+
let s = Ue(t);
|
|
2020
2021
|
for (; o.length > 0 && o[o.length - 1].indent >= s;) o.pop();
|
|
2021
2022
|
if (o.length === 0) n.push(e);
|
|
2022
2023
|
else {
|
|
@@ -2043,13 +2044,13 @@ function Ve(e, t) {
|
|
|
2043
2044
|
sql: t
|
|
2044
2045
|
};
|
|
2045
2046
|
}
|
|
2046
|
-
function
|
|
2047
|
+
function Ue(e) {
|
|
2047
2048
|
let t = 0;
|
|
2048
2049
|
for (let n of e) if (n === " " || n === "│" || n === "├" || n === "└" || n === "─") t++;
|
|
2049
2050
|
else break;
|
|
2050
2051
|
return t;
|
|
2051
2052
|
}
|
|
2052
|
-
function
|
|
2053
|
+
function We(e) {
|
|
2053
2054
|
let t = e.replace(/[┌├└│─┐┤┘]/g, "").replace(/^\s*/, "").trim();
|
|
2054
2055
|
if (!t || /^(filters|table|estimated rows|output columns|push downs):/.test(t)) return null;
|
|
2055
2056
|
let n = t.match(/^([A-Z][A-Za-z_]+(?:\s+[A-Z][A-Za-z_]+)*)(?:\s+(\S+))?/);
|
|
@@ -2063,7 +2064,7 @@ function Ue(e) {
|
|
|
2063
2064
|
}
|
|
2064
2065
|
//#endregion
|
|
2065
2066
|
//#region src/server/executors/databend-executor.ts
|
|
2066
|
-
var
|
|
2067
|
+
var Ge = class extends H {
|
|
2067
2068
|
async execute(e, t) {
|
|
2068
2069
|
if (e && typeof e == "object" && typeof e.execute == "function") try {
|
|
2069
2070
|
let n = await e.execute();
|
|
@@ -2157,7 +2158,7 @@ var We = class extends H {
|
|
|
2157
2158
|
typeof t == "string" && a.push(t);
|
|
2158
2159
|
}
|
|
2159
2160
|
}
|
|
2160
|
-
return
|
|
2161
|
+
return He(a, {
|
|
2161
2162
|
sql: e,
|
|
2162
2163
|
params: t
|
|
2163
2164
|
});
|
|
@@ -2166,19 +2167,19 @@ var We = class extends H {
|
|
|
2166
2167
|
return !e || e.length, [];
|
|
2167
2168
|
}
|
|
2168
2169
|
};
|
|
2169
|
-
function
|
|
2170
|
-
return new
|
|
2170
|
+
function Ke(e, t) {
|
|
2171
|
+
return new Ge(e, t, "databend");
|
|
2171
2172
|
}
|
|
2172
2173
|
//#endregion
|
|
2173
2174
|
//#region src/server/explain/snowflake-parser.ts
|
|
2174
|
-
function
|
|
2175
|
+
function qe(e, t) {
|
|
2175
2176
|
let n = [], r = [], i = !1, a, o = [];
|
|
2176
2177
|
for (let t of e) {
|
|
2177
2178
|
if (!t.trim()) continue;
|
|
2178
|
-
let e =
|
|
2179
|
+
let e = Ye(t);
|
|
2179
2180
|
if (e) {
|
|
2180
2181
|
(e.type.includes("TableScan") || e.type.includes("SCAN")) && (i = !0), n.length === 0 && e.estimatedCost !== void 0 && (a = e.estimatedCost);
|
|
2181
|
-
let r =
|
|
2182
|
+
let r = Je(t);
|
|
2182
2183
|
for (; o.length > 0 && o[o.length - 1].indent >= r;) o.pop();
|
|
2183
2184
|
if (o.length === 0) n.push(e);
|
|
2184
2185
|
else {
|
|
@@ -2205,13 +2206,13 @@ function Ke(e, t) {
|
|
|
2205
2206
|
sql: t
|
|
2206
2207
|
};
|
|
2207
2208
|
}
|
|
2208
|
-
function
|
|
2209
|
+
function Je(e) {
|
|
2209
2210
|
let t = 0;
|
|
2210
2211
|
for (let n of e) if (n === " " || n === "-" || n === ">") t++;
|
|
2211
2212
|
else break;
|
|
2212
2213
|
return t;
|
|
2213
2214
|
}
|
|
2214
|
-
function
|
|
2215
|
+
function Ye(e) {
|
|
2215
2216
|
let t = e.replace(/^[\s\d:]*->/, "").trim();
|
|
2216
2217
|
if (!t || /^(GlobalStats|partitions|bytes):/i.test(t) || /^\w+=\d+/.test(t)) return null;
|
|
2217
2218
|
let n = t.match(/^([A-Z][A-Za-z_]+(?:\s+[A-Z][A-Za-z_]+)*)(?:\s+(\S+))?/);
|
|
@@ -2225,7 +2226,7 @@ function Je(e) {
|
|
|
2225
2226
|
}
|
|
2226
2227
|
//#endregion
|
|
2227
2228
|
//#region src/server/executors/snowflake-executor.ts
|
|
2228
|
-
var
|
|
2229
|
+
var Xe = class extends H {
|
|
2229
2230
|
async execute(e, t) {
|
|
2230
2231
|
if (e && typeof e == "object" && typeof e.execute == "function") try {
|
|
2231
2232
|
let n = await e.execute();
|
|
@@ -2318,7 +2319,7 @@ var Ye = class extends H {
|
|
|
2318
2319
|
typeof t == "string" && i.push(t);
|
|
2319
2320
|
}
|
|
2320
2321
|
}
|
|
2321
|
-
return
|
|
2322
|
+
return qe(i, {
|
|
2322
2323
|
sql: e,
|
|
2323
2324
|
params: t
|
|
2324
2325
|
});
|
|
@@ -2327,23 +2328,23 @@ var Ye = class extends H {
|
|
|
2327
2328
|
return [];
|
|
2328
2329
|
}
|
|
2329
2330
|
};
|
|
2330
|
-
function
|
|
2331
|
-
return new
|
|
2331
|
+
function Ze(e, t) {
|
|
2332
|
+
return new Xe(e, t, "snowflake");
|
|
2332
2333
|
}
|
|
2333
2334
|
//#endregion
|
|
2334
2335
|
//#region src/server/executors/index.ts
|
|
2335
|
-
function
|
|
2336
|
+
function Qe(e, t, n) {
|
|
2336
2337
|
if (n) switch (n) {
|
|
2337
|
-
case "postgres": return
|
|
2338
|
-
case "mysql": return
|
|
2339
|
-
case "sqlite": return
|
|
2340
|
-
case "singlestore": return
|
|
2341
|
-
case "duckdb": return
|
|
2342
|
-
case "databend": return
|
|
2343
|
-
case "snowflake": return
|
|
2344
|
-
}
|
|
2345
|
-
if (e.all && e.run) return
|
|
2346
|
-
if (e.execute) return
|
|
2338
|
+
case "postgres": return Ee(e, t);
|
|
2339
|
+
case "mysql": return Ae(e, t);
|
|
2340
|
+
case "sqlite": return Pe(e, t);
|
|
2341
|
+
case "singlestore": return Ie(e, t);
|
|
2342
|
+
case "duckdb": return Ve(e, t);
|
|
2343
|
+
case "databend": return Ke(e, t);
|
|
2344
|
+
case "snowflake": return Ze(e, t);
|
|
2345
|
+
}
|
|
2346
|
+
if (e.all && e.run) return Pe(e, t);
|
|
2347
|
+
if (e.execute) return Ee(e, t);
|
|
2347
2348
|
throw Error("Unable to determine database engine type. Please specify engineType parameter.");
|
|
2348
2349
|
}
|
|
2349
2350
|
//#endregion
|
|
@@ -2351,7 +2352,7 @@ function Ze(e, t, n) {
|
|
|
2351
2352
|
function U(e, t) {
|
|
2352
2353
|
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;
|
|
2353
2354
|
}
|
|
2354
|
-
function
|
|
2355
|
+
function $e(e) {
|
|
2355
2356
|
switch (e) {
|
|
2356
2357
|
case "belongsTo": return "hasMany";
|
|
2357
2358
|
case "hasMany": return "belongsTo";
|
|
@@ -2360,7 +2361,7 @@ function Qe(e) {
|
|
|
2360
2361
|
default: return e;
|
|
2361
2362
|
}
|
|
2362
2363
|
}
|
|
2363
|
-
function
|
|
2364
|
+
function et(e, t) {
|
|
2364
2365
|
if (t) return t;
|
|
2365
2366
|
switch (e) {
|
|
2366
2367
|
case "belongsTo": return "inner";
|
|
@@ -2370,17 +2371,17 @@ function $e(e, t) {
|
|
|
2370
2371
|
default: return "left";
|
|
2371
2372
|
}
|
|
2372
2373
|
}
|
|
2373
|
-
function
|
|
2374
|
+
function tt(e) {
|
|
2374
2375
|
return e && typeof e == "object" ? D`${D`${e}`}` : e;
|
|
2375
2376
|
}
|
|
2376
|
-
function
|
|
2377
|
+
function nt(e) {
|
|
2377
2378
|
if (e === "__proto__" || e === "constructor" || e === "prototype") throw Error(`Unsafe property key: ${e}`);
|
|
2378
2379
|
return e;
|
|
2379
2380
|
}
|
|
2380
2381
|
function W(e, t) {
|
|
2381
|
-
return
|
|
2382
|
+
return tt(typeof e == "function" ? e(t) : e);
|
|
2382
2383
|
}
|
|
2383
|
-
function
|
|
2384
|
+
function rt(e, t) {
|
|
2384
2385
|
if (e.relationship !== "belongsToMany" || !e.through) throw Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
|
|
2385
2386
|
let { table: n, sourceKey: r, targetKey: i, securitySql: a } = e.through, o = [];
|
|
2386
2387
|
for (let e of r) {
|
|
@@ -2397,7 +2398,7 @@ function nt(e, t) {
|
|
|
2397
2398
|
let e = a(t);
|
|
2398
2399
|
c = Array.isArray(e) ? e : [e];
|
|
2399
2400
|
}
|
|
2400
|
-
let l =
|
|
2401
|
+
let l = et("belongsToMany", e.sqlJoinType);
|
|
2401
2402
|
return {
|
|
2402
2403
|
junctionJoins: [{
|
|
2403
2404
|
joinType: l,
|
|
@@ -2419,7 +2420,7 @@ function G(e) {
|
|
|
2419
2420
|
let t = e, n = JSON.stringify(Array.isArray(t.values) ? [...t.values].sort() : t.values), r = t.dateRange ? `:dr:${JSON.stringify(t.dateRange)}` : "";
|
|
2420
2421
|
return `${t.member}:${t.operator}:${n}${r}`;
|
|
2421
2422
|
}
|
|
2422
|
-
function
|
|
2423
|
+
function it(e, t) {
|
|
2423
2424
|
return `timeDim:${e}:${JSON.stringify(t)}`;
|
|
2424
2425
|
}
|
|
2425
2426
|
var K = class {
|
|
@@ -2460,37 +2461,37 @@ var K = class {
|
|
|
2460
2461
|
};
|
|
2461
2462
|
}
|
|
2462
2463
|
};
|
|
2463
|
-
function
|
|
2464
|
+
function at(e) {
|
|
2464
2465
|
let t = [];
|
|
2465
|
-
for (let n of e) "and" in n && n.and ? t.push(...
|
|
2466
|
+
for (let n of e) "and" in n && n.and ? t.push(...at(n.and)) : "or" in n && n.or ? t.push(...at(n.or)) : "member" in n && t.push(n);
|
|
2466
2467
|
return t;
|
|
2467
2468
|
}
|
|
2468
2469
|
//#endregion
|
|
2469
2470
|
//#region src/server/cache-utils.ts
|
|
2470
|
-
function
|
|
2471
|
-
let r = n.keyPrefix ?? "drizzle-cube:", i =
|
|
2471
|
+
function ot(e, t, n = {}) {
|
|
2472
|
+
let r = n.keyPrefix ?? "drizzle-cube:", i = st(e), a = `${r}query:${ft(JSON.stringify(i))}`;
|
|
2472
2473
|
if (n.includeSecurityContext !== !1) {
|
|
2473
|
-
let e =
|
|
2474
|
+
let e = ft(n.securityContextSerializer ? n.securityContextSerializer(t) : JSON.stringify(J(t)));
|
|
2474
2475
|
a += `:ctx:${e}`;
|
|
2475
2476
|
}
|
|
2476
2477
|
return a;
|
|
2477
2478
|
}
|
|
2478
|
-
function
|
|
2479
|
+
function st(e) {
|
|
2479
2480
|
return {
|
|
2480
2481
|
measures: e.measures ? [...e.measures].sort() : void 0,
|
|
2481
2482
|
dimensions: e.dimensions ? [...e.dimensions].sort() : void 0,
|
|
2482
2483
|
filters: e.filters ? q(e.filters) : void 0,
|
|
2483
|
-
timeDimensions: e.timeDimensions ?
|
|
2484
|
+
timeDimensions: e.timeDimensions ? dt(e.timeDimensions) : void 0,
|
|
2484
2485
|
limit: e.limit,
|
|
2485
2486
|
offset: e.offset,
|
|
2486
2487
|
order: e.order ? J(e.order) : void 0,
|
|
2487
2488
|
fillMissingDatesValue: e.fillMissingDatesValue,
|
|
2488
|
-
funnel: e.funnel ?
|
|
2489
|
-
flow: e.flow ?
|
|
2490
|
-
retention: e.retention ?
|
|
2489
|
+
funnel: e.funnel ? ct(e.funnel) : void 0,
|
|
2490
|
+
flow: e.flow ? lt(e.flow) : void 0,
|
|
2491
|
+
retention: e.retention ? ut(e.retention) : void 0
|
|
2491
2492
|
};
|
|
2492
2493
|
}
|
|
2493
|
-
function
|
|
2494
|
+
function ct(e) {
|
|
2494
2495
|
return {
|
|
2495
2496
|
bindingKey: e.bindingKey,
|
|
2496
2497
|
timeDimension: e.timeDimension,
|
|
@@ -2506,7 +2507,7 @@ function st(e) {
|
|
|
2506
2507
|
globalTimeWindow: e.globalTimeWindow
|
|
2507
2508
|
};
|
|
2508
2509
|
}
|
|
2509
|
-
function
|
|
2510
|
+
function lt(e) {
|
|
2510
2511
|
return {
|
|
2511
2512
|
bindingKey: e.bindingKey,
|
|
2512
2513
|
timeDimension: e.timeDimension,
|
|
@@ -2522,7 +2523,7 @@ function ct(e) {
|
|
|
2522
2523
|
joinStrategy: e.joinStrategy
|
|
2523
2524
|
};
|
|
2524
2525
|
}
|
|
2525
|
-
function
|
|
2526
|
+
function ut(e) {
|
|
2526
2527
|
return {
|
|
2527
2528
|
timeDimension: e.timeDimension,
|
|
2528
2529
|
bindingKey: e.bindingKey,
|
|
@@ -2546,7 +2547,7 @@ function q(e) {
|
|
|
2546
2547
|
};
|
|
2547
2548
|
}).sort((e, t) => JSON.stringify(e).localeCompare(JSON.stringify(t)));
|
|
2548
2549
|
}
|
|
2549
|
-
function
|
|
2550
|
+
function dt(e) {
|
|
2550
2551
|
return [...e].map((e) => ({
|
|
2551
2552
|
dimension: e.dimension,
|
|
2552
2553
|
granularity: e.granularity,
|
|
@@ -2561,7 +2562,7 @@ function ut(e) {
|
|
|
2561
2562
|
function J(e) {
|
|
2562
2563
|
return typeof e != "object" || !e ? e : Array.isArray(e) ? e.map(J) : Object.keys(e).sort().reduce((t, n) => (t[n] = J(e[n]), t), {});
|
|
2563
2564
|
}
|
|
2564
|
-
function
|
|
2565
|
+
function ft(e) {
|
|
2565
2566
|
let t = 2166136261, n = Math.min(e.length, 65536);
|
|
2566
2567
|
for (let r = 0; r < n; r++) t ^= e.charCodeAt(r), t = t * 16777619 >>> 0;
|
|
2567
2568
|
return t.toString(16).padStart(8, "0");
|
|
@@ -2948,8 +2949,8 @@ var Y = class {
|
|
|
2948
2949
|
};
|
|
2949
2950
|
//#endregion
|
|
2950
2951
|
//#region src/server/template-substitution.ts
|
|
2951
|
-
function
|
|
2952
|
-
let { cube: n, allCubes: r, resolvedMeasures: i } = t, a =
|
|
2952
|
+
function pt(e, t) {
|
|
2953
|
+
let { cube: n, allCubes: r, resolvedMeasures: i } = t, a = mt(e), o = /* @__PURE__ */ new Map();
|
|
2953
2954
|
for (let e of a) {
|
|
2954
2955
|
let { originalRef: t, cubeName: a, fieldName: s } = e, c = a || n.name;
|
|
2955
2956
|
if (!r.get(c)) throw Error(`Cannot substitute {${t}}: cube '${c}' not found`);
|
|
@@ -2972,7 +2973,7 @@ function ft(e, t) {
|
|
|
2972
2973
|
for (let e = 0; e < s.length; e++) s[e] && u.push(new x(s[e])), e < c.length && u.push(c[e]);
|
|
2973
2974
|
return D.join(u, D.raw(""));
|
|
2974
2975
|
}
|
|
2975
|
-
function
|
|
2976
|
+
function mt(e) {
|
|
2976
2977
|
if (e.length > 1e3) return [];
|
|
2977
2978
|
let t = e.matchAll(/\{([^}]+)\}/g), n = [];
|
|
2978
2979
|
for (let e of t) {
|
|
@@ -2992,7 +2993,7 @@ function pt(e) {
|
|
|
2992
2993
|
}
|
|
2993
2994
|
return n;
|
|
2994
2995
|
}
|
|
2995
|
-
function
|
|
2996
|
+
function ht(e) {
|
|
2996
2997
|
let t = [], n = 0;
|
|
2997
2998
|
for (let r = 0; r < e.length; r++) if (e[r] === "{") n++;
|
|
2998
2999
|
else if (e[r] === "}" && (n--, n < 0)) {
|
|
@@ -3000,7 +3001,7 @@ function mt(e) {
|
|
|
3000
3001
|
break;
|
|
3001
3002
|
}
|
|
3002
3003
|
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");
|
|
3003
|
-
let r =
|
|
3004
|
+
let r = mt(e);
|
|
3004
3005
|
for (let e of r) {
|
|
3005
3006
|
let n = e.cubeName ? `${e.cubeName}.${e.fieldName}` : e.fieldName;
|
|
3006
3007
|
/^[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)`);
|
|
@@ -3010,8 +3011,8 @@ function mt(e) {
|
|
|
3010
3011
|
errors: t
|
|
3011
3012
|
};
|
|
3012
3013
|
}
|
|
3013
|
-
function
|
|
3014
|
-
let n =
|
|
3014
|
+
function gt(e, t) {
|
|
3015
|
+
let n = mt(e), r = /* @__PURE__ */ new Set();
|
|
3015
3016
|
for (let e of n) {
|
|
3016
3017
|
let n = `${e.cubeName || t}.${e.fieldName}`;
|
|
3017
3018
|
r.add(n);
|
|
@@ -3038,11 +3039,11 @@ var Q = class e {
|
|
|
3038
3039
|
n && c.add(n);
|
|
3039
3040
|
continue;
|
|
3040
3041
|
}
|
|
3041
|
-
Z.isCalculatedMeasure(d) ? (s.push(r),
|
|
3042
|
+
Z.isCalculatedMeasure(d) ? (s.push(r), gt(d.calculatedSql, t).forEach((e) => c.add(e)), l.getAllDependencies(r).forEach((e) => {
|
|
3042
3043
|
let [t, r] = e.split("."), i = n.get(t);
|
|
3043
3044
|
if (i && i.measures[r]) {
|
|
3044
3045
|
let e = i.measures[r];
|
|
3045
|
-
Z.isCalculatedMeasure(e) &&
|
|
3046
|
+
Z.isCalculatedMeasure(e) && gt(e.calculatedSql, t).forEach((e) => c.add(e));
|
|
3046
3047
|
}
|
|
3047
3048
|
})) : o.push(r);
|
|
3048
3049
|
}
|
|
@@ -3073,7 +3074,7 @@ var Q = class e {
|
|
|
3073
3074
|
}
|
|
3074
3075
|
buildCalculatedMeasure(e, t, n, r, i) {
|
|
3075
3076
|
if (!e.calculatedSql) throw Error(`Calculated measure '${t.name}.${e.name}' missing calculatedSql property`);
|
|
3076
|
-
return
|
|
3077
|
+
return pt(this.databaseAdapter.preprocessCalculatedTemplate(e.calculatedSql), {
|
|
3077
3078
|
cube: t,
|
|
3078
3079
|
allCubes: n,
|
|
3079
3080
|
resolvedMeasures: r,
|
|
@@ -3082,7 +3083,7 @@ var Q = class e {
|
|
|
3082
3083
|
}
|
|
3083
3084
|
buildCTECalculatedMeasure(e, t, n, r, i) {
|
|
3084
3085
|
if (!e.calculatedSql) throw Error(`Calculated measure '${t.name}.${e.name || "unknown"}' missing calculatedSql property`);
|
|
3085
|
-
let a = /* @__PURE__ */ new Map(), o =
|
|
3086
|
+
let a = /* @__PURE__ */ new Map(), o = gt(e.calculatedSql, t.name);
|
|
3086
3087
|
for (let e of o) {
|
|
3087
3088
|
let [t, i] = e.split("."), o = r.get(t);
|
|
3088
3089
|
if (o && o.measures[i]) {
|
|
@@ -3317,7 +3318,7 @@ var Q = class e {
|
|
|
3317
3318
|
let { postAggWindowMeasures: r } = e.categorizeForPostAggregation(t, n);
|
|
3318
3319
|
return r.length > 0;
|
|
3319
3320
|
}
|
|
3320
|
-
},
|
|
3321
|
+
}, _t = class {
|
|
3321
3322
|
constructor(e) {
|
|
3322
3323
|
this.dateTimeBuilder = e;
|
|
3323
3324
|
}
|
|
@@ -3416,13 +3417,13 @@ var Q = class e {
|
|
|
3416
3417
|
}
|
|
3417
3418
|
return i;
|
|
3418
3419
|
}
|
|
3419
|
-
},
|
|
3420
|
+
}, vt = class {
|
|
3420
3421
|
dateTimeBuilder;
|
|
3421
3422
|
filterBuilder;
|
|
3422
3423
|
groupByBuilder;
|
|
3423
3424
|
measureBuilder;
|
|
3424
3425
|
constructor(e) {
|
|
3425
|
-
this.dateTimeBuilder = new Y(e), this.filterBuilder = new X(e, this.dateTimeBuilder), this.groupByBuilder = new
|
|
3426
|
+
this.dateTimeBuilder = new Y(e), this.filterBuilder = new X(e, this.dateTimeBuilder), this.groupByBuilder = new _t(this.dateTimeBuilder), this.measureBuilder = new Q(e);
|
|
3426
3427
|
}
|
|
3427
3428
|
buildResolvedMeasures(e, t, n, r) {
|
|
3428
3429
|
return this.measureBuilder.buildResolvedMeasures(e, t, n, r);
|
|
@@ -3487,7 +3488,7 @@ var Q = class e {
|
|
|
3487
3488
|
if (s && s.dimensions[i] && e.dateRange) {
|
|
3488
3489
|
if (r?.preAggregationCTEs && r.preAggregationCTEs.some((e) => e.cube.name === t)) continue;
|
|
3489
3490
|
if (n.filterCache) {
|
|
3490
|
-
let t =
|
|
3491
|
+
let t = it(e.dimension, e.dateRange), r = n.filterCache.get(t);
|
|
3491
3492
|
if (r) {
|
|
3492
3493
|
a.push(r);
|
|
3493
3494
|
continue;
|
|
@@ -3596,7 +3597,7 @@ var Q = class e {
|
|
|
3596
3597
|
buildLogicalFilter(e, t, n) {
|
|
3597
3598
|
return this.filterBuilder.buildLogicalFilter(e, t, n);
|
|
3598
3599
|
}
|
|
3599
|
-
},
|
|
3600
|
+
}, yt = class {
|
|
3600
3601
|
cubes;
|
|
3601
3602
|
connectivityCache = /* @__PURE__ */ new Map();
|
|
3602
3603
|
reverseIndex;
|
|
@@ -3803,7 +3804,7 @@ var Q = class e {
|
|
|
3803
3804
|
buildJoinCondition(e, t, n) {
|
|
3804
3805
|
let r = [];
|
|
3805
3806
|
for (let i of e.on) {
|
|
3806
|
-
let e = t ? D`${D.identifier(t)}.${D.identifier(i.source.name)}` :
|
|
3807
|
+
let e = t ? D`${D.identifier(t)}.${D.identifier(i.source.name)}` : tt(i.source), a = n ? D`${D.identifier(n)}.${D.identifier(i.target.name)}` : tt(i.target), o = i.as || M;
|
|
3807
3808
|
r.push(o(e, a));
|
|
3808
3809
|
}
|
|
3809
3810
|
return P(...r);
|
|
@@ -3833,11 +3834,11 @@ var Q = class e {
|
|
|
3833
3834
|
setInCache(e, t) {
|
|
3834
3835
|
this.connectivityCache.set(e, { path: t });
|
|
3835
3836
|
}
|
|
3836
|
-
},
|
|
3837
|
+
}, bt = class {
|
|
3837
3838
|
resolverCache = /* @__PURE__ */ new WeakMap();
|
|
3838
3839
|
getResolver(e) {
|
|
3839
3840
|
let t = this.resolverCache.get(e);
|
|
3840
|
-
return t || (t = new
|
|
3841
|
+
return t || (t = new yt(e), this.resolverCache.set(e, t)), t;
|
|
3841
3842
|
}
|
|
3842
3843
|
analyzeCubeUsage(e) {
|
|
3843
3844
|
let t = /* @__PURE__ */ new Set();
|
|
@@ -3926,9 +3927,9 @@ var Q = class e {
|
|
|
3926
3927
|
if (s.has(n)) continue;
|
|
3927
3928
|
let c = e.get(n);
|
|
3928
3929
|
if (!c) throw Error(`Cube '${n}' not found`);
|
|
3929
|
-
let u = l ?
|
|
3930
|
+
let u = l ? $e(i.relationship) : i.relationship;
|
|
3930
3931
|
if (u === "belongsToMany" && i.through) {
|
|
3931
|
-
let e =
|
|
3932
|
+
let e = rt(i, r.securityContext);
|
|
3932
3933
|
o.push({
|
|
3933
3934
|
cube: c,
|
|
3934
3935
|
alias: `${n.toLowerCase()}_cube`,
|
|
@@ -3945,7 +3946,7 @@ var Q = class e {
|
|
|
3945
3946
|
}
|
|
3946
3947
|
});
|
|
3947
3948
|
} else {
|
|
3948
|
-
let e = a.buildJoinCondition(i, null, null), t =
|
|
3949
|
+
let e = a.buildJoinCondition(i, null, null), t = et(u, i.sqlJoinType);
|
|
3949
3950
|
o.push({
|
|
3950
3951
|
cube: c,
|
|
3951
3952
|
alias: `${n.toLowerCase()}_cube`,
|
|
@@ -4041,7 +4042,7 @@ var Q = class e {
|
|
|
4041
4042
|
joinDef: e.joinDef,
|
|
4042
4043
|
reversed: e.reversed
|
|
4043
4044
|
}));
|
|
4044
|
-
if (!c.slice(0, -1).some((e) => (e.reversed ?
|
|
4045
|
+
if (!c.slice(0, -1).some((e) => (e.reversed ? $e(e.joinDef.relationship) : e.joinDef.relationship) === "hasMany")) return {
|
|
4045
4046
|
path: c,
|
|
4046
4047
|
hasIntermediateHasMany: !1,
|
|
4047
4048
|
intermediateJoins: [],
|
|
@@ -4345,7 +4346,7 @@ var Q = class e {
|
|
|
4345
4346
|
}
|
|
4346
4347
|
convertInternalPathToJoinPathSteps(e) {
|
|
4347
4348
|
return e.map((e) => {
|
|
4348
|
-
let t = e.reversed ?
|
|
4349
|
+
let t = e.reversed ? $e(e.joinDef.relationship) : e.joinDef.relationship, n = et(t, e.joinDef.sqlJoinType), r = e.joinDef.on.map((e) => ({
|
|
4349
4350
|
sourceColumn: e.source.name,
|
|
4350
4351
|
targetColumn: e.target.name
|
|
4351
4352
|
})), i = {
|
|
@@ -4410,7 +4411,7 @@ var Q = class e {
|
|
|
4410
4411
|
suggestion: "Add a dimension to see per-group breakdowns, or add a time dimension with granularity."
|
|
4411
4412
|
};
|
|
4412
4413
|
}
|
|
4413
|
-
},
|
|
4414
|
+
}, xt = class {
|
|
4414
4415
|
constructor(e) {
|
|
4415
4416
|
this.queryBuilder = e;
|
|
4416
4417
|
}
|
|
@@ -4562,13 +4563,128 @@ var Q = class e {
|
|
|
4562
4563
|
}
|
|
4563
4564
|
};
|
|
4564
4565
|
//#endregion
|
|
4566
|
+
//#region src/shared/date-utils.ts
|
|
4567
|
+
function St(e) {
|
|
4568
|
+
let t = /* @__PURE__ */ new Date(), n = e.toLowerCase().trim(), r = t.getUTCFullYear(), i = t.getUTCMonth(), a = t.getUTCDate(), o = t.getUTCDay();
|
|
4569
|
+
if (n === "today") {
|
|
4570
|
+
let e = new Date(t);
|
|
4571
|
+
e.setUTCHours(0, 0, 0, 0);
|
|
4572
|
+
let n = new Date(t);
|
|
4573
|
+
return n.setUTCHours(23, 59, 59, 999), {
|
|
4574
|
+
start: e,
|
|
4575
|
+
end: n
|
|
4576
|
+
};
|
|
4577
|
+
}
|
|
4578
|
+
if (n === "yesterday") {
|
|
4579
|
+
let e = new Date(t);
|
|
4580
|
+
e.setUTCDate(a - 1), e.setUTCHours(0, 0, 0, 0);
|
|
4581
|
+
let n = new Date(t);
|
|
4582
|
+
return n.setUTCDate(a - 1), n.setUTCHours(23, 59, 59, 999), {
|
|
4583
|
+
start: e,
|
|
4584
|
+
end: n
|
|
4585
|
+
};
|
|
4586
|
+
}
|
|
4587
|
+
if (n === "this week") {
|
|
4588
|
+
let e = o === 0 ? -6 : 1 - o, n = new Date(t);
|
|
4589
|
+
n.setUTCDate(a + e), n.setUTCHours(0, 0, 0, 0);
|
|
4590
|
+
let r = new Date(n);
|
|
4591
|
+
return r.setUTCDate(n.getUTCDate() + 6), r.setUTCHours(23, 59, 59, 999), {
|
|
4592
|
+
start: n,
|
|
4593
|
+
end: r
|
|
4594
|
+
};
|
|
4595
|
+
}
|
|
4596
|
+
if (n === "this month") return {
|
|
4597
|
+
start: new Date(Date.UTC(r, i, 1, 0, 0, 0, 0)),
|
|
4598
|
+
end: new Date(Date.UTC(r, i + 1, 0, 23, 59, 59, 999))
|
|
4599
|
+
};
|
|
4600
|
+
if (n === "this quarter") {
|
|
4601
|
+
let e = Math.floor(i / 3);
|
|
4602
|
+
return {
|
|
4603
|
+
start: new Date(Date.UTC(r, e * 3, 1, 0, 0, 0, 0)),
|
|
4604
|
+
end: new Date(Date.UTC(r, e * 3 + 3, 0, 23, 59, 59, 999))
|
|
4605
|
+
};
|
|
4606
|
+
}
|
|
4607
|
+
if (n === "this year") return {
|
|
4608
|
+
start: new Date(Date.UTC(r, 0, 1, 0, 0, 0, 0)),
|
|
4609
|
+
end: new Date(Date.UTC(r, 11, 31, 23, 59, 59, 999))
|
|
4610
|
+
};
|
|
4611
|
+
let s = n.match(/^last\s+(\d+)\s+days?$/);
|
|
4612
|
+
if (s) {
|
|
4613
|
+
let e = parseInt(s[1], 10), n = new Date(t);
|
|
4614
|
+
n.setUTCDate(a - e + 1), n.setUTCHours(0, 0, 0, 0);
|
|
4615
|
+
let r = new Date(t);
|
|
4616
|
+
return r.setUTCHours(23, 59, 59, 999), {
|
|
4617
|
+
start: n,
|
|
4618
|
+
end: r
|
|
4619
|
+
};
|
|
4620
|
+
}
|
|
4621
|
+
let c = n.match(/^last\s+(\d+)\s+weeks?$/);
|
|
4622
|
+
if (c) {
|
|
4623
|
+
let e = parseInt(c[1], 10) * 7, n = new Date(t);
|
|
4624
|
+
n.setUTCDate(a - e + 1), n.setUTCHours(0, 0, 0, 0);
|
|
4625
|
+
let r = new Date(t);
|
|
4626
|
+
return r.setUTCHours(23, 59, 59, 999), {
|
|
4627
|
+
start: n,
|
|
4628
|
+
end: r
|
|
4629
|
+
};
|
|
4630
|
+
}
|
|
4631
|
+
if (n === "last week") {
|
|
4632
|
+
let e = o === 0 ? -13 : -6 - o, n = new Date(t);
|
|
4633
|
+
n.setUTCDate(a + e), n.setUTCHours(0, 0, 0, 0);
|
|
4634
|
+
let r = new Date(n);
|
|
4635
|
+
return r.setUTCDate(n.getUTCDate() + 6), r.setUTCHours(23, 59, 59, 999), {
|
|
4636
|
+
start: n,
|
|
4637
|
+
end: r
|
|
4638
|
+
};
|
|
4639
|
+
}
|
|
4640
|
+
if (n === "last month") return {
|
|
4641
|
+
start: new Date(Date.UTC(r, i - 1, 1, 0, 0, 0, 0)),
|
|
4642
|
+
end: new Date(Date.UTC(r, i, 0, 23, 59, 59, 999))
|
|
4643
|
+
};
|
|
4644
|
+
if (n === "last quarter") {
|
|
4645
|
+
let e = Math.floor(i / 3), t = e === 0 ? 3 : e - 1, n = e === 0 ? r - 1 : r;
|
|
4646
|
+
return {
|
|
4647
|
+
start: new Date(Date.UTC(n, t * 3, 1, 0, 0, 0, 0)),
|
|
4648
|
+
end: new Date(Date.UTC(n, t * 3 + 3, 0, 23, 59, 59, 999))
|
|
4649
|
+
};
|
|
4650
|
+
}
|
|
4651
|
+
if (n === "last year") return {
|
|
4652
|
+
start: new Date(Date.UTC(r - 1, 0, 1, 0, 0, 0, 0)),
|
|
4653
|
+
end: new Date(Date.UTC(r - 1, 11, 31, 23, 59, 59, 999))
|
|
4654
|
+
};
|
|
4655
|
+
if (n === "last 12 months") {
|
|
4656
|
+
let e = new Date(Date.UTC(r, i - 11, 1, 0, 0, 0, 0)), n = new Date(t);
|
|
4657
|
+
return n.setUTCHours(23, 59, 59, 999), {
|
|
4658
|
+
start: e,
|
|
4659
|
+
end: n
|
|
4660
|
+
};
|
|
4661
|
+
}
|
|
4662
|
+
let l = n.match(/^last\s+(\d+)\s+months?$/);
|
|
4663
|
+
if (l) {
|
|
4664
|
+
let e = parseInt(l[1], 10), n = new Date(Date.UTC(r, i - e + 1, 1, 0, 0, 0, 0)), a = new Date(t);
|
|
4665
|
+
return a.setUTCHours(23, 59, 59, 999), {
|
|
4666
|
+
start: n,
|
|
4667
|
+
end: a
|
|
4668
|
+
};
|
|
4669
|
+
}
|
|
4670
|
+
let u = n.match(/^last\s+(\d+)\s+years?$/);
|
|
4671
|
+
if (u) {
|
|
4672
|
+
let e = parseInt(u[1], 10), n = new Date(Date.UTC(r - e, 0, 1, 0, 0, 0, 0)), i = new Date(t);
|
|
4673
|
+
return i.setUTCHours(23, 59, 59, 999), {
|
|
4674
|
+
start: n,
|
|
4675
|
+
end: i
|
|
4676
|
+
};
|
|
4677
|
+
}
|
|
4678
|
+
return null;
|
|
4679
|
+
}
|
|
4680
|
+
//#endregion
|
|
4565
4681
|
//#region src/server/gap-filler.ts
|
|
4566
|
-
function
|
|
4567
|
-
let r = [], i =
|
|
4568
|
-
for (; i <= a && r.length < 1e4;) r.push(new Date(i)), i =
|
|
4682
|
+
function Ct(e, t, n) {
|
|
4683
|
+
let r = [], i = wt(new Date(e), n), a = wt(new Date(t), n);
|
|
4684
|
+
for (; i <= a && r.length < 1e4;) r.push(new Date(i)), i = Tt(i, n);
|
|
4569
4685
|
return r;
|
|
4570
4686
|
}
|
|
4571
|
-
function
|
|
4687
|
+
function wt(e, t) {
|
|
4572
4688
|
let n = new Date(e);
|
|
4573
4689
|
switch (t) {
|
|
4574
4690
|
case "second":
|
|
@@ -4602,7 +4718,7 @@ function St(e, t) {
|
|
|
4602
4718
|
}
|
|
4603
4719
|
return n;
|
|
4604
4720
|
}
|
|
4605
|
-
function
|
|
4721
|
+
function Tt(e, t) {
|
|
4606
4722
|
let n = new Date(e);
|
|
4607
4723
|
switch (t) {
|
|
4608
4724
|
case "second":
|
|
@@ -4632,7 +4748,7 @@ function Ct(e, t) {
|
|
|
4632
4748
|
}
|
|
4633
4749
|
return n;
|
|
4634
4750
|
}
|
|
4635
|
-
function
|
|
4751
|
+
function Et(e) {
|
|
4636
4752
|
if (e instanceof Date) return e.toISOString();
|
|
4637
4753
|
if (typeof e == "string") {
|
|
4638
4754
|
let t = new Date(e);
|
|
@@ -4640,15 +4756,15 @@ function wt(e) {
|
|
|
4640
4756
|
}
|
|
4641
4757
|
return String(e);
|
|
4642
4758
|
}
|
|
4643
|
-
function
|
|
4759
|
+
function Dt(e, t) {
|
|
4644
4760
|
return t.length === 0 ? "__all__" : t.map((t) => String(e[t] ?? "")).join("|||");
|
|
4645
4761
|
}
|
|
4646
|
-
function
|
|
4647
|
-
let { timeDimensionKey: n, granularity: r, dateRange: i, fillValue: a, measures: o, dimensions: s } = t, c =
|
|
4762
|
+
function Ot(e, t) {
|
|
4763
|
+
let { timeDimensionKey: n, granularity: r, dateRange: i, fillValue: a, measures: o, dimensions: s } = t, c = Ct(i[0], i[1], r);
|
|
4648
4764
|
if (c.length === 0) return e;
|
|
4649
4765
|
let l = /* @__PURE__ */ new Map();
|
|
4650
4766
|
for (let t of e) {
|
|
4651
|
-
let e =
|
|
4767
|
+
let e = Dt(t, s), r = Et(t[n]);
|
|
4652
4768
|
l.has(e) || l.set(e, /* @__PURE__ */ new Map()), l.get(e).set(r, t);
|
|
4653
4769
|
}
|
|
4654
4770
|
l.size === 0 && s.length === 0 && l.set("__all__", /* @__PURE__ */ new Map());
|
|
@@ -4668,42 +4784,74 @@ function Et(e, t) {
|
|
|
4668
4784
|
}
|
|
4669
4785
|
return u;
|
|
4670
4786
|
}
|
|
4671
|
-
function
|
|
4787
|
+
function kt(e) {
|
|
4672
4788
|
if (!e) return null;
|
|
4673
4789
|
if (Array.isArray(e)) {
|
|
4674
4790
|
if (e.length < 2) return null;
|
|
4675
4791
|
let t = new Date(e[0]), n = new Date(e[1]);
|
|
4676
4792
|
return isNaN(t.getTime()) || isNaN(n.getTime()) ? null : [t, n];
|
|
4677
4793
|
}
|
|
4678
|
-
let t =
|
|
4679
|
-
|
|
4794
|
+
let t = St(e);
|
|
4795
|
+
if (t) return [t.start, t.end];
|
|
4796
|
+
let n = new Date(e);
|
|
4797
|
+
return isNaN(n.getTime()) ? null : [n, n];
|
|
4680
4798
|
}
|
|
4681
|
-
function
|
|
4799
|
+
function At(e, t, n) {
|
|
4682
4800
|
if (!t.timeDimensions || t.timeDimensions.length === 0) return e;
|
|
4683
4801
|
let r = t.timeDimensions.filter((e) => {
|
|
4684
|
-
let
|
|
4685
|
-
return
|
|
4802
|
+
let n = e.fillMissingDates !== !1, r = !!e.granularity, i = e.dateRange || jt(e.dimension, t.filters);
|
|
4803
|
+
return n && r && i;
|
|
4686
4804
|
});
|
|
4687
4805
|
if (r.length === 0) return e;
|
|
4688
4806
|
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;
|
|
4689
4807
|
for (let e of r) {
|
|
4690
|
-
let
|
|
4691
|
-
if (!
|
|
4692
|
-
let
|
|
4808
|
+
let r = kt(e.dateRange) || Mt(e.dimension, t.filters);
|
|
4809
|
+
if (!r) continue;
|
|
4810
|
+
let a = {
|
|
4693
4811
|
timeDimensionKey: e.dimension,
|
|
4694
4812
|
granularity: e.granularity,
|
|
4695
|
-
dateRange:
|
|
4813
|
+
dateRange: r,
|
|
4696
4814
|
fillValue: i,
|
|
4697
4815
|
measures: n,
|
|
4698
4816
|
dimensions: o
|
|
4699
4817
|
};
|
|
4700
|
-
s =
|
|
4818
|
+
s = Ot(s, a);
|
|
4701
4819
|
}
|
|
4702
4820
|
return s;
|
|
4703
4821
|
}
|
|
4822
|
+
function jt(e, t) {
|
|
4823
|
+
if (!t) return null;
|
|
4824
|
+
for (let n of t) {
|
|
4825
|
+
if ("member" in n && "operator" in n && n.member === e && n.operator === "inDateRange") return n;
|
|
4826
|
+
if ("and" in n && n.and) {
|
|
4827
|
+
let t = jt(e, n.and);
|
|
4828
|
+
if (t) return t;
|
|
4829
|
+
}
|
|
4830
|
+
if ("or" in n && n.or) {
|
|
4831
|
+
let t = jt(e, n.or);
|
|
4832
|
+
if (t) return t;
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
return null;
|
|
4836
|
+
}
|
|
4837
|
+
function Mt(e, t) {
|
|
4838
|
+
let n = jt(e, t);
|
|
4839
|
+
if (!n) return null;
|
|
4840
|
+
if (n.dateRange) {
|
|
4841
|
+
let e = kt(n.dateRange);
|
|
4842
|
+
if (e) return e;
|
|
4843
|
+
}
|
|
4844
|
+
let r = n.values;
|
|
4845
|
+
if (!r || r.length === 0) return null;
|
|
4846
|
+
if (r.length === 1 && typeof r[0] == "string") {
|
|
4847
|
+
let e = St(r[0]);
|
|
4848
|
+
return e ? [e.start, e.end] : kt(r);
|
|
4849
|
+
}
|
|
4850
|
+
return r.length >= 2 ? kt(r) : null;
|
|
4851
|
+
}
|
|
4704
4852
|
//#endregion
|
|
4705
4853
|
//#region src/server/builders/comparison-query-builder.ts
|
|
4706
|
-
var
|
|
4854
|
+
var Nt = class {
|
|
4707
4855
|
dateTimeBuilder;
|
|
4708
4856
|
constructor(e) {
|
|
4709
4857
|
this.dateTimeBuilder = new Y(e);
|
|
@@ -4834,7 +4982,7 @@ var kt = class {
|
|
|
4834
4982
|
return typeof i == "string" && typeof a == "string" ? new Date(i).getTime() - new Date(a).getTime() : 0;
|
|
4835
4983
|
});
|
|
4836
4984
|
}
|
|
4837
|
-
},
|
|
4985
|
+
}, Pt = class {
|
|
4838
4986
|
filterBuilder;
|
|
4839
4987
|
dateTimeBuilder;
|
|
4840
4988
|
constructor(e) {
|
|
@@ -4873,7 +5021,7 @@ var kt = class {
|
|
|
4873
5021
|
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) {
|
|
4874
5022
|
let a;
|
|
4875
5023
|
"cube" in i && i.cube ? a = i.cube : typeof e.bindingKey == "string" && ([a] = e.bindingKey.split("."));
|
|
4876
|
-
let o = a ? new
|
|
5024
|
+
let o = a ? new yt(t) : null, s = Array.isArray(i.filter) ? i.filter : [i.filter];
|
|
4877
5025
|
for (let e of s) if ("member" in e) {
|
|
4878
5026
|
let [i, s] = e.member.split("."), c = t.get(i);
|
|
4879
5027
|
if (!c) n.push(`Step ${r} filter cube not found: ${i}`);
|
|
@@ -4936,7 +5084,7 @@ var kt = class {
|
|
|
4936
5084
|
return t;
|
|
4937
5085
|
}
|
|
4938
5086
|
resolveSteps(e, t, n) {
|
|
4939
|
-
let r = new
|
|
5087
|
+
let r = new yt(t);
|
|
4940
5088
|
return e.steps.map((i, a) => {
|
|
4941
5089
|
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 = [];
|
|
4942
5090
|
for (let e of u) if (e !== o.name) {
|
|
@@ -5034,7 +5182,7 @@ var kt = class {
|
|
|
5034
5182
|
let u = n.get(s);
|
|
5035
5183
|
if (!u) return null;
|
|
5036
5184
|
if (s !== t.name) {
|
|
5037
|
-
let e = new
|
|
5185
|
+
let e = new yt(n).findPath(t.name, s);
|
|
5038
5186
|
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;
|
|
5039
5187
|
}
|
|
5040
5188
|
let d = u.dimensions?.[c];
|
|
@@ -5115,7 +5263,7 @@ var kt = class {
|
|
|
5115
5263
|
let o = i.db.select(a).from(e);
|
|
5116
5264
|
return i.db.$with("funnel_metrics").as(o);
|
|
5117
5265
|
}
|
|
5118
|
-
},
|
|
5266
|
+
}, Ft = class {
|
|
5119
5267
|
filterBuilder;
|
|
5120
5268
|
dateTimeBuilder;
|
|
5121
5269
|
databaseAdapter;
|
|
@@ -5579,27 +5727,27 @@ var kt = class {
|
|
|
5579
5727
|
};
|
|
5580
5728
|
//#endregion
|
|
5581
5729
|
//#region src/server/types/retention.ts
|
|
5582
|
-
function
|
|
5730
|
+
function It(e) {
|
|
5583
5731
|
return Array.isArray(e);
|
|
5584
5732
|
}
|
|
5585
|
-
function
|
|
5733
|
+
function Lt(e) {
|
|
5586
5734
|
return typeof e == "object" && !!e && "cube" in e;
|
|
5587
5735
|
}
|
|
5588
|
-
function
|
|
5589
|
-
if (
|
|
5736
|
+
function Rt(e) {
|
|
5737
|
+
if (Lt(e)) return e.cube;
|
|
5590
5738
|
let t = e.indexOf(".");
|
|
5591
5739
|
if (t === -1) throw Error(`Invalid time dimension format: ${e}. Expected 'CubeName.dimensionName'`);
|
|
5592
5740
|
return e.substring(0, t);
|
|
5593
5741
|
}
|
|
5594
|
-
function
|
|
5595
|
-
if (
|
|
5742
|
+
function zt(e) {
|
|
5743
|
+
if (Lt(e)) return e.dimension;
|
|
5596
5744
|
let t = e.indexOf(".");
|
|
5597
5745
|
if (t === -1) throw Error(`Invalid time dimension format: ${e}. Expected 'CubeName.dimensionName'`);
|
|
5598
5746
|
return e.substring(t + 1);
|
|
5599
5747
|
}
|
|
5600
5748
|
//#endregion
|
|
5601
5749
|
//#region src/server/builders/retention-query-builder.ts
|
|
5602
|
-
var
|
|
5750
|
+
var Bt = class {
|
|
5603
5751
|
filterBuilder;
|
|
5604
5752
|
dateTimeBuilder;
|
|
5605
5753
|
constructor(e) {
|
|
@@ -5611,12 +5759,12 @@ var It = class {
|
|
|
5611
5759
|
validateConfig(e, t) {
|
|
5612
5760
|
let n = [];
|
|
5613
5761
|
try {
|
|
5614
|
-
let r =
|
|
5762
|
+
let r = Rt(e.timeDimension), i = zt(e.timeDimension), a = t.get(r);
|
|
5615
5763
|
a ? a.dimensions?.[i] || n.push(`Time dimension not found: ${i} in cube ${r}`) : n.push(`Cube not found: ${r}`);
|
|
5616
5764
|
} catch {
|
|
5617
5765
|
n.push(`Invalid time dimension format: ${e.timeDimension}`);
|
|
5618
5766
|
}
|
|
5619
|
-
if (
|
|
5767
|
+
if (It(e.bindingKey)) for (let r of e.bindingKey) {
|
|
5620
5768
|
let e = t.get(r.cube);
|
|
5621
5769
|
if (!e) n.push(`Binding key mapping cube not found: ${r.cube}`);
|
|
5622
5770
|
else {
|
|
@@ -5704,7 +5852,7 @@ var It = class {
|
|
|
5704
5852
|
});
|
|
5705
5853
|
}
|
|
5706
5854
|
resolveConfig(e, t, n) {
|
|
5707
|
-
let r =
|
|
5855
|
+
let r = Rt(e.timeDimension), i = zt(e.timeDimension), a = t.get(r);
|
|
5708
5856
|
if (!a) throw Error(`Cube not found: ${r}`);
|
|
5709
5857
|
let o = a.dimensions?.[i];
|
|
5710
5858
|
if (!o) throw Error(`Time dimension not found: ${i}`);
|
|
@@ -5729,7 +5877,7 @@ var It = class {
|
|
|
5729
5877
|
};
|
|
5730
5878
|
}
|
|
5731
5879
|
resolveBindingKey(e, t, n, r) {
|
|
5732
|
-
if (
|
|
5880
|
+
if (It(e)) {
|
|
5733
5881
|
let i = e.find((e) => e.cube === t.name);
|
|
5734
5882
|
if (!i) throw Error(`No binding key mapping found for cube: ${t.name}`);
|
|
5735
5883
|
let a = this.extractDimensionName(i.dimension), o = n.get(i.cube);
|
|
@@ -5868,7 +6016,7 @@ var It = class {
|
|
|
5868
6016
|
let t = e.split(".");
|
|
5869
6017
|
return t.length > 1 ? t[1] : t[0];
|
|
5870
6018
|
}
|
|
5871
|
-
},
|
|
6019
|
+
}, Vt = class {
|
|
5872
6020
|
constructor(e) {
|
|
5873
6021
|
this.queryPlanner = e;
|
|
5874
6022
|
}
|
|
@@ -6303,7 +6451,7 @@ var It = class {
|
|
|
6303
6451
|
timeDimensions: []
|
|
6304
6452
|
};
|
|
6305
6453
|
}
|
|
6306
|
-
},
|
|
6454
|
+
}, Ht = class {
|
|
6307
6455
|
name = "identity";
|
|
6308
6456
|
optimise(e) {
|
|
6309
6457
|
return e;
|
|
@@ -6311,7 +6459,7 @@ var It = class {
|
|
|
6311
6459
|
};
|
|
6312
6460
|
//#endregion
|
|
6313
6461
|
//#region src/server/physical-plan/processors/cte-processor.ts
|
|
6314
|
-
function
|
|
6462
|
+
function Ut(e, t, n, r) {
|
|
6315
6463
|
let i = /* @__PURE__ */ new Map();
|
|
6316
6464
|
if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0) {
|
|
6317
6465
|
for (let t of e.preAggregationCTEs) if (t.propagatingFilters && t.propagatingFilters.length > 0) for (let e of t.propagatingFilters) {
|
|
@@ -6341,7 +6489,7 @@ function zt(e, t, n, r) {
|
|
|
6341
6489
|
}
|
|
6342
6490
|
//#endregion
|
|
6343
6491
|
//#region src/server/physical-plan/processors/window-processor.ts
|
|
6344
|
-
function
|
|
6492
|
+
function Wt(e, t, n, r, i, a) {
|
|
6345
6493
|
if (n.measures) for (let o of n.measures) {
|
|
6346
6494
|
let [s, c] = o.split("."), l = i.get(s);
|
|
6347
6495
|
if (!l?.measures?.[c]) continue;
|
|
@@ -6353,11 +6501,11 @@ function Bt(e, t, n, r, i, a) {
|
|
|
6353
6501
|
if (!m?.measures?.[p]) continue;
|
|
6354
6502
|
let h = m.measures[p], g = t.preAggregationCTEs?.find((e) => e.cube?.name === f && e.measures?.includes(d)), _;
|
|
6355
6503
|
_ = g ? D`sum(${D`${D.identifier(g.cteAlias)}.${D.identifier(p)}`})` : a.queryBuilder.buildMeasureExpression(h, r, m), e[d] || (e[d] = D`${_}`.as(d));
|
|
6356
|
-
let v =
|
|
6504
|
+
let v = Gt(u, _, n, r, l, t, a);
|
|
6357
6505
|
v && (e[o] = D`${v}`.as(o));
|
|
6358
6506
|
}
|
|
6359
6507
|
}
|
|
6360
|
-
function
|
|
6508
|
+
function Gt(e, t, n, r, i, a, o) {
|
|
6361
6509
|
let s = e.windowConfig || {}, c = (e, t) => {
|
|
6362
6510
|
if (!a.preAggregationCTEs) return null;
|
|
6363
6511
|
let n = a.preAggregationCTEs.find((t) => t.cube?.name === e);
|
|
@@ -6427,7 +6575,7 @@ function Vt(e, t, n, r, i, a, o) {
|
|
|
6427
6575
|
}
|
|
6428
6576
|
//#endregion
|
|
6429
6577
|
//#region src/server/physical-plan/processors/selection-processor.ts
|
|
6430
|
-
function
|
|
6578
|
+
function Kt(e, t, n, r, i) {
|
|
6431
6579
|
let a = { ...i.queryBuilder.buildSelections(e.joinCubes.length > 0 ? r : e.primaryCube, t, n) };
|
|
6432
6580
|
if (e.preAggregationCTEs) for (let o of e.preAggregationCTEs) {
|
|
6433
6581
|
let e = o.cube.name;
|
|
@@ -6438,7 +6586,7 @@ function Ht(e, t, n, r, i) {
|
|
|
6438
6586
|
let u = l.measures[c], d = D`${D.identifier(o.cteAlias)}.${D.identifier(c)}`, f;
|
|
6439
6587
|
if (u.type === "calculated" && u.calculatedSql) f = i.queryBuilder.buildCTECalculatedMeasure(u, l, o, r, n);
|
|
6440
6588
|
else {
|
|
6441
|
-
let e = o.cteReason === "fanOutPrevention", n =
|
|
6589
|
+
let e = o.cteReason === "fanOutPrevention", n = qt(o, t, r), a = e || n;
|
|
6442
6590
|
switch (u.type) {
|
|
6443
6591
|
case "count":
|
|
6444
6592
|
case "countDistinct":
|
|
@@ -6475,12 +6623,12 @@ function Ht(e, t, n, r, i) {
|
|
|
6475
6623
|
(u || l && s?.dimensions?.[i]) && (a[t] = D`${D.identifier(o.cteAlias)}.${D.identifier(i)}`.as(t));
|
|
6476
6624
|
}
|
|
6477
6625
|
}
|
|
6478
|
-
return
|
|
6626
|
+
return Wt(a, e, t, n, r, i), a;
|
|
6479
6627
|
}
|
|
6480
|
-
function
|
|
6481
|
-
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 &&
|
|
6628
|
+
function qt(e, t, n) {
|
|
6629
|
+
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 && Jt(e.sourceColumnObj, t, n));
|
|
6482
6630
|
}
|
|
6483
|
-
function
|
|
6631
|
+
function Jt(e, t, n) {
|
|
6484
6632
|
if (t.dimensions) for (let r of t.dimensions) {
|
|
6485
6633
|
let [t, i] = r.split(".");
|
|
6486
6634
|
if (n.get(t)?.dimensions?.[i]?.sql === e) return !0;
|
|
@@ -6494,7 +6642,7 @@ function Wt(e, t, n) {
|
|
|
6494
6642
|
}
|
|
6495
6643
|
//#endregion
|
|
6496
6644
|
//#region src/server/physical-plan/processors/joins-processor.ts
|
|
6497
|
-
function
|
|
6645
|
+
function Yt(e, t, n, r, i, a) {
|
|
6498
6646
|
let o = [], s = t.db.select(r).from(n.from);
|
|
6499
6647
|
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") {
|
|
6500
6648
|
case "left":
|
|
@@ -6594,7 +6742,7 @@ function Gt(e, t, n, r, i, a) {
|
|
|
6594
6742
|
}
|
|
6595
6743
|
//#endregion
|
|
6596
6744
|
//#region src/server/physical-plan/processors/predicates-processor.ts
|
|
6597
|
-
function
|
|
6745
|
+
function Xt(e, t, n, r, i, a, o, s) {
|
|
6598
6746
|
let c = [...o.allWhereConditions];
|
|
6599
6747
|
if (i.where && c.push(i.where), e.joinCubes && e.joinCubes.length > 0) for (let t of e.joinCubes) {
|
|
6600
6748
|
let e = t.cube.name;
|
|
@@ -6622,14 +6770,14 @@ function Kt(e, t, n, r, i, a, o, s) {
|
|
|
6622
6770
|
}
|
|
6623
6771
|
//#endregion
|
|
6624
6772
|
//#region src/server/physical-plan/processors/shared.ts
|
|
6625
|
-
function
|
|
6773
|
+
function Zt(e) {
|
|
6626
6774
|
let t = /* @__PURE__ */ new Map();
|
|
6627
6775
|
if (t.set(e.primaryCube.name, e.primaryCube), e.joinCubes) for (let n of e.joinCubes) t.set(n.cube.name, n.cube);
|
|
6628
6776
|
return t;
|
|
6629
6777
|
}
|
|
6630
6778
|
//#endregion
|
|
6631
6779
|
//#region src/server/physical-plan/drizzle-plan-builder.ts
|
|
6632
|
-
var
|
|
6780
|
+
var Qt = class {
|
|
6633
6781
|
constructor(e, t, n) {
|
|
6634
6782
|
this.queryBuilder = e, this.cteBuilder = t, this.databaseAdapter = n;
|
|
6635
6783
|
}
|
|
@@ -6769,13 +6917,13 @@ var Jt = class {
|
|
|
6769
6917
|
if (i) return i;
|
|
6770
6918
|
let a = this.tryBuildKeysDeduplicationQuery(e, t, n, r);
|
|
6771
6919
|
if (a) return a;
|
|
6772
|
-
let o =
|
|
6773
|
-
return
|
|
6920
|
+
let o = Ut(e, t, n, r), s = e.primaryCube.sql(n), c = e.joinCubes.length > 0 ? Zt(e) : new Map([[e.primaryCube.name, e.primaryCube]]);
|
|
6921
|
+
return Xt(e, t, n, c, s, o, Yt(e, n, s, Kt(e, t, n, c, r), o, r), r);
|
|
6774
6922
|
}
|
|
6775
6923
|
tryBuildKeysDeduplicationQuery(e, t, n, r) {
|
|
6776
6924
|
let i = e.keysDeduplication;
|
|
6777
6925
|
if (!i?.multipliedCubeName || !t.measures?.length) return null;
|
|
6778
|
-
let a = e.joinCubes.length > 0 ?
|
|
6926
|
+
let a = e.joinCubes.length > 0 ? Zt(e) : new Map([[e.primaryCube.name, e.primaryCube]]), o = a.get(i.multipliedCubeName);
|
|
6779
6927
|
if (!o || !this.canExecuteKeysDeduplication(t, o, i.multipliedCubeName)) return null;
|
|
6780
6928
|
let s = i.primaryKeyDimensions.length > 0 ? i.primaryKeyDimensions : this.getPrimaryKeyDimensions(o);
|
|
6781
6929
|
if (s.length === 0) return null;
|
|
@@ -6994,7 +7142,7 @@ function $(e, t) {
|
|
|
6994
7142
|
console.log(`\n[DC_DEBUG] ${e}`), console.log(n), r.length > 0 && console.log("params:", r), console.log();
|
|
6995
7143
|
} catch {}
|
|
6996
7144
|
}
|
|
6997
|
-
var
|
|
7145
|
+
var $t = class {
|
|
6998
7146
|
queryBuilder;
|
|
6999
7147
|
drizzlePlanBuilder;
|
|
7000
7148
|
databaseAdapter;
|
|
@@ -7008,9 +7156,9 @@ var Yt = class {
|
|
|
7008
7156
|
rlsSetup;
|
|
7009
7157
|
constructor(e, t, n) {
|
|
7010
7158
|
if (this.dbExecutor = e, this.databaseAdapter = e.databaseAdapter, !this.databaseAdapter) throw Error("DatabaseExecutor must have a databaseAdapter property");
|
|
7011
|
-
this.queryBuilder = new
|
|
7012
|
-
let r = new
|
|
7013
|
-
this.drizzlePlanBuilder = new
|
|
7159
|
+
this.queryBuilder = new vt(this.databaseAdapter);
|
|
7160
|
+
let r = new bt(), i = new xt(this.queryBuilder);
|
|
7161
|
+
this.drizzlePlanBuilder = new Qt(this.queryBuilder, i, this.databaseAdapter), this.comparisonQueryBuilder = new Nt(this.databaseAdapter), this.funnelQueryBuilder = new Pt(this.databaseAdapter), this.flowQueryBuilder = new Ft(this.databaseAdapter), this.retentionQueryBuilder = new Bt(this.databaseAdapter), this.logicalPlanBuilder = new Vt(r), this.planOptimiser = new Ht(), this.cacheConfig = t, this.rlsSetup = n;
|
|
7014
7162
|
}
|
|
7015
7163
|
async withRLSContext(e, t) {
|
|
7016
7164
|
if (!this.rlsSetup) return t();
|
|
@@ -7028,7 +7176,7 @@ var Yt = class {
|
|
|
7028
7176
|
let i = this.resolveQueryMode(t);
|
|
7029
7177
|
this.validateQueryForMode(i, e, t);
|
|
7030
7178
|
let a;
|
|
7031
|
-
if (this.cacheConfig?.enabled !== !1 && this.cacheConfig?.provider) if (a =
|
|
7179
|
+
if (this.cacheConfig?.enabled !== !1 && this.cacheConfig?.provider) if (a = ot(t, n, this.cacheConfig), r?.skipCache) this.cacheConfig.onCacheEvent?.({
|
|
7032
7180
|
type: "miss",
|
|
7033
7181
|
key: a,
|
|
7034
7182
|
durationMs: 0
|
|
@@ -7214,7 +7362,7 @@ var Yt = class {
|
|
|
7214
7362
|
$("query", s);
|
|
7215
7363
|
let c = this.queryBuilder.collectNumericFields(e, t), l = await this.dbExecutor.execute(s, c);
|
|
7216
7364
|
return {
|
|
7217
|
-
data:
|
|
7365
|
+
data: At(Array.isArray(l) ? l.map((e) => {
|
|
7218
7366
|
let n = { ...e };
|
|
7219
7367
|
if (t.timeDimensions) {
|
|
7220
7368
|
for (let e of t.timeDimensions) if (e.dimension in n) {
|
|
@@ -7341,7 +7489,7 @@ var Yt = class {
|
|
|
7341
7489
|
}
|
|
7342
7490
|
validateQueryForMode(e, t, n) {
|
|
7343
7491
|
let r = () => {
|
|
7344
|
-
let e =
|
|
7492
|
+
let e = nn(t, n);
|
|
7345
7493
|
if (!e.isValid) throw Error(`Query validation failed: ${e.errors.join(", ")}`);
|
|
7346
7494
|
};
|
|
7347
7495
|
({
|
|
@@ -7359,7 +7507,7 @@ var Yt = class {
|
|
|
7359
7507
|
let e = this.retentionQueryBuilder.validateConfig(n.retention, t);
|
|
7360
7508
|
if (!e.isValid) throw Error(`Retention validation failed: ${e.errors.join(", ")}`);
|
|
7361
7509
|
}
|
|
7362
|
-
})[
|
|
7510
|
+
})[nt(e)]();
|
|
7363
7511
|
}
|
|
7364
7512
|
async executeQueryByModeWithCache(e, t, n, r, i) {
|
|
7365
7513
|
return {
|
|
@@ -7368,7 +7516,7 @@ var Yt = class {
|
|
|
7368
7516
|
funnel: () => this.executeFunnelQueryWithCache(t, n, r, i),
|
|
7369
7517
|
flow: () => this.executeFlowQueryWithCache(t, n, r, i),
|
|
7370
7518
|
retention: () => this.executeRetentionQueryWithCache(t, n, r, i)
|
|
7371
|
-
}[
|
|
7519
|
+
}[nt(e)]();
|
|
7372
7520
|
}
|
|
7373
7521
|
async executeRegularQueryWithCache(e, t, n, r) {
|
|
7374
7522
|
let i = new K(), a = this.createQueryContext(n, i, t);
|
|
@@ -7378,7 +7526,7 @@ var Yt = class {
|
|
|
7378
7526
|
let c = this.drizzlePlanBuilder.build(s, t, a);
|
|
7379
7527
|
$("query", c);
|
|
7380
7528
|
let l = this.queryBuilder.collectNumericFields(e, t), u = await this.dbExecutor.execute(c, l), d = {
|
|
7381
|
-
data:
|
|
7529
|
+
data: At(Array.isArray(u) ? u.map((e) => {
|
|
7382
7530
|
let n = { ...e };
|
|
7383
7531
|
if (t.timeDimensions) {
|
|
7384
7532
|
for (let e of t.timeDimensions) if (e.dimension in n) {
|
|
@@ -7416,7 +7564,7 @@ var Yt = class {
|
|
|
7416
7564
|
funnel: () => this.dryRunFunnel(t, n, r),
|
|
7417
7565
|
flow: () => this.dryRunFlow(t, n, r),
|
|
7418
7566
|
retention: () => this.dryRunRetention(t, n, r)
|
|
7419
|
-
}[
|
|
7567
|
+
}[nt(e)]();
|
|
7420
7568
|
}
|
|
7421
7569
|
async generateComparisonSQL(e, t, n) {
|
|
7422
7570
|
let r = this.buildComparisonExecutionPlan(t).periodQueries[0];
|
|
@@ -7468,7 +7616,7 @@ var Yt = class {
|
|
|
7468
7616
|
}
|
|
7469
7617
|
preloadFilterCache(e, t, n, r) {
|
|
7470
7618
|
if (e.filters && e.filters.length > 0) {
|
|
7471
|
-
let i =
|
|
7619
|
+
let i = at(e.filters);
|
|
7472
7620
|
for (let e of i) {
|
|
7473
7621
|
let i = G(e);
|
|
7474
7622
|
if (t.has(i)) continue;
|
|
@@ -7486,7 +7634,7 @@ var Yt = class {
|
|
|
7486
7634
|
}
|
|
7487
7635
|
if (e.timeDimensions) {
|
|
7488
7636
|
for (let i of e.timeDimensions) if (i.dateRange) {
|
|
7489
|
-
let e =
|
|
7637
|
+
let e = it(i.dimension, i.dateRange);
|
|
7490
7638
|
if (t.has(e)) continue;
|
|
7491
7639
|
let [a, o] = i.dimension.split("."), s = n.get(a);
|
|
7492
7640
|
if (!s) continue;
|
|
@@ -7497,7 +7645,7 @@ var Yt = class {
|
|
|
7497
7645
|
}
|
|
7498
7646
|
}
|
|
7499
7647
|
}
|
|
7500
|
-
},
|
|
7648
|
+
}, en = class t {
|
|
7501
7649
|
cubes = /* @__PURE__ */ new Map();
|
|
7502
7650
|
metadataCache;
|
|
7503
7651
|
cacheConfig;
|
|
@@ -7522,10 +7670,10 @@ var Yt = class {
|
|
|
7522
7670
|
}
|
|
7523
7671
|
createDbExecutor() {
|
|
7524
7672
|
if (!this.db) throw Error("Database executor not configured");
|
|
7525
|
-
return
|
|
7673
|
+
return Qe(this.db, this.schema, this.engineType);
|
|
7526
7674
|
}
|
|
7527
7675
|
createQueryExecutor(e = !1) {
|
|
7528
|
-
return new
|
|
7676
|
+
return new $t(this.createDbExecutor(), e ? this.cacheConfig : void 0, this.rlsSetup);
|
|
7529
7677
|
}
|
|
7530
7678
|
formatSqlResult(t) {
|
|
7531
7679
|
let n = this.getEngineType() ?? "postgres";
|
|
@@ -7549,7 +7697,7 @@ var Yt = class {
|
|
|
7549
7697
|
t.push(`Calculated measure '${e.name}.${n}' must have calculatedSql property`);
|
|
7550
7698
|
continue;
|
|
7551
7699
|
}
|
|
7552
|
-
let i =
|
|
7700
|
+
let i = ht(r.calculatedSql);
|
|
7553
7701
|
if (!i.isValid) {
|
|
7554
7702
|
t.push(`Invalid calculatedSql syntax in '${e.name}.${n}': ${i.errors.join(", ")}`);
|
|
7555
7703
|
continue;
|
|
@@ -7719,18 +7867,18 @@ var Yt = class {
|
|
|
7719
7867
|
return Array.from(this.cubes.keys());
|
|
7720
7868
|
}
|
|
7721
7869
|
validateQuery(e) {
|
|
7722
|
-
return
|
|
7870
|
+
return nn(this.cubes, e);
|
|
7723
7871
|
}
|
|
7724
7872
|
analyzeQuery(e, t) {
|
|
7725
7873
|
return this.createQueryExecutor(!0).analyzeQuery(this.cubes, e, t);
|
|
7726
7874
|
}
|
|
7727
7875
|
};
|
|
7728
|
-
function
|
|
7876
|
+
function tn(e) {
|
|
7729
7877
|
let t = [];
|
|
7730
7878
|
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;
|
|
7731
7879
|
}
|
|
7732
|
-
function
|
|
7733
|
-
let n = [], r =
|
|
7880
|
+
function nn(e, t) {
|
|
7881
|
+
let n = [], r = tn(t);
|
|
7734
7882
|
if (r.length > 1) return n.push(`Query contains multiple query modes: ${r.join(", ")}`), {
|
|
7735
7883
|
isValid: !1,
|
|
7736
7884
|
errors: n
|
|
@@ -7751,7 +7899,7 @@ function Qt(e, t) {
|
|
|
7751
7899
|
}
|
|
7752
7900
|
},
|
|
7753
7901
|
retention: () => {
|
|
7754
|
-
let r = t.retention, i =
|
|
7902
|
+
let r = t.retention, i = an(r.timeDimension);
|
|
7755
7903
|
i && !e.has(i) && n.push(`Retention cube not found: ${i}`);
|
|
7756
7904
|
let a = r.bindingKey;
|
|
7757
7905
|
if (typeof a == "string") {
|
|
@@ -7817,7 +7965,7 @@ function Qt(e, t) {
|
|
|
7817
7965
|
}
|
|
7818
7966
|
o.dimensions[i] || n.push(`TimeDimension '${i}' not found on cube '${t}' (must be a dimension with time type)`);
|
|
7819
7967
|
}
|
|
7820
|
-
if (t.filters) for (let r of t.filters)
|
|
7968
|
+
if (t.filters) for (let r of t.filters) rn(r, e, n, a);
|
|
7821
7969
|
if (a.size === 0 && n.push("Query must reference at least one cube through measures, dimensions, or filters"), t.ungrouped) {
|
|
7822
7970
|
t.dimensions && t.dimensions.length > 0 || t.timeDimensions && t.timeDimensions.length > 0 || n.push("Ungrouped queries require at least one dimension or time dimension"), t.funnel && n.push("Ungrouped queries are incompatible with funnel analysis"), t.flow && n.push("Ungrouped queries are incompatible with flow analysis"), t.retention && n.push("Ungrouped queries are incompatible with retention analysis"), t.timeDimensions?.some((e) => e.compareDateRange && e.compareDateRange.length > 0) && n.push("Ungrouped queries are incompatible with compareDateRange"), t.timeDimensions?.some((e) => e.fillMissingDates === !0) && n.push("Ungrouped queries are incompatible with fillMissingDates");
|
|
7823
7971
|
let r = new Set([
|
|
@@ -7872,10 +8020,10 @@ function Qt(e, t) {
|
|
|
7872
8020
|
errors: n
|
|
7873
8021
|
};
|
|
7874
8022
|
}
|
|
7875
|
-
function
|
|
8023
|
+
function rn(e, t, n, r) {
|
|
7876
8024
|
if ("and" in e || "or" in e) {
|
|
7877
8025
|
let i = e.and || e.or || [];
|
|
7878
|
-
for (let e of i)
|
|
8026
|
+
for (let e of i) rn(e, t, n, r);
|
|
7879
8027
|
return;
|
|
7880
8028
|
}
|
|
7881
8029
|
if (!("member" in e)) {
|
|
@@ -7898,7 +8046,7 @@ function $t(e, t, n, r) {
|
|
|
7898
8046
|
n.push(`Filter field '${a}' not found on cube '${i}' (must be a dimension or measure)${e}`);
|
|
7899
8047
|
}
|
|
7900
8048
|
}
|
|
7901
|
-
function
|
|
8049
|
+
function an(e) {
|
|
7902
8050
|
if (typeof e == "string") {
|
|
7903
8051
|
let [t] = e.split(".");
|
|
7904
8052
|
return t || null;
|
|
@@ -7906,4 +8054,4 @@ function en(e) {
|
|
|
7906
8054
|
return e.cube;
|
|
7907
8055
|
}
|
|
7908
8056
|
//#endregion
|
|
7909
|
-
export {
|
|
8057
|
+
export { en as t };
|