@gscdump/analysis 0.8.2 → 0.9.1

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 CHANGED
@@ -49,14 +49,24 @@ const movers = analyzeMovers(currentRows, previousRows)
49
49
  const decay = analyzeDecay(currentRows, previousRows)
50
50
  ```
51
51
 
52
- Meta-analysis helpers are available too:
52
+ Meta-analyses live in the report layer. Run a composed, ranked priority list via `runReport`:
53
53
 
54
54
  ```ts
55
- import { analyzeActionPriority } from '@gscdump/analysis'
56
-
57
- const prioritized = await analyzeActionPriority({
58
- analyze: params => runner.analyze(params),
55
+ import {
56
+ defaultAnalyzerRegistry,
57
+ defaultReportRegistry,
58
+ runReport,
59
+ } from '@gscdump/analysis'
60
+ import { resolveWindow } from '@gscdump/engine/period'
61
+
62
+ const report = defaultReportRegistry.getReport('priority')!
63
+ const window = resolveWindow({ preset: 'last-28d', comparison: 'prev-period' })
64
+ const result = await runReport(report, {
65
+ source,
66
+ analyzers: defaultAnalyzerRegistry,
67
+ ctx: { site: siteUrl, window, params: {}, registryVersion: defaultReportRegistry.version },
59
68
  })
69
+ // result.sections[0].findings — ranked priority actions, page+query keyed.
60
70
  ```
61
71
 
62
72
  Source adapters compose a GSC client + analyzer in one call:
@@ -2754,8 +2754,7 @@ const keywordBreadthAnalyzer = defineAnalyzer({
2754
2754
  FROM per_page
2755
2755
  )
2756
2756
  SELECT
2757
- (SELECT to_json(list({ 'bucket': bucket, 'pageCount': pageCount, 'sortKey': sort_key })
2758
- ORDER BY sort_key ASC) FROM bucketed) AS distribution_json,
2757
+ (SELECT to_json(list({ 'bucket': bucket, 'pageCount': pageCount, 'sortKey': sort_key })) FROM bucketed) AS distribution_json,
2759
2758
  (SELECT to_json(list({ 'url': url, 'keywordCount': keywordCount, 'clicks': clicks, 'impressions': impressions })) FROM fragile) AS fragile_json,
2760
2759
  (SELECT to_json(list({ 'url': url, 'keywordCount': keywordCount, 'clicks': clicks, 'impressions': impressions })) FROM authority) AS authority_json,
2761
2760
  (SELECT to_json({
@@ -3570,8 +3570,7 @@ const keywordBreadthAnalyzer = defineAnalyzer({
3570
3570
  FROM per_page
3571
3571
  )
3572
3572
  SELECT
3573
- (SELECT to_json(list({ 'bucket': bucket, 'pageCount': pageCount, 'sortKey': sort_key })
3574
- ORDER BY sort_key ASC) FROM bucketed) AS distribution_json,
3573
+ (SELECT to_json(list({ 'bucket': bucket, 'pageCount': pageCount, 'sortKey': sort_key })) FROM bucketed) AS distribution_json,
3575
3574
  (SELECT to_json(list({ 'url': url, 'keywordCount': keywordCount, 'clicks': clicks, 'impressions': impressions })) FROM fragile) AS fragile_json,
3576
3575
  (SELECT to_json(list({ 'url': url, 'keywordCount': keywordCount, 'clicks': clicks, 'impressions': impressions })) FROM authority) AS authority_json,
3577
3576
  (SELECT to_json({
package/dist/index.d.mts CHANGED
@@ -1,10 +1,12 @@
1
+ import { AnalysisParams, AnalysisParams as AnalysisParams$1, AnalysisResult, AnalysisResult as AnalysisResult$1, AnalysisTool, num } from "@gscdump/engine/analysis-types";
1
2
  import * as _$_gscdump_engine_analyzer0 from "@gscdump/engine/analyzer";
2
3
  import { Analyzer, Analyzer as Analyzer$1, AnalyzerCapabilityError, AnalyzerRegistry, AnalyzerRegistry as AnalyzerRegistry$1, AnalyzerRegistryInit, AnalyzerVariants, Capability, DefineAnalyzerOptions, DefinedAnalyzer, Plan, ReduceContext, ReduceCtx, Reducer, RowQueriesPlan, SqlExtraQuery, SqlPlan, SqlPlanSpec, TypedRowQuery, createAnalyzerRegistry, defineAnalyzer, runAnalyzerFromSource } from "@gscdump/engine/analyzer";
3
- import { AnalysisParams, AnalysisParams as AnalysisParams$1, AnalysisResult, AnalysisResult as AnalysisResult$1, AnalysisTool, num } from "@gscdump/engine/analysis-types";
4
4
  import { AnalysisPeriod, AnalysisPeriod as AnalysisPeriod$1, ComparisonMode, ComparisonPeriod, ComparisonPeriod as ComparisonPeriod$1, PadTimeseriesOptions, ResolveWindowOptions, ResolvedWindow, WindowPreset, comparisonOf, padTimeseries, periodOf, resolveWindow, windowToComparisonPeriod, windowToPeriod } from "@gscdump/engine/period";
5
5
  import { BuilderState } from "gscdump/query";
6
6
  import { AttachedTableRunner, AttachedTableRunner as AnalyzerRunner, AttachedTableSourceOptions, AttachedTableSourceOptions as BrowserAnalyzeOptions, ENGINE_QUERY_CAPABILITIES, EngineQuerySourceOptions, TypedQuery, createEngineQuerySource, queryComparisonRows, queryRows, rewriteForTableSource, runAnalyzerWithEngine, typedQuery } from "@gscdump/engine/source";
7
7
  import { AnalysisQuerySource, AnalysisQuerySource as AnalysisQuerySource$1, ExecuteSqlOptions, FileSet, QueryRow, QueryRow as QueryRow$1, RowQuerySource, RowQuerySource as RowQuerySource$1, SourceCapabilities, SqlQuerySource, SqlQuerySource as SqlQuerySource$1, isSqlQuerySource } from "@gscdump/engine/resolver";
8
+ import * as _$_gscdump_engine_report0 from "@gscdump/engine/report";
9
+ import { DefineReportOptions, DefinedReport, DefinedReport as DefinedReport$1, ReportAction, ReportContext, ReportContext as ReportContext$1, ReportFinding, ReportParams, ReportPlanStep, ReportResult, ReportResult as ReportResult$1, ReportSection } from "@gscdump/engine/report";
8
10
  import { PlannerCapabilities } from "gscdump/query/plan";
9
11
  type ActionSource = 'cannibalization' | 'striking-distance' | 'ctr-anomaly' | 'change-point' | 'opportunity';
10
12
  type Effort = 'low' | 'medium' | 'high';
@@ -34,29 +36,10 @@ interface ActionPriorityResult {
34
36
  totalSignals: number;
35
37
  sources: ActionPrioritySourceState[];
36
38
  }
37
- interface ActionPriorityRunOptions {
38
- sources?: ActionSource[];
39
- limit?: number;
40
- continueOnError?: boolean;
41
- paramsBySource?: Partial<Record<ActionSource, Omit<AnalysisParams$1, 'type'>>>;
42
- onSourceStatus?: (state: ActionPrioritySourceState) => void;
43
- }
44
- interface ActionPriorityAnalyzer {
45
- analyze: (params: AnalysisParams$1) => Promise<AnalysisResult$1>;
46
- }
39
+ declare const DEFAULT_PRIORITY_SOURCES: ActionSource[];
47
40
  declare function normalizePriorityActions(source: ActionSource, result: AnalysisResult$1): PriorityAction[];
48
41
  declare function mergePriorityActions(all: PriorityAction[]): PriorityAction[];
49
42
  declare function scorePriorityActions(actions: PriorityAction[]): PriorityAction[];
50
- declare function analyzeActionPriority(analyzer: ActionPriorityAnalyzer, options?: ActionPriorityRunOptions): Promise<ActionPriorityResult>;
51
- /**
52
- * Convenience wrapper: build the analyzer callback from an
53
- * {@link AnalysisQuerySource} so consumers don't hand-roll the adapter.
54
- * SQL-only tools (e.g. `cannibalization`, `ctr-anomaly`, `change-point`) will
55
- * surface as `status: 'error'` on their source state when the source lacks a
56
- * row-based implementation — `continueOnError` defaults to true, so the
57
- * overall run still produces whatever the other analyzers found.
58
- */
59
- declare function analyzeActionPriorityFromSource(source: AnalysisQuerySource$1, registry: AnalyzerRegistry$1, options?: ActionPriorityRunOptions): Promise<ActionPriorityResult>;
60
43
  declare const ROW_ANALYZERS: readonly Analyzer$1[];
61
44
  /**
62
45
  * Domain row shapes + analysis utilities. Analyzer-call contracts
@@ -379,6 +362,44 @@ declare const defaultAnalyzerRegistry: _$_gscdump_engine_analyzer0.AnalyzerRegis
379
362
  * Idempotent: `normalizeQuery(normalizeQuery(q)) === normalizeQuery(q)`.
380
363
  */
381
364
  declare function normalizeQuery(query: string): string;
365
+ interface FormatReportOptions {
366
+ /** Cap findings rendered per section. Defaults to all (already bounded by report). */
367
+ maxFindingsPerSection?: number;
368
+ }
369
+ declare function formatReport(report: ReportResult$1, opts?: FormatReportOptions): string;
370
+ declare const REPORTS: readonly DefinedReport$1<ReportParams>[];
371
+ declare const defaultReportRegistry: _$_gscdump_engine_report0.ReportRegistry;
372
+ interface RunReportOptions<P extends ReportParams = ReportParams> {
373
+ source: AnalysisQuerySource$1;
374
+ analyzers: AnalyzerRegistry$1;
375
+ ctx: ReportContext$1<P>;
376
+ }
377
+ /**
378
+ * Run a defined report against a source. Steps execute in parallel via
379
+ * `Promise.all`. The report's `reduce` is invoked with a results bag that
380
+ * only contains successful steps — sections that depended on a failed step
381
+ * should set their own `coverage: 'partial'` (the runtime additionally
382
+ * marks `meta.degraded` when any step errored).
383
+ */
384
+ declare function runReport<P extends ReportParams = ReportParams>(report: DefinedReport$1<P>, opts: RunReportOptions<P>): Promise<ReportResult$1>;
385
+ interface DryRunReportResult {
386
+ steps: {
387
+ key: string;
388
+ type: string;
389
+ estRowsScanned?: number;
390
+ }[];
391
+ windowResolved: {
392
+ start: string;
393
+ end: string;
394
+ days: number;
395
+ };
396
+ }
397
+ /**
398
+ * Plan-only preview. v1 doesn't compute row estimates — analyzer-level
399
+ * cost models don't exist yet — so `estRowsScanned` is left undefined.
400
+ * Useful right now only as an "is this report wired up correctly?" check.
401
+ */
402
+ declare function dryRunReport<P extends ReportParams = ReportParams>(report: DefinedReport$1<P>, ctx: ReportContext$1<P>): Promise<DryRunReportResult>;
382
403
  declare function analyzeFromSource(source: AnalysisQuerySource$1, params: AnalysisParams$1, registry: AnalyzerRegistry$1): Promise<AnalysisResult$1>;
383
404
  interface CompositeSourceOptions {
384
405
  engine: SqlQuerySource$1;
@@ -458,4 +479,4 @@ declare function analyzeSeasonalityFromSource(source: AnalysisQuerySource$1, per
458
479
  declare function analyzeDecayFromSource(source: AnalysisQuerySource$1, periods: ComparisonPeriod$1, options?: DecayOptions): Promise<DecayResult[]>;
459
480
  declare function analyzeMoversFromSource(source: AnalysisQuerySource$1, periods: ComparisonPeriod$1, options?: MoversOptions): Promise<MoversResult>;
460
481
  declare const SQL_ANALYZERS: readonly Analyzer$1[];
461
- export { type ActionPriorityAnalyzer, type ActionPriorityResult, type ActionPriorityRunOptions, type ActionPrioritySourceState, type ActionPrioritySourceStatus, type ActionSource, type AnalysisParams, type AnalysisPeriod, type AnalysisQuerySource, type AnalysisResult, type AnalysisTool, type Analyzer, AnalyzerCapabilityError, type AnalyzerRegistry, type AnalyzerRegistryInit, type AnalyzerRunner, type AnalyzerVariants, type BaseMetrics, type BrandSegmentationOptions, type BrandSegmentationResult, type BrandSummary, type BrowserAnalyzeOptions, type CannibalizationCompetitor, type CannibalizationEvent, type CannibalizationOptions, type CannibalizationPage, type CannibalizationResult, type CannibalizationSortMetric, type Capability, type ClusterType, type ClusteringOptions, type ClusteringResult, type ComparisonMode, type ComparisonPeriod, type ComparisonQueryResult, type CompositeSourceOptions, type ConcentrationInput, type ConcentrationItem, type ConcentrationOptions, type ConcentrationResult, type ConcentrationRiskLevel, type DateRow, type DecayInput, type DecayOptions, type DecayResult, type DecaySeriesPoint, type DecaySortMetric, type DefineAnalyzerOptions, type DefinedAnalyzer, ENGINE_QUERY_CAPABILITIES, type Effort, type EngineQuerySourceOptions, type ExecuteSqlOptions, type FileSet, IN_MEMORY_DEFAULT_CAPABILITIES, type InMemoryQuerySourceOptions, type KeywordCluster, type KeywordRow, type MonthlyData, type MoverData, type MoversInput, type MoversOptions, type MoversResult, type MoversSortMetric, type OpportunityResult, type PadTimeseriesOptions, type PageRow, type Plan, type PriorityAction, type QueryDimension, type QueryOptions, type QueryPageRow, type QueryResult, type QueryRow, ROW_ANALYZERS, type ReduceContext, type ReduceCtx, type Reducer, type ResolveWindowOptions, type ResolvedWindow, type RowQueriesPlan, type RowQuerySource, SQL_ANALYZERS, type SeasonalityMetric, type SeasonalityOptions, type SeasonalityResult, type SortOrder, type SourceCapabilities, type SqlExtraQuery, type SqlPlan, type SqlPlanSpec, type SqlQuerySource, type StrikingDistanceOptions, type StrikingDistanceResult, type StrikingDistanceSortMetric, type TypedQuery, type TypedRowQuery, type WindowPreset, type ZeroClickResult, analyzeActionPriority, analyzeActionPriorityFromSource, analyzeBrandSegmentation, analyzeBrandSegmentationFromSource, analyzeCannibalization, analyzeClustering, analyzeClusteringFromSource, analyzeConcentration, analyzeDecay, analyzeDecayFromSource, analyzeFromSource, analyzeInBrowser, analyzeKeywordConcentration, analyzeKeywordConcentrationFromSource, analyzeMovers, analyzeMoversFromSource, analyzeOpportunityFromSource, analyzePageConcentration, analyzePageConcentrationFromSource, analyzeSeasonality, analyzeSeasonalityFromSource, analyzeStrikingDistance, analyzeStrikingDistanceFromSource, comparisonOf, createAnalyzerRegistry, createCompositeSource, createEngineQuerySource, createInMemoryQuerySource, createSorter, defaultAnalyzerRegistry, defineAnalyzer, isSqlQuerySource, mergePriorityActions, normalizePriorityActions, normalizeQuery, num, padTimeseries, periodOf, queryAnalyticsFromSource, queryComparisonFromSource, queryComparisonRows, queryRows, resolveWindow, rewriteForTableSource, runAnalyzerFromSource, runAnalyzerWithEngine, scorePriorityActions, typedQuery, windowToComparisonPeriod, windowToPeriod };
482
+ export { type ActionPriorityResult, type ActionPrioritySourceState, type ActionPrioritySourceStatus, type ActionSource, type AnalysisParams, type AnalysisPeriod, type AnalysisQuerySource, type AnalysisResult, type AnalysisTool, type Analyzer, AnalyzerCapabilityError, type AnalyzerRegistry, type AnalyzerRegistryInit, type AnalyzerRunner, type AnalyzerVariants, type BaseMetrics, type BrandSegmentationOptions, type BrandSegmentationResult, type BrandSummary, type BrowserAnalyzeOptions, type CannibalizationCompetitor, type CannibalizationEvent, type CannibalizationOptions, type CannibalizationPage, type CannibalizationResult, type CannibalizationSortMetric, type Capability, type ClusterType, type ClusteringOptions, type ClusteringResult, type ComparisonMode, type ComparisonPeriod, type ComparisonQueryResult, type CompositeSourceOptions, type ConcentrationInput, type ConcentrationItem, type ConcentrationOptions, type ConcentrationResult, type ConcentrationRiskLevel, DEFAULT_PRIORITY_SOURCES, type DateRow, type DecayInput, type DecayOptions, type DecayResult, type DecaySeriesPoint, type DecaySortMetric, type DefineAnalyzerOptions, type DefineReportOptions, type DefinedAnalyzer, type DefinedReport, type DryRunReportResult, ENGINE_QUERY_CAPABILITIES, type Effort, type EngineQuerySourceOptions, type ExecuteSqlOptions, type FileSet, type FormatReportOptions, IN_MEMORY_DEFAULT_CAPABILITIES, type InMemoryQuerySourceOptions, type KeywordCluster, type KeywordRow, type MonthlyData, type MoverData, type MoversInput, type MoversOptions, type MoversResult, type MoversSortMetric, type OpportunityResult, type PadTimeseriesOptions, type PageRow, type Plan, type PriorityAction, type QueryDimension, type QueryOptions, type QueryPageRow, type QueryResult, type QueryRow, REPORTS, ROW_ANALYZERS, type ReduceContext, type ReduceCtx, type Reducer, type ReportAction, type ReportContext, type ReportFinding, type ReportPlanStep, type ReportResult, type ReportSection, type ResolveWindowOptions, type ResolvedWindow, type RowQueriesPlan, type RowQuerySource, type RunReportOptions, SQL_ANALYZERS, type SeasonalityMetric, type SeasonalityOptions, type SeasonalityResult, type SortOrder, type SourceCapabilities, type SqlExtraQuery, type SqlPlan, type SqlPlanSpec, type SqlQuerySource, type StrikingDistanceOptions, type StrikingDistanceResult, type StrikingDistanceSortMetric, type TypedQuery, type TypedRowQuery, type WindowPreset, type ZeroClickResult, analyzeBrandSegmentation, analyzeBrandSegmentationFromSource, analyzeCannibalization, analyzeClustering, analyzeClusteringFromSource, analyzeConcentration, analyzeDecay, analyzeDecayFromSource, analyzeFromSource, analyzeInBrowser, analyzeKeywordConcentration, analyzeKeywordConcentrationFromSource, analyzeMovers, analyzeMoversFromSource, analyzeOpportunityFromSource, analyzePageConcentration, analyzePageConcentrationFromSource, analyzeSeasonality, analyzeSeasonalityFromSource, analyzeStrikingDistance, analyzeStrikingDistanceFromSource, comparisonOf, createAnalyzerRegistry, createCompositeSource, createEngineQuerySource, createInMemoryQuerySource, createSorter, defaultAnalyzerRegistry, defaultReportRegistry, defineAnalyzer, dryRunReport, formatReport, isSqlQuerySource, mergePriorityActions, normalizePriorityActions, normalizeQuery, num, padTimeseries, periodOf, queryAnalyticsFromSource, queryComparisonFromSource, queryComparisonRows, queryRows, resolveWindow, rewriteForTableSource, runAnalyzerFromSource, runAnalyzerWithEngine, runReport, scorePriorityActions, typedQuery, windowToComparisonPeriod, windowToPeriod };