@gscdump/cli 0.29.0 → 0.31.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.
Files changed (2) hide show
  1. package/dist/index.mjs +46 -7
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { defineCommand, runMain } from "citty";
4
4
  import { defaultAnalyzerRegistry } from "@gscdump/analysis/registry";
5
5
  import fs, { readFile, readdir, rm } from "node:fs/promises";
6
6
  import path, { join } from "node:path";
7
- import { AnalyzerCapabilityError, createEngineQuerySource, runAnalyzerFromSource } from "@gscdump/analysis";
7
+ import { AnalyzerCapabilityError, INTENT_CLASSIFIER_VERSION, NORMALIZER_VERSION, classifyQueryIntent, createEngineQuerySource, encodeIntent, normalizeQuery, runAnalyzerFromSource } from "@gscdump/analysis";
8
8
  import { createGscApiQuerySource } from "@gscdump/engine-gsc-api";
9
9
  import { err, ok, unwrapResult } from "gscdump/result";
10
10
  import { decodeSiteId, normalizeSiteUrl } from "gscdump/tenant";
@@ -26,7 +26,7 @@ import { isEngineError } from "@gscdump/engine/errors";
26
26
  import { DuckDBInstance } from "@duckdb/node-api";
27
27
  import { sqlEscape } from "@gscdump/engine/sql";
28
28
  import { dateReplaceClause } from "@gscdump/engine/sql-fragments";
29
- import { createEmptyTypesStore, createIndexingMetadataStore, createInspectionStore, createSitemapStore } from "@gscdump/engine/entities";
29
+ import { buildQueryDimRecords, createEmptyTypesStore, createIndexingMetadataStore, createInspectionStore, createQueryDimStore, createSitemapStore } from "@gscdump/engine/entities";
30
30
  import { daysAgo, getDateRange, progressBar } from "gscdump";
31
31
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
32
32
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -34,7 +34,7 @@ import { z } from "zod";
34
34
  import { defaultReportRegistry, dryRunReport, formatReport, runReport } from "@gscdump/analysis/report";
35
35
  import { resolveWindow } from "@gscdump/engine/period";
36
36
  import { collectSpans, inferLegacyTier } from "@gscdump/engine";
37
- import { DEFAULT_ROLLUPS, rebuildRollups } from "@gscdump/engine/rollups";
37
+ import { CANONICAL_ROLLUPS, DEFAULT_ROLLUPS, rebuildRollups } from "@gscdump/engine/rollups";
38
38
  import { filesystemStats } from "@gscdump/engine/filesystem";
39
39
  var __defProp = Object.defineProperty;
40
40
  var __exportAll = (all, no_symbols) => {
@@ -136,7 +136,7 @@ function loadEnvFromCwd() {
136
136
  }
137
137
  return applied;
138
138
  }
139
- var version = "0.29.0";
139
+ var version = "0.31.0";
140
140
  const ALL_SEARCH_TYPES$1 = Object.values(SearchTypes);
141
141
  const VERSION = version;
142
142
  function noSubcommandSelected(parent, subNames) {
@@ -6347,6 +6347,35 @@ const gcCommand = defineCommand({
6347
6347
  logger.success(`gc: deleted ${result.deleted} orphan file(s)`);
6348
6348
  }
6349
6349
  });
6350
+ async function buildSiteQueryDim(store, siteId) {
6351
+ const ctx = {
6352
+ userId: store.userId,
6353
+ siteId
6354
+ };
6355
+ const entries = await store.engine.listLive({
6356
+ userId: ctx.userId,
6357
+ siteId,
6358
+ table: "queries"
6359
+ });
6360
+ if (entries.length === 0) return 0;
6361
+ const { rows } = await store.engine.runSQL({
6362
+ ctx,
6363
+ table: "queries",
6364
+ fileSets: { FILES: {
6365
+ table: "queries",
6366
+ partitions: entries.map((e) => e.partition)
6367
+ } },
6368
+ sql: `SELECT DISTINCT query FROM read_parquet({{FILES}}, union_by_name = true) WHERE query IS NOT NULL`
6369
+ });
6370
+ const records = buildQueryDimRecords(rows.map((r) => String(r.query)), {
6371
+ normalizeQuery,
6372
+ normalizerVersion: NORMALIZER_VERSION,
6373
+ classifyIntentCode: (q) => encodeIntent(classifyQueryIntent(q)),
6374
+ intentVersion: INTENT_CLASSIFIER_VERSION
6375
+ });
6376
+ await createQueryDimStore({ dataSource: store.dataSource }).write(ctx, records, Date.now());
6377
+ return records.length;
6378
+ }
6350
6379
  const rollupsCommand = defineCommand({
6351
6380
  meta: {
6352
6381
  name: "rollups",
@@ -6359,14 +6388,20 @@ const rollupsCommand = defineCommand({
6359
6388
  },
6360
6389
  args: {
6361
6390
  ...OUTPUT_ARGS,
6362
- site: {
6391
+ "site": {
6363
6392
  type: "string",
6364
6393
  alias: "s",
6365
6394
  description: "Restrict to a single site (default: all sites with local data)"
6395
+ },
6396
+ "with-canonical": {
6397
+ type: "boolean",
6398
+ description: "Also build the opt-in canonical-primary rollups (query_canonical_variants, query_canonical_daily)",
6399
+ default: false
6366
6400
  }
6367
6401
  },
6368
6402
  async run({ args }) {
6369
6403
  const { json } = applyOutputMode(args);
6404
+ const defs = args["with-canonical"] ? [...DEFAULT_ROLLUPS, ...CANONICAL_ROLLUPS] : DEFAULT_ROLLUPS;
6370
6405
  const store = (await createCommandContext({ needsStore: true })).store;
6371
6406
  const explicitSiteId = args.site ? store.siteIdFor(String(args.site)) : void 0;
6372
6407
  const allSiteIds = /* @__PURE__ */ new Set();
@@ -6389,7 +6424,11 @@ const rollupsCommand = defineCommand({
6389
6424
  const summary = [];
6390
6425
  let totalBytes = 0;
6391
6426
  for (const siteId of allSiteIds) {
6392
- logger.info(`Rebuilding rollups for [${siteId}] (${DEFAULT_ROLLUPS.length} rollups)`);
6427
+ if (args["with-canonical"]) {
6428
+ const dimRows = await buildSiteQueryDim(store, siteId);
6429
+ if (!json) logger.info(`Built query dimension for [${siteId}] (${dimRows} distinct queries, normalizer v${NORMALIZER_VERSION})`);
6430
+ }
6431
+ logger.info(`Rebuilding rollups for [${siteId}] (${defs.length} rollups)`);
6393
6432
  const results = await rebuildRollups({
6394
6433
  engine: {
6395
6434
  runSQL: (opts) => store.engine.runSQL(opts),
@@ -6410,7 +6449,7 @@ const rollupsCommand = defineCommand({
6410
6449
  userId: store.userId,
6411
6450
  siteId
6412
6451
  },
6413
- defs: DEFAULT_ROLLUPS
6452
+ defs
6414
6453
  });
6415
6454
  const site = {
6416
6455
  siteId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/cli",
3
3
  "type": "module",
4
- "version": "0.29.0",
4
+ "version": "0.31.0",
5
5
  "description": "CLI for Google Search Console - dump, query, and run MCP server",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -43,10 +43,10 @@
43
43
  "ofetch": "^1.5.1",
44
44
  "open": "^11.0.0",
45
45
  "zod": "^4.4.3",
46
- "@gscdump/analysis": "0.29.0",
47
- "@gscdump/engine-gsc-api": "0.29.0",
48
- "@gscdump/engine": "0.29.0",
49
- "gscdump": "0.29.0"
46
+ "@gscdump/analysis": "0.31.0",
47
+ "@gscdump/engine": "0.31.0",
48
+ "@gscdump/engine-gsc-api": "0.31.0",
49
+ "gscdump": "0.31.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@duckdb/node-api": "1.5.1-r.2",