@gscdump/engine 0.9.2 → 0.11.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.
@@ -1,3 +1,3 @@
1
- import { _ as resolveToSQL, a as createResolverAdapter, c as LOGICAL_DATASETS, d as inferLogicalDataset, f as supportsDimensionOnSurface, g as resolveComparisonSQL, h as mergeExtras, i as compileSqlite, l as assertDimensionsSupported, m as buildTotalsSql, n as pgResolverAdapter, o as createSqlFragments, p as buildExtrasQueries, r as compilePg, s as DIMENSION_SURFACES, t as createParquetResolverAdapter, u as dimensionColumn, v as resolveToSQLOptimized } from "../_chunks/pg-adapter.mjs";
2
- import { a as getFilterDimensions, c as matchesMetricFilter, d as createSqlQuerySource, i as getDimensionFilters, l as matchesTopLevelPage, n as assertSchemaInSync, o as getInternalFilters, r as dimensionValue, s as matchesDimensionFilter, t as isSqlQuerySource, u as metricValue } from "../_chunks/resolver.mjs";
3
- export { DIMENSION_SURFACES, LOGICAL_DATASETS, assertDimensionsSupported, assertSchemaInSync, buildExtrasQueries, buildTotalsSql, compilePg, compileSqlite, createParquetResolverAdapter, createResolverAdapter, createSqlFragments, createSqlQuerySource, dimensionColumn, dimensionValue, getDimensionFilters, getFilterDimensions, getInternalFilters, inferLogicalDataset, isSqlQuerySource, matchesDimensionFilter, matchesMetricFilter, matchesTopLevelPage, mergeExtras, metricValue, pgResolverAdapter, resolveComparisonSQL, resolveToSQL, resolveToSQLOptimized, supportsDimensionOnSurface };
1
+ import { a as DIMENSION_SURFACES, c as dimensionColumn, d as buildExtrasQueries, f as buildTotalsSql, g as resolveToSQLOptimized, h as resolveToSQL, i as createSqlFragments, l as inferLogicalDataset, m as resolveComparisonSQL, n as pgResolverAdapter, o as LOGICAL_DATASETS, p as mergeExtras, r as createResolverAdapter, s as assertDimensionsSupported, t as createParquetResolverAdapter, u as supportsDimensionOnSurface } from "../_chunks/pg-adapter.mjs";
2
+ import { a as getInternalFilters, c as matchesTopLevelPage, i as getFilterDimensions, l as metricValue, n as dimensionValue, o as matchesDimensionFilter, r as getDimensionFilters, s as matchesMetricFilter, t as assertSchemaInSync } from "../_chunks/resolver.mjs";
3
+ export { DIMENSION_SURFACES, LOGICAL_DATASETS, assertDimensionsSupported, assertSchemaInSync, buildExtrasQueries, buildTotalsSql, createParquetResolverAdapter, createResolverAdapter, createSqlFragments, dimensionColumn, dimensionValue, getDimensionFilters, getFilterDimensions, getInternalFilters, inferLogicalDataset, matchesDimensionFilter, matchesMetricFilter, matchesTopLevelPage, mergeExtras, metricValue, pgResolverAdapter, resolveComparisonSQL, resolveToSQL, resolveToSQLOptimized, supportsDimensionOnSurface };
@@ -0,0 +1,196 @@
1
+ import { a as DataSource } from "./_chunks/storage.mjs";
2
+ import { t as ColumnDef } from "./_chunks/schema.mjs";
3
+ import { TenantCtx } from "gscdump/contracts";
4
+ import * as _$_gscdump_engine_contracts0 from "@gscdump/engine/contracts";
5
+ interface RollupCtx extends TenantCtx {
6
+ /** When the rollup was built. Stamped into payload + filename. */
7
+ builtAt: number;
8
+ }
9
+ /**
10
+ * Tenant-scoped engine surface a rollup builder needs. Subset of
11
+ * `StorageEngine.runSQL` so rollups stay testable without a full engine.
12
+ */
13
+ interface RollupEngine {
14
+ runSQL: (opts: {
15
+ ctx: TenantCtx;
16
+ fileSets: Record<string, {
17
+ table: _$_gscdump_engine_contracts0.TableName;
18
+ partitions?: string[];
19
+ }>;
20
+ table?: _$_gscdump_engine_contracts0.TableName;
21
+ sql: string;
22
+ params?: unknown[];
23
+ }) => Promise<{
24
+ rows: _$_gscdump_engine_contracts0.Row[];
25
+ }>;
26
+ }
27
+ /**
28
+ * One rollup definition. Build runs SQL over the tenant's facts and/or reads
29
+ * from entity stores via `dataSource`, returning a JSON-serializable payload
30
+ * that the runner timestamps + writes.
31
+ */
32
+ interface RollupDef {
33
+ id: string;
34
+ /**
35
+ * Window in days the rollup covers. `null` means full history. Used by
36
+ * the runner to populate `windowDays` in the payload metadata so readers
37
+ * can validate freshness.
38
+ */
39
+ windowDays: number | null;
40
+ /**
41
+ * Storage format. `'json'` (default) wraps the build payload in a
42
+ * `RollupEnvelope` and writes as a JSON blob. `'parquet'` expects `build`
43
+ * to return rows matching `parquetColumns` and writes a parquet file plus
44
+ * a tiny JSON sidecar envelope that points at it, so metadata
45
+ * (`builtAt` / `windowDays`) stays readable without decoding parquet.
46
+ */
47
+ format?: 'json' | 'parquet';
48
+ /**
49
+ * Column schema for parquet output. Required when `format === 'parquet'`.
50
+ * Types map the same way as the fact-table encoder: VARCHAR / DATE go
51
+ * through BYTE_ARRAY/UTF8; BIGINT → INT64; INTEGER → INT32; DOUBLE → DOUBLE.
52
+ */
53
+ parquetColumns?: readonly ColumnDef[];
54
+ /** Sort-key column names for parquet row-group stats. Optional. */
55
+ parquetSortKey?: readonly string[];
56
+ build: (deps: {
57
+ engine: RollupEngine;
58
+ ctx: TenantCtx;
59
+ /**
60
+ * Tenant-scoped object store. Rollups that aggregate over entity
61
+ * snapshots (e.g. indexing metadata) read JSON docs through this.
62
+ * Pure-SQL rollups can ignore it.
63
+ */
64
+ dataSource: DataSource;
65
+ /**
66
+ * Wall-clock millis when the runner started this rollup. Use for
67
+ * derived window cutoffs (e.g. trailing-28d boundary) so the SQL can
68
+ * inline a date literal and stay portable across DuckDB builds that
69
+ * don't bundle the ICU extension (Workers DuckDB, for one — CURRENT_DATE
70
+ * lives in ICU).
71
+ */
72
+ builtAt: number;
73
+ }) => Promise<unknown>;
74
+ }
75
+ /**
76
+ * Wire shape persisted to R2/disk. Readers can rely on the `version` + `builtAt`.
77
+ * Parquet rollups write this envelope as a sidecar whose `payload` points at
78
+ * the co-located `.parquet` object via `{ parquetKey, rowCount }`.
79
+ */
80
+ interface RollupEnvelope<T = unknown> {
81
+ version: 1;
82
+ id: string;
83
+ builtAt: number;
84
+ windowDays: number | null;
85
+ payload: T;
86
+ }
87
+ interface ParquetRollupPointer {
88
+ parquetKey: string;
89
+ rowCount: number;
90
+ }
91
+ declare function rollupKey(ctx: TenantCtx, id: string, builtAt: number): string;
92
+ declare function rollupParquetKey(ctx: TenantCtx, id: string, builtAt: number): string;
93
+ interface RebuildRollupsOptions {
94
+ engine: RollupEngine;
95
+ dataSource: DataSource;
96
+ ctx: TenantCtx;
97
+ defs: readonly RollupDef[];
98
+ now?: () => number;
99
+ }
100
+ interface RebuildRollupResult {
101
+ id: string;
102
+ /** JSON envelope key. For parquet rollups this is the sidecar pointer. */
103
+ objectKey: string;
104
+ /** Parquet payload key. Present only when `format === 'parquet'`. */
105
+ parquetKey?: string;
106
+ /** Envelope byte size; for parquet rollups does NOT include parquet bytes. */
107
+ bytes: number;
108
+ /** Parquet payload byte size when `format === 'parquet'`. */
109
+ parquetBytes?: number;
110
+ builtAt: number;
111
+ }
112
+ declare function rebuildRollups(opts: RebuildRollupsOptions): Promise<RebuildRollupResult[]>;
113
+ /**
114
+ * Daily totals across the full history. One row per (date, table) with
115
+ * clicks + impressions + position. Powers sparklines and headline totals.
116
+ *
117
+ * Includes `anonymizedImpressionsPct` per day computed as
118
+ * 1 - sum(query_grained_impressions) / sum(page_grained_impressions)
119
+ * — surfaces GSC's anonymous-query gap so the dashboard can warn users not
120
+ * to trust query-grained breakdowns as comprehensive.
121
+ */
122
+ declare const dailyTotalsRollup: RollupDef;
123
+ /** Weekly totals, ISO week aligned. Cheap and stable for trend widgets. */
124
+ declare const weeklyTotalsRollup: RollupDef;
125
+ /**
126
+ * Top 1000 pages by clicks over the trailing 28-day window. JSON for v1;
127
+ * promote to parquet (`top_pages_28d.parquet`) when the dashboard needs
128
+ * server-side WHERE filtering on this rollup.
129
+ */
130
+ declare const topPages28dRollup: RollupDef;
131
+ /**
132
+ * Top 250 countries by clicks over the trailing 28-day window. Countries
133
+ * cardinality is bounded (~250 ISO codes), so the list fits in a tiny JSON
134
+ * payload regardless of traffic shape. Powers a geo-overview widget without
135
+ * spinning up DuckDB-WASM.
136
+ */
137
+ declare const topCountries28dRollup: RollupDef;
138
+ /** Top 1000 keywords by clicks over the trailing 28-day window. */
139
+ declare const topKeywords28dRollup: RollupDef;
140
+ /**
141
+ * Parquet-format companion to `topKeywords28dRollup`. Same shape, but persists
142
+ * as a parquet object plus JSON sidecar pointer so widgets that need
143
+ * server-side WHERE (filter by prefix, by clicks threshold, paginate) can scan
144
+ * it directly with DuckDB-WASM instead of loading all 1000 rows into JS.
145
+ *
146
+ * Opt-in: include in the caller's rollup def list alongside (or instead of)
147
+ * the JSON variant; the runner treats the two as independent ids so they can
148
+ * coexist during a migration.
149
+ */
150
+ declare const topKeywords28dParquetRollup: RollupDef;
151
+ /**
152
+ * Aggregates the per-URL Indexing API metadata entity store (populated by
153
+ * `gscdump entities indexing snapshot`) into daily counts of `URL_UPDATED`
154
+ * and `URL_REMOVED` notifications. Covers the third entity-snapshot shape
155
+ * without needing its own parquet family — publish events are sparse and
156
+ * aggregate cleanly into a small JSON rollup.
157
+ *
158
+ * Safe no-op when the entity store is empty: returns `{ totals: {...}, days: [] }`
159
+ * so downstream readers don't have to special-case first-run sites.
160
+ */
161
+ declare const indexingMetadataRollup: RollupDef;
162
+ /**
163
+ * Indexing-API health by day: per `inspectedAt` date, counts of indexed,
164
+ * soft-404, redirect, not-found, mobile passes, rich-results passes, and
165
+ * canonical mismatches. Sourced from the inspections parquet sidecar
166
+ * (`InspectionStore.parquetUri`), which holds the latest record per URL.
167
+ *
168
+ * Empty-payload no-op when the sidecar URI is unavailable (in-memory
169
+ * `DataSource`, or before `materialize` has run).
170
+ */
171
+ declare const indexingHealthRollup: RollupDef;
172
+ /**
173
+ * Per-day index-percent: ratio of (sitemap URLs that received GSC clicks on
174
+ * that date) / (total live sitemap URLs). Uses a DuckDB JOIN between the
175
+ * sitemap urls parquet (`SitemapStore.urlsParquetUri`) and the `pages` fact
176
+ * parquet. Total denominator is the count of live URLs in the urls index;
177
+ * numerator is per-day distinct loc count where pages.clicks > 0.
178
+ */
179
+ declare const indexPercentRollup: RollupDef;
180
+ /**
181
+ * Sitemap-health per-day series materialized from the sitemap-store JSON
182
+ * index. Each `SitemapRecord` carries `urlCount`, `errors`, `warnings`,
183
+ * `contentHash`, and `lastDownloaded`. We bucket records by the day of their
184
+ * `capturedAt` (or `lastDownloaded` fallback) and emit per-day aggregates plus
185
+ * a snapshot of per-feed stats at the most recent capture.
186
+ */
187
+ declare const sitemapHealthRollup: RollupDef;
188
+ /**
189
+ * Trailing-28-day sitemap URL changes: per-day per-feedpath {added, removed}
190
+ * counts plus rolling top-200 added and removed URLs. Streams from
191
+ * `SitemapStore.loadDeltas()` so it scales independently of how many feeds
192
+ * exist on the site.
193
+ */
194
+ declare const sitemapChanges28dRollup: RollupDef;
195
+ declare const DEFAULT_ROLLUPS: readonly RollupDef[];
196
+ export { DEFAULT_ROLLUPS, ParquetRollupPointer, RebuildRollupResult, RebuildRollupsOptions, RollupCtx, RollupDef, RollupEngine, RollupEnvelope, dailyTotalsRollup, indexPercentRollup, indexingHealthRollup, indexingMetadataRollup, rebuildRollups, rollupKey, rollupParquetKey, sitemapChanges28dRollup, sitemapHealthRollup, topCountries28dRollup, topKeywords28dParquetRollup, topKeywords28dRollup, topPages28dRollup, weeklyTotalsRollup };