@gscdump/analysis 1.0.1 → 1.0.3
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/_chunks/default-registry.d.mts +5 -0
- package/dist/_chunks/default-registry.mjs +5183 -0
- package/dist/_chunks/errors.d.mts +52 -0
- package/dist/_chunks/index.d.mts +89 -0
- package/dist/_chunks/index2.d.mts +37 -0
- package/dist/_chunks/report.mjs +1710 -0
- package/dist/_chunks/scoring.mjs +15 -0
- package/dist/_chunks/source.mjs +60 -0
- package/dist/default-registry.d.mts +2 -8
- package/dist/default-registry.mjs +2 -4892
- package/dist/errors.d.mts +1 -51
- package/dist/index.d.mts +7 -154
- package/dist/index.mjs +8 -7025
- package/dist/report/index.d.mts +1 -116
- package/dist/report/index.mjs +1 -1771
- package/dist/source/index.d.mts +2 -0
- package/dist/source/index.mjs +2 -0
- package/package.json +9 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function clamp01(value) {
|
|
2
|
+
if (value < 0) return 0;
|
|
3
|
+
if (value > 1) return 1;
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
function clamp(value, min, max) {
|
|
7
|
+
if (value < min) return min;
|
|
8
|
+
if (value > max) return max;
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function percentDifference(current, previous) {
|
|
12
|
+
if (previous === 0) return current > 0 ? 100 : 0;
|
|
13
|
+
return (current - previous) / previous * 100;
|
|
14
|
+
}
|
|
15
|
+
export { clamp, clamp01, percentDifference };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { extractDateRange } from "gscdump/query";
|
|
2
|
+
import { canProxyToGsc } from "@gscdump/engine-gsc-api";
|
|
3
|
+
import { isStateResolvable } from "gscdump/query/plan";
|
|
4
|
+
function hasGapInCoveredSpans(start, end, coveredSpans) {
|
|
5
|
+
let cursor = start;
|
|
6
|
+
for (const span of coveredSpans) {
|
|
7
|
+
if (span.end < cursor) continue;
|
|
8
|
+
if (span.start > cursor) return true;
|
|
9
|
+
if (span.end >= end) return false;
|
|
10
|
+
cursor = nextDay(span.end);
|
|
11
|
+
if (cursor > end) return false;
|
|
12
|
+
}
|
|
13
|
+
return cursor <= end;
|
|
14
|
+
}
|
|
15
|
+
function nextDay(day) {
|
|
16
|
+
const t = Date.parse(`${day}T00:00:00Z`) + 864e5;
|
|
17
|
+
return new Date(t).toISOString().slice(0, 10);
|
|
18
|
+
}
|
|
19
|
+
function shouldRouteToLive(state, site) {
|
|
20
|
+
if (!canProxyToGsc(state)) return false;
|
|
21
|
+
if (!isStateResolvable(state)) return true;
|
|
22
|
+
const { startDate, endDate } = extractDateRange(state.filter);
|
|
23
|
+
if (!startDate || !endDate) return false;
|
|
24
|
+
if (!site.oldestDateSynced || !site.newestDateSynced) return true;
|
|
25
|
+
if (startDate < site.oldestDateSynced || endDate > site.newestDateSynced) return true;
|
|
26
|
+
if (site.coveredSpans && site.coveredSpans.length > 0) return hasGapInCoveredSpans(startDate, endDate, site.coveredSpans);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function createCompositeSource(opts) {
|
|
30
|
+
const { engine, live, site } = opts;
|
|
31
|
+
const engineExecuteSql = engine.executeSql;
|
|
32
|
+
return {
|
|
33
|
+
name: "composite-engine-live",
|
|
34
|
+
kind: "composite",
|
|
35
|
+
capabilities: engine.capabilities,
|
|
36
|
+
adapter: engine.adapter,
|
|
37
|
+
siteId: engine.siteId,
|
|
38
|
+
async queryRows(state) {
|
|
39
|
+
return shouldRouteToLive(state, site) ? live.queryRows(state) : engine.queryRows(state);
|
|
40
|
+
},
|
|
41
|
+
executeSql: engineExecuteSql ? (sql, params, execOpts) => engineExecuteSql(sql, params, execOpts) : void 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const IN_MEMORY_DEFAULT_CAPABILITIES = {
|
|
45
|
+
regex: true,
|
|
46
|
+
multiDataset: true,
|
|
47
|
+
comparisonJoin: true,
|
|
48
|
+
windowTotals: true
|
|
49
|
+
};
|
|
50
|
+
function createInMemoryQuerySource(options) {
|
|
51
|
+
return {
|
|
52
|
+
name: "memory",
|
|
53
|
+
kind: "in-memory",
|
|
54
|
+
capabilities: options.capabilities ?? IN_MEMORY_DEFAULT_CAPABILITIES,
|
|
55
|
+
async queryRows(state) {
|
|
56
|
+
return await options.queryRows(state);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { IN_MEMORY_DEFAULT_CAPABILITIES, createCompositeSource, createInMemoryQuerySource };
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* for callers who don't care about bundle size; edge / browser consumers
|
|
4
|
-
* should compose their own narrower registry via `createAnalyzerRegistry`
|
|
5
|
-
* with the flat `ROW_ANALYZERS` / `SQL_ANALYZERS` arrays.
|
|
6
|
-
*/
|
|
7
|
-
declare const defaultAnalyzerRegistry: import("@gscdump/engine/analyzer").AnalyzerRegistry;
|
|
8
|
-
export { defaultAnalyzerRegistry };
|
|
1
|
+
import { ROW_ANALYZERS, SQL_ANALYZERS, defaultAnalyzerRegistry } from "./_chunks/default-registry.mjs";
|
|
2
|
+
export { ROW_ANALYZERS, SQL_ANALYZERS, defaultAnalyzerRegistry };
|