@objectstack/service-analytics 15.1.0 → 16.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +33 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/analytics-service.ts
|
|
2
|
-
import { createLogger } from "@objectstack/core";
|
|
2
|
+
import { createLogger, bucketKeyToCalendarRange, zonedDateStartToUtcMs } from "@objectstack/core";
|
|
3
3
|
|
|
4
4
|
// src/cube-registry.ts
|
|
5
5
|
var CubeRegistry = class {
|
|
@@ -1709,6 +1709,39 @@ var AnalyticsService = class {
|
|
|
1709
1709
|
for (const d of drillDims) raw[d.name] = row[d.name];
|
|
1710
1710
|
return raw;
|
|
1711
1711
|
});
|
|
1712
|
+
if (result.totals?.length) {
|
|
1713
|
+
result.drillRawTotals = result.totals.map((total) => {
|
|
1714
|
+
const groupingDims = drillDims.filter((d) => total.dimensions.includes(d.name));
|
|
1715
|
+
return total.rows.map((row) => {
|
|
1716
|
+
const raw = {};
|
|
1717
|
+
for (const d of groupingDims) raw[d.name] = row[d.name];
|
|
1718
|
+
return raw;
|
|
1719
|
+
});
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
const rangeTz = selection.timezone ?? context?.timezone ?? "UTC";
|
|
1724
|
+
const rangeDims = [];
|
|
1725
|
+
for (const d of selectedDims) {
|
|
1726
|
+
if (!d.field || d.type !== "date" || !d.dateGranularity) continue;
|
|
1727
|
+
const ftype = this.measureCurrency?.(dataset.object, d.field)?.type;
|
|
1728
|
+
if (ftype === "datetime") rangeDims.push({ d, instant: true });
|
|
1729
|
+
else if (ftype === "date") rangeDims.push({ d, instant: false });
|
|
1730
|
+
else if (rangeTz === "UTC") rangeDims.push({ d, instant: false });
|
|
1731
|
+
}
|
|
1732
|
+
if (rangeDims.length && result.rows.length) {
|
|
1733
|
+
const bound = (ymd, instant) => instant ? new Date(zonedDateStartToUtcMs(ymd, rangeTz)).toISOString() : ymd;
|
|
1734
|
+
result.drillRanges = result.rows.map((row) => {
|
|
1735
|
+
const ranges = {};
|
|
1736
|
+
for (const { d, instant } of rangeDims) {
|
|
1737
|
+
const cal = bucketKeyToCalendarRange(row[d.name], d.dateGranularity);
|
|
1738
|
+
if (cal) {
|
|
1739
|
+
ranges[d.name] = { field: d.field, gte: bound(cal.start, instant), lt: bound(cal.end, instant) };
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
return ranges;
|
|
1743
|
+
});
|
|
1744
|
+
result.object = dataset.object;
|
|
1712
1745
|
}
|
|
1713
1746
|
if (this.labelResolver && selectedDims.length) {
|
|
1714
1747
|
const dims = selectedDims.filter((d) => !!d.field).map((d) => ({ name: d.name, field: d.field, type: d.type, dateGranularity: d.dateGranularity }));
|