@gscdump/engine-gsc-api 0.37.2 → 0.37.4
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.mjs +38 -3
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -52,8 +52,9 @@ async function fetchGscTopN(opts) {
|
|
|
52
52
|
if (searchType) builder = builder.type(searchType);
|
|
53
53
|
if (orderByClicksDesc) builder = builder.orderBy(clicks, "desc");
|
|
54
54
|
if (typeof limit === "number") builder = builder.limit(limit);
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const rows = await collectRows(client.query(siteUrl, builder));
|
|
56
|
+
const mapRow = (raw) => {
|
|
57
|
+
const row = raw;
|
|
57
58
|
const key = row[dimension.dimension];
|
|
58
59
|
if (typeof key !== "string" || !key) return null;
|
|
59
60
|
const impressions = Number(row.impressions ?? 0);
|
|
@@ -64,7 +65,41 @@ async function fetchGscTopN(opts) {
|
|
|
64
65
|
impressions,
|
|
65
66
|
sum_position: (position - 1) * impressions
|
|
66
67
|
};
|
|
67
|
-
}
|
|
68
|
+
};
|
|
69
|
+
const topLimit = typeof sliceTop === "number" && Number.isInteger(sliceTop) && sliceTop >= 0 ? sliceTop : void 0;
|
|
70
|
+
const mapped = [];
|
|
71
|
+
if (topLimit === 0) return mapped;
|
|
72
|
+
if (orderByClicksDesc && topLimit !== void 0) {
|
|
73
|
+
for (const row of rows) {
|
|
74
|
+
const value = mapRow(row);
|
|
75
|
+
if (value) mapped.push(value);
|
|
76
|
+
if (mapped.length >= topLimit) break;
|
|
77
|
+
}
|
|
78
|
+
return mapped;
|
|
79
|
+
}
|
|
80
|
+
if (!orderByClicksDesc && topLimit !== void 0 && topLimit <= 128) {
|
|
81
|
+
let requiresFullSort = false;
|
|
82
|
+
for (const row of rows) {
|
|
83
|
+
const value = mapRow(row);
|
|
84
|
+
if (!value) continue;
|
|
85
|
+
if (!Number.isFinite(value.clicks)) {
|
|
86
|
+
requiresFullSort = true;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
let insertAt = 0;
|
|
90
|
+
while (insertAt < mapped.length && mapped[insertAt].clicks >= value.clicks) insertAt++;
|
|
91
|
+
if (insertAt < topLimit) {
|
|
92
|
+
mapped.splice(insertAt, 0, value);
|
|
93
|
+
if (mapped.length > topLimit) mapped.pop();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (!requiresFullSort) return mapped;
|
|
97
|
+
mapped.length = 0;
|
|
98
|
+
}
|
|
99
|
+
for (const row of rows) {
|
|
100
|
+
const value = mapRow(row);
|
|
101
|
+
if (value) mapped.push(value);
|
|
102
|
+
}
|
|
68
103
|
if (!orderByClicksDesc) mapped.sort((a, b) => b.clicks - a.clicks);
|
|
69
104
|
return typeof sliceTop === "number" ? mapped.slice(0, sliceTop) : mapped;
|
|
70
105
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/engine-gsc-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.37.
|
|
4
|
+
"version": "0.37.4",
|
|
5
5
|
"description": "GSC live-API engine adapter — wraps the Search Analytics REST API as an AnalysisQuerySource for typed analyzer dispatch.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"node": ">=18"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@gscdump/engine": "0.37.
|
|
40
|
-
"gscdump": "0.37.
|
|
39
|
+
"@gscdump/engine": "0.37.4",
|
|
40
|
+
"gscdump": "0.37.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"vitest": "^4.1.9"
|