@gscdump/analysis 0.7.1 → 0.7.6
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/README.md +43 -108
- package/dist/analyzer/index.d.mts +38 -179
- package/dist/analyzer/index.mjs +269 -502
- package/dist/default-registry.d.mts +2 -86
- package/dist/default-registry.mjs +2986 -204
- package/dist/index.d.mts +75 -234
- package/dist/index.mjs +3275 -800
- package/dist/query/index.d.mts +1 -1
- package/dist/query/index.mjs +1 -33
- package/dist/rollups.d.mts +163 -0
- package/dist/rollups.mjs +346 -0
- package/dist/source/index.d.mts +31 -219
- package/dist/source/index.mjs +27 -388
- package/package.json +23 -17
- package/dist/period/index.d.mts +0 -57
- package/dist/period/index.mjs +0 -150
package/dist/source/index.d.mts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BuilderState
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { AnalyzerCapabilityError, AnalyzerRegistry } from "@gscdump/engine/analyzer";
|
|
2
|
+
import { BuilderState } from "gscdump/query";
|
|
3
|
+
import { AnalysisParams, AnalysisResult } from "@gscdump/engine/analysis-types";
|
|
4
|
+
import { AnalysisPeriod, ComparisonPeriod } from "@gscdump/engine/period";
|
|
5
|
+
import { AnalysisQuerySource, QueryRow, RowQuerySource, SqlQuerySource } from "@gscdump/engine/resolver";
|
|
5
6
|
import { PlannerCapabilities } from "gscdump/query/plan";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
declare function analyzeFromSource(source: AnalysisQuerySource, params: AnalysisParams, registry: AnalyzerRegistry): Promise<AnalysisResult>;
|
|
8
|
+
interface CompositeSourceOptions {
|
|
9
|
+
engine: SqlQuerySource;
|
|
10
|
+
live: AnalysisQuerySource;
|
|
11
|
+
site: {
|
|
12
|
+
oldestDateSynced: string | null;
|
|
13
|
+
newestDateSynced: string | null;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare function createCompositeSource(opts: CompositeSourceOptions): SqlQuerySource;
|
|
17
|
+
/**
|
|
18
|
+
* Permissive defaults: in-memory sources are usually test doubles, so they
|
|
19
|
+
* advertise every capability unless the test explicitly narrows them.
|
|
20
|
+
*/
|
|
21
|
+
declare const IN_MEMORY_DEFAULT_CAPABILITIES: PlannerCapabilities;
|
|
22
|
+
interface InMemoryQuerySourceOptions {
|
|
23
|
+
queryRows: (state: BuilderState) => Promise<QueryRow[]> | QueryRow[];
|
|
24
|
+
capabilities?: PlannerCapabilities;
|
|
25
|
+
}
|
|
26
|
+
declare function createInMemoryQuerySource(options: InMemoryQuerySourceOptions): RowQuerySource;
|
|
27
|
+
/**
|
|
28
|
+
* Domain row shapes + analysis utilities. Analyzer-call contracts
|
|
29
|
+
* (`AnalysisParams`, `AnalysisResult`, `AnalysisTool`, `num`) live in
|
|
30
|
+
* `@gscdump/engine/analysis-types`.
|
|
31
|
+
*/
|
|
9
32
|
type SortOrder = 'asc' | 'desc';
|
|
10
33
|
/** Base search metrics */
|
|
11
34
|
interface BaseMetrics {
|
|
@@ -27,208 +50,6 @@ interface PageRow extends BaseMetrics {
|
|
|
27
50
|
interface DateRow extends BaseMetrics {
|
|
28
51
|
date: string;
|
|
29
52
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Capabilities a Plan may require of its host. A dispatcher matches these
|
|
32
|
-
* against a source's declared capabilities and rejects mismatches.
|
|
33
|
-
*/
|
|
34
|
-
type Capability = 'executeSql' | 'partitionedParquet' | 'attachedTables' | 'regex' | 'windowTotals' | 'comparisonJoin';
|
|
35
|
-
interface SqlExtraQuery {
|
|
36
|
-
name: string;
|
|
37
|
-
sql: string;
|
|
38
|
-
params: unknown[];
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* SQL-native plan: SQL string + placeholders, with optional extra file sets
|
|
42
|
-
* and follow-up queries. Mirrors the existing `AnalyzerSpec` shape but
|
|
43
|
-
* renamed for clarity under the unified contract.
|
|
44
|
-
*/
|
|
45
|
-
interface SqlPlan {
|
|
46
|
-
kind: 'sql';
|
|
47
|
-
sql: string;
|
|
48
|
-
params: unknown[];
|
|
49
|
-
current: FileSet;
|
|
50
|
-
previous?: FileSet;
|
|
51
|
-
extraFiles?: Record<string, FileSet>;
|
|
52
|
-
extraQueries?: SqlExtraQuery[];
|
|
53
|
-
/** Emits direct table refs (browser-only). Dispatcher rejects for manifest path. */
|
|
54
|
-
requiresAttachedTables?: boolean;
|
|
55
|
-
}
|
|
56
|
-
interface TypedRowQuery<T extends Row = Row> {
|
|
57
|
-
state: BuilderState;
|
|
58
|
-
/** Optional type tag for downstream narrowing. */
|
|
59
|
-
rowType?: (row: Row) => T;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Row-queries plan: a named set of typed `BuilderState` queries. A portable
|
|
63
|
-
* dispatcher runs each against a source's `queryRows` and hands the row
|
|
64
|
-
* collection to `reduce`.
|
|
65
|
-
*/
|
|
66
|
-
interface RowQueriesPlan {
|
|
67
|
-
kind: 'rows';
|
|
68
|
-
queries: Record<string, TypedRowQuery>;
|
|
69
|
-
}
|
|
70
|
-
type Plan = SqlPlan | RowQueriesPlan;
|
|
71
|
-
interface ReduceContext<TRow extends Row = Row> {
|
|
72
|
-
params: AnalysisParams;
|
|
73
|
-
/** Extra SQL-query results keyed by `SqlExtraQuery.name`. */
|
|
74
|
-
extras?: Record<string, TRow[]>;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Unified analyzer contract. `TRow` lets authors narrow from the default
|
|
78
|
-
* `Row = Record<string, unknown>` to a typed row shape (e.g. `KeywordRow`)
|
|
79
|
-
* when their reducer assumes specific columns exist — catches drift between
|
|
80
|
-
* `build` (SELECT list) and `reduce` (column access) at compile time.
|
|
81
|
-
*/
|
|
82
|
-
interface Analyzer<P extends AnalysisParams = AnalysisParams, R = unknown, TRow extends Row = Row> {
|
|
83
|
-
/** Stable tool id (e.g. `striking-distance`, `opportunity`). */
|
|
84
|
-
id: string;
|
|
85
|
-
/** Capabilities a host source must provide. */
|
|
86
|
-
requires: readonly Capability[];
|
|
87
|
-
/** Pure: params → plan. Snapshot-testable. */
|
|
88
|
-
build: (params: P) => Plan;
|
|
89
|
-
/** Pure: rows + context → typed result + meta. */
|
|
90
|
-
reduce: (rows: TRow[] | Record<string, TRow[]>, ctx: ReduceContext<TRow>) => {
|
|
91
|
-
results: R;
|
|
92
|
-
meta?: Record<string, unknown>;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
interface AnalyzerVariants {
|
|
96
|
-
sql?: Analyzer;
|
|
97
|
-
rows?: Analyzer;
|
|
98
|
-
}
|
|
99
|
-
interface AnalyzerRegistry {
|
|
100
|
-
listAnalyzerIds: () => readonly string[];
|
|
101
|
-
getAnalyzerVariants: (id: string) => AnalyzerVariants | undefined;
|
|
102
|
-
resolveAnalyzer: (id: string, sourceSupportsSql: boolean) => Analyzer | undefined;
|
|
103
|
-
listAnalyzersFor: (sourceSupportsSql: boolean) => readonly Analyzer[];
|
|
104
|
-
listAnalyzerIdsFor: (source: {
|
|
105
|
-
executeSql?: unknown;
|
|
106
|
-
}) => readonly string[];
|
|
107
|
-
}
|
|
108
|
-
interface TypedQuery<TRow> {
|
|
109
|
-
state: BuilderState;
|
|
110
|
-
readonly __row?: TRow;
|
|
111
|
-
}
|
|
112
|
-
declare function typedQuery<TRow>(state: BuilderState): TypedQuery<TRow>;
|
|
113
|
-
declare function queryRows<TRow = QueryRow$1>(source: AnalysisQuerySource$1, query: BuilderState | TypedQuery<TRow>): Promise<TRow[]>;
|
|
114
|
-
declare function queryComparisonRows<TRow = QueryRow$1>(source: AnalysisQuerySource$1, current: BuilderState | TypedQuery<TRow>, previous: BuilderState | TypedQuery<TRow>): Promise<{
|
|
115
|
-
current: TRow[];
|
|
116
|
-
previous: TRow[];
|
|
117
|
-
}>;
|
|
118
|
-
declare class AnalyzerCapabilityError extends Error {
|
|
119
|
-
readonly tool: string;
|
|
120
|
-
readonly missing: readonly Capability[];
|
|
121
|
-
constructor(tool: string, missing: readonly Capability[]);
|
|
122
|
-
}
|
|
123
|
-
declare function analyzeFromSource(source: AnalysisQuerySource, params: AnalysisParams, registry: AnalyzerRegistry): Promise<AnalysisResult>;
|
|
124
|
-
interface CompositeSourceOptions {
|
|
125
|
-
engine: SqlQuerySource;
|
|
126
|
-
live: AnalysisQuerySource;
|
|
127
|
-
site: {
|
|
128
|
-
oldestDateSynced: string | null;
|
|
129
|
-
newestDateSynced: string | null;
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
declare function createCompositeSource(opts: CompositeSourceOptions): SqlQuerySource;
|
|
133
|
-
/**
|
|
134
|
-
* Capabilities the engine query path honors. Matches what the DuckDB compiler
|
|
135
|
-
* passes to {@link buildLogicalPlan} (see `gscdump/analytics/compiler`): regex
|
|
136
|
-
* pushes down; comparison joins and multi-dataset queries belong to the
|
|
137
|
-
* analyzer dispatcher, not the engine's builder-state query path.
|
|
138
|
-
*/
|
|
139
|
-
declare const ENGINE_QUERY_CAPABILITIES: PlannerCapabilities;
|
|
140
|
-
interface EngineQuerySourceOptions {
|
|
141
|
-
engine: StorageEngine;
|
|
142
|
-
ctx: TenantCtx;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Wraps a storage engine as a {@link SqlQuerySource}. `queryRows` runs typed
|
|
146
|
-
* builder-state queries; `executeSql` delegates to `engine.runSQL` and
|
|
147
|
-
* requires `opts.fileSets` (with a `FILES` entry so the target table can be
|
|
148
|
-
* resolved for partition lookup).
|
|
149
|
-
*/
|
|
150
|
-
declare function createEngineQuerySource(options: EngineQuerySourceOptions): SqlQuerySource;
|
|
151
|
-
/**
|
|
152
|
-
* Convenience: wrap a storage engine + tenant ctx in a source and dispatch.
|
|
153
|
-
* Equivalent to
|
|
154
|
-
* `runAnalyzerFromSource(createEngineQuerySource({ engine, ctx }), params, registry)`.
|
|
155
|
-
*/
|
|
156
|
-
declare function runAnalyzerWithEngine(deps: {
|
|
157
|
-
engine: StorageEngine;
|
|
158
|
-
}, ctx: TenantCtx, params: AnalysisParams, registry: AnalyzerRegistry): Promise<AnalysisResult>;
|
|
159
|
-
/**
|
|
160
|
-
* Capabilities the live GSC API can satisfy. Regex pushes down via the
|
|
161
|
-
* `INCLUDING_REGEX` / `EXCLUDING_REGEX` filter types; comparison joins and
|
|
162
|
-
* cross-dataset queries do not exist on the wire, and the API does not
|
|
163
|
-
* expose window aggregations. Metric filters and ordering are honored by
|
|
164
|
-
* the source-layer post-process pass after row collection.
|
|
165
|
-
*/
|
|
166
|
-
declare const GSC_API_CAPABILITIES: PlannerCapabilities;
|
|
167
|
-
interface GscApiQuerySourceOptions {
|
|
168
|
-
client: GoogleSearchConsoleClient;
|
|
169
|
-
siteUrl: string;
|
|
170
|
-
}
|
|
171
|
-
declare function createGscApiQuerySource(options: GscApiQuerySourceOptions): RowQuerySource;
|
|
172
|
-
declare function collectRows<T>(gen: AsyncGenerator<T[]>): Promise<T[]>;
|
|
173
|
-
interface GscRange {
|
|
174
|
-
start: string;
|
|
175
|
-
end: string;
|
|
176
|
-
}
|
|
177
|
-
interface GscTopNRow {
|
|
178
|
-
key: string;
|
|
179
|
-
clicks: number;
|
|
180
|
-
impressions: number;
|
|
181
|
-
sum_position: number;
|
|
182
|
-
}
|
|
183
|
-
interface FetchTopNOptions<D extends Dimension> {
|
|
184
|
-
client: GoogleSearchConsoleClient;
|
|
185
|
-
siteUrl: string;
|
|
186
|
-
dimension: Column<D>;
|
|
187
|
-
range: GscRange;
|
|
188
|
-
/**
|
|
189
|
-
* Ask the GSC API to order by clicks desc. Skip for dimensions where GSC
|
|
190
|
-
* already returns sensibly ranked rows (e.g. country).
|
|
191
|
-
*/
|
|
192
|
-
orderByClicksDesc?: boolean;
|
|
193
|
-
/** Forwarded to the GSC builder. */
|
|
194
|
-
limit?: number;
|
|
195
|
-
/** Trim after the fact (e.g. country has no server-side limit). */
|
|
196
|
-
sliceTop?: number;
|
|
197
|
-
}
|
|
198
|
-
declare function fetchGscTopN<D extends Dimension>(opts: FetchTopNOptions<D>): Promise<GscTopNRow[]>;
|
|
199
|
-
interface GscDailyRow {
|
|
200
|
-
date: number;
|
|
201
|
-
clicks: number;
|
|
202
|
-
impressions: number;
|
|
203
|
-
sum_position: number;
|
|
204
|
-
anonymizedImpressionsPct: number;
|
|
205
|
-
}
|
|
206
|
-
declare function fetchGscDaily(opts: {
|
|
207
|
-
client: GoogleSearchConsoleClient;
|
|
208
|
-
siteUrl: string;
|
|
209
|
-
range: GscRange;
|
|
210
|
-
}): Promise<GscDailyRow[]>;
|
|
211
|
-
/**
|
|
212
|
-
* Permissive defaults: in-memory sources are usually test doubles, so they
|
|
213
|
-
* advertise every capability unless the test explicitly narrows them.
|
|
214
|
-
*/
|
|
215
|
-
declare const IN_MEMORY_DEFAULT_CAPABILITIES: PlannerCapabilities;
|
|
216
|
-
interface InMemoryQuerySourceOptions {
|
|
217
|
-
queryRows: (state: BuilderState) => Promise<QueryRow[]> | QueryRow[];
|
|
218
|
-
capabilities?: PlannerCapabilities;
|
|
219
|
-
}
|
|
220
|
-
declare function createInMemoryQuerySource(options: InMemoryQuerySourceOptions): RowQuerySource;
|
|
221
|
-
declare function canProxyToGsc(state: BuilderState): boolean;
|
|
222
|
-
interface CreateLiveGscSourceOptions {
|
|
223
|
-
/** GSC property URL (e.g. `sc-domain:example.com` or `https://example.com/`). */
|
|
224
|
-
siteUrl: string;
|
|
225
|
-
/**
|
|
226
|
-
* Returns a valid GSC access token. Called lazily on first query so refresh
|
|
227
|
-
* cost is paid only when the source actually runs. Host owns refresh logic.
|
|
228
|
-
*/
|
|
229
|
-
getAccessToken: () => Promise<string>;
|
|
230
|
-
}
|
|
231
|
-
declare function createLiveGscSource(opts: CreateLiveGscSourceOptions): AnalysisQuerySource;
|
|
232
53
|
interface BrandSegmentationOptions {
|
|
233
54
|
/** Brand terms to match against keywords (case-insensitive) */
|
|
234
55
|
brandTerms: string[];
|
|
@@ -382,14 +203,6 @@ interface SeasonalityResult {
|
|
|
382
203
|
monthlyBreakdown: MonthlyData[];
|
|
383
204
|
insufficientData: boolean;
|
|
384
205
|
}
|
|
385
|
-
interface AnalysisPeriod {
|
|
386
|
-
startDate: string;
|
|
387
|
-
endDate: string;
|
|
388
|
-
}
|
|
389
|
-
interface ComparisonPeriod {
|
|
390
|
-
current: AnalysisPeriod;
|
|
391
|
-
previous: AnalysisPeriod;
|
|
392
|
-
}
|
|
393
206
|
interface StrikingDistanceResult {
|
|
394
207
|
keyword: string;
|
|
395
208
|
page: string | null;
|
|
@@ -443,5 +256,4 @@ declare function analyzeClusteringFromSource(source: AnalysisQuerySource, period
|
|
|
443
256
|
declare function analyzeSeasonalityFromSource(source: AnalysisQuerySource, period: AnalysisPeriod, options?: SeasonalityOptions): Promise<SeasonalityResult>;
|
|
444
257
|
declare function analyzeDecayFromSource(source: AnalysisQuerySource, periods: ComparisonPeriod, options?: DecayOptions): Promise<DecayResult[]>;
|
|
445
258
|
declare function analyzeMoversFromSource(source: AnalysisQuerySource, periods: ComparisonPeriod, options?: MoversOptions): Promise<MoversResult>;
|
|
446
|
-
type
|
|
447
|
-
export { type AnalysisQuerySource, AnalyzerCapabilityError, type BrowserQueryRunner, type ComparisonQueryResult, type CompositeSourceOptions, type CreateLiveGscSourceOptions, ENGINE_QUERY_CAPABILITIES, type EngineQuerySourceOptions, type FetchTopNOptions, GSC_API_CAPABILITIES, type GscApiQuerySourceOptions, type GscDailyRow, type GscRange, type GscTopNRow, IN_MEMORY_DEFAULT_CAPABILITIES, type InMemoryQuerySourceOptions, type QueryDimension, type QueryOptions, type QueryResult, type QueryRow, type RowQuerySource, type SourceCapabilities, type SqlQuerySource, type SqliteQueryExecutor, type SqliteQuerySourceOptions, type TypedQuery, analyzeBrandSegmentationFromSource, analyzeClusteringFromSource, analyzeDecayFromSource, analyzeFromSource, analyzeKeywordConcentrationFromSource, analyzeMoversFromSource, analyzeOpportunityFromSource, analyzePageConcentrationFromSource, analyzeSeasonalityFromSource, analyzeStrikingDistanceFromSource, canProxyToGsc, collectRows as collectGscRows, createBrowserQuerySource, createCompositeSource, createEngineQuerySource, createGscApiQuerySource, createInMemoryQuerySource, createLiveGscSource, createSqliteQuerySource, fetchGscDaily, fetchGscTopN, isSqlQuerySource, queryAnalyticsFromSource, queryComparisonFromSource, queryComparisonRows, queryRows, runAnalyzerWithEngine, typedQuery };
|
|
259
|
+
export { AnalyzerCapabilityError, type ComparisonQueryResult, type CompositeSourceOptions, IN_MEMORY_DEFAULT_CAPABILITIES, type InMemoryQuerySourceOptions, type QueryDimension, type QueryOptions, type QueryResult, analyzeBrandSegmentationFromSource, analyzeClusteringFromSource, analyzeDecayFromSource, analyzeFromSource, analyzeKeywordConcentrationFromSource, analyzeMoversFromSource, analyzeOpportunityFromSource, analyzePageConcentrationFromSource, analyzeSeasonalityFromSource, analyzeStrikingDistanceFromSource, createCompositeSource, createInMemoryQuerySource, queryAnalyticsFromSource, queryComparisonFromSource };
|