@gscdump/analysis 1.0.2 → 1.0.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/errors.d.mts CHANGED
@@ -1,52 +1,2 @@
1
- type AnalysisErrorKind = 'missing-report-param' | 'missing-comparison-window' | 'missing-brand-terms' | 'unknown-report' | 'unknown-analyzer' | 'required-step-failed';
2
- type AnalysisError = {
3
- kind: 'missing-report-param';
4
- report: string;
5
- param: string;
6
- message: string;
7
- } | {
8
- kind: 'missing-comparison-window';
9
- report: string;
10
- message: string;
11
- } | {
12
- kind: 'missing-brand-terms';
13
- message: string;
14
- } | {
15
- kind: 'unknown-report';
16
- report: string;
17
- available: readonly string[];
18
- message: string;
19
- } | {
20
- kind: 'unknown-analyzer';
21
- analyzer: string;
22
- message: string;
23
- } | {
24
- kind: 'required-step-failed';
25
- report: string;
26
- stepKey: string;
27
- stepError: string;
28
- message: string;
29
- cause?: unknown;
30
- };
31
- declare const analysisErrors: {
32
- readonly missingReportParam: (report: string, param: string, message: string) => AnalysisError;
33
- readonly missingComparisonWindow: (report: string, message: string) => AnalysisError;
34
- readonly missingBrandTerms: () => AnalysisError;
35
- readonly unknownReport: (report: string, available: readonly string[]) => AnalysisError;
36
- readonly unknownAnalyzer: (analyzer: string) => AnalysisError;
37
- readonly requiredStepFailed: (report: string, stepKey: string, stepError: string, cause?: unknown) => AnalysisError;
38
- };
39
- declare function isAnalysisError(value: unknown): value is AnalysisError;
40
- /** The human-readable rendering of an `AnalysisError`, for logs and string sinks. */
41
- declare function formatAnalysisError(error: AnalysisError): string;
42
- /**
43
- * Re-raises an `AnalysisError` value as a generic `Error`, stashing the union
44
- * under `.analysisError` for stack-walking and preserving the original `cause`
45
- * (so a `required-step-failed` keeps the underlying thrown value reachable).
46
- * Used by the throwing wrappers over the `Result`-returning cores. The thrown
47
- * `.message` is kept verbatim from the union, so existing message-regex
48
- * assertions (`/--target/`, `/comparison window/`, `/required step "k"/`)
49
- * continue to match.
50
- */
51
- declare function analysisErrorToException(error: AnalysisError): Error;
1
+ import { AnalysisError, AnalysisErrorKind, analysisErrorToException, analysisErrors, formatAnalysisError, isAnalysisError } from "./_chunks/errors.mjs";
52
2
  export { AnalysisError, AnalysisErrorKind, analysisErrorToException, analysisErrors, formatAnalysisError, isAnalysisError };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,12 @@
1
- import { Analyzer, Analyzer as Analyzer$1, AnalyzerCapabilityError, AnalyzerRegistry, AnalyzerRegistry as AnalyzerRegistry$1, AnalyzerRegistryInit, AnalyzerVariants, DefineAnalyzerOptions, DefinedAnalyzer, Plan, ReduceContext, ReduceCtx, Reducer, RequiredCapability, RowQueriesPlan, SqlExtraQuery, SqlPlan, SqlPlanSpec, TypedRowQuery, createAnalyzerRegistry, defineAnalyzer, runAnalyzerFromSource } from "@gscdump/engine/analyzer";
1
+ import { ROW_ANALYZERS, SQL_ANALYZERS, defaultAnalyzerRegistry } from "./_chunks/default-registry.mjs";
2
+ import { AnalysisError, AnalysisErrorKind, analysisErrorToException, analysisErrors, formatAnalysisError, isAnalysisError } from "./_chunks/errors.mjs";
3
+ import { DryRunReportResult, FormatReportOptions, REPORTS, RunReportOptions, defaultReportRegistry, dryRunReport, formatReport, runReport, runReportResult } from "./_chunks/index.mjs";
4
+ import { CompositeSourceOptions, IN_MEMORY_DEFAULT_CAPABILITIES, InMemoryQuerySourceOptions, createCompositeSource, createInMemoryQuerySource } from "./_chunks/index2.mjs";
5
+ import { Analyzer, AnalyzerCapabilityError, AnalyzerRegistry, AnalyzerRegistry as AnalyzerRegistry$1, AnalyzerRegistryInit, AnalyzerVariants, DefineAnalyzerOptions, DefinedAnalyzer, Plan, ReduceContext, ReduceCtx, Reducer, RequiredCapability, RowQueriesPlan, SqlExtraQuery, SqlPlan, SqlPlanSpec, TypedRowQuery, createAnalyzerRegistry, defineAnalyzer, runAnalyzerFromSource } from "@gscdump/engine/analyzer";
2
6
  import { AnalysisPeriod, ComparisonMode, ComparisonPeriod, PadTimeseriesOptions, ResolveWindowOptions, ResolvedWindow, WindowPreset, comparisonOf, padTimeseries, periodOf, resolveWindow } from "@gscdump/engine/period";
3
7
  import { AnalysisParams, AnalysisParams as AnalysisParams$1, AnalysisResult, AnalysisResult as AnalysisResult$1, AnalysisTool, num } from "@gscdump/engine/analysis-types";
4
- import { Result } from "gscdump/result";
5
- import { BuilderState } from "gscdump/query";
6
- import { AnalysisQuerySource, AnalysisQuerySource as AnalysisQuerySource$1, AnalysisSourceKind, AttachedTableRunner, AttachedTableRunner as AnalyzerRunner, AttachedTableSourceOptions, AttachedTableSourceOptions as BrowserAnalyzeOptions, ENGINE_QUERY_CAPABILITIES, EngineQuerySourceOptions, ExecuteSqlOptions, FileSet, QueryRow, QueryRow as QueryRow$1, SourceCapabilities, createEngineQuerySource, queryRows, runAnalyzerWithEngine } from "@gscdump/engine/source";
7
- 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
- import { PlannerCapabilities } from "gscdump/query/plan";
8
+ import { AnalysisQuerySource, AnalysisSourceKind, AttachedTableRunner, AttachedTableRunner as AnalyzerRunner, AttachedTableSourceOptions, AttachedTableSourceOptions as BrowserAnalyzeOptions, ENGINE_QUERY_CAPABILITIES, EngineQuerySourceOptions, ExecuteSqlOptions, FileSet, QueryRow, SourceCapabilities, createEngineQuerySource, queryRows, runAnalyzerWithEngine } from "@gscdump/engine/source";
9
+ import { DefineReportOptions, DefinedReport, ReportAction, ReportContext, ReportFinding, ReportPlanStep, ReportResult, ReportSection } from "@gscdump/engine/report";
9
10
  type ActionSource = 'cannibalization' | 'striking-distance' | 'ctr-anomaly' | 'change-point' | 'opportunity';
10
11
  type Effort = 'low' | 'medium' | 'high';
11
12
  interface PriorityAction {
@@ -38,7 +39,6 @@ declare const DEFAULT_PRIORITY_SOURCES: ActionSource[];
38
39
  declare function normalizePriorityActions(source: ActionSource, result: AnalysisResult$1): PriorityAction[];
39
40
  declare function mergePriorityActions(all: PriorityAction[]): PriorityAction[];
40
41
  declare function scorePriorityActions(actions: PriorityAction[]): PriorityAction[];
41
- declare const ROW_ANALYZERS: readonly Analyzer$1[];
42
42
  /**
43
43
  * Domain row shapes + analysis utilities. Analyzer-call contracts
44
44
  * (`AnalysisParams`, `AnalysisResult`, `AnalysisTool`, `num`) live in
@@ -428,64 +428,6 @@ interface ZeroClickOptions {
428
428
  /** Pure zero-click detector shared by hosted and package analyzer callers. */
429
429
  declare function analyzeZeroClick(rows: QueryPageRow[], options?: ZeroClickOptions): ZeroClickResult[];
430
430
  declare function analyzeInBrowser(runner: AttachedTableRunner, opts: AttachedTableSourceOptions, params: AnalysisParams$1, registry: AnalyzerRegistry$1): Promise<AnalysisResult$1>;
431
- /**
432
- * Default analyzer registry built from every in-tree analyzer. Convenience
433
- * for callers who don't care about bundle size; edge / browser consumers
434
- * should compose their own narrower registry via `createAnalyzerRegistry`
435
- * with the flat `ROW_ANALYZERS` / `SQL_ANALYZERS` arrays.
436
- */
437
- declare const defaultAnalyzerRegistry: import("@gscdump/engine/analyzer").AnalyzerRegistry;
438
- type AnalysisErrorKind = 'missing-report-param' | 'missing-comparison-window' | 'missing-brand-terms' | 'unknown-report' | 'unknown-analyzer' | 'required-step-failed';
439
- type AnalysisError = {
440
- kind: 'missing-report-param';
441
- report: string;
442
- param: string;
443
- message: string;
444
- } | {
445
- kind: 'missing-comparison-window';
446
- report: string;
447
- message: string;
448
- } | {
449
- kind: 'missing-brand-terms';
450
- message: string;
451
- } | {
452
- kind: 'unknown-report';
453
- report: string;
454
- available: readonly string[];
455
- message: string;
456
- } | {
457
- kind: 'unknown-analyzer';
458
- analyzer: string;
459
- message: string;
460
- } | {
461
- kind: 'required-step-failed';
462
- report: string;
463
- stepKey: string;
464
- stepError: string;
465
- message: string;
466
- cause?: unknown;
467
- };
468
- declare const analysisErrors: {
469
- readonly missingReportParam: (report: string, param: string, message: string) => AnalysisError;
470
- readonly missingComparisonWindow: (report: string, message: string) => AnalysisError;
471
- readonly missingBrandTerms: () => AnalysisError;
472
- readonly unknownReport: (report: string, available: readonly string[]) => AnalysisError;
473
- readonly unknownAnalyzer: (analyzer: string) => AnalysisError;
474
- readonly requiredStepFailed: (report: string, stepKey: string, stepError: string, cause?: unknown) => AnalysisError;
475
- };
476
- declare function isAnalysisError(value: unknown): value is AnalysisError;
477
- /** The human-readable rendering of an `AnalysisError`, for logs and string sinks. */
478
- declare function formatAnalysisError(error: AnalysisError): string;
479
- /**
480
- * Re-raises an `AnalysisError` value as a generic `Error`, stashing the union
481
- * under `.analysisError` for stack-walking and preserving the original `cause`
482
- * (so a `required-step-failed` keeps the underlying thrown value reachable).
483
- * Used by the throwing wrappers over the `Result`-returning cores. The thrown
484
- * `.message` is kept verbatim from the union, so existing message-regex
485
- * assertions (`/--target/`, `/comparison window/`, `/required step "k"/`)
486
- * continue to match.
487
- */
488
- declare function analysisErrorToException(error: AnalysisError): Error;
489
431
  declare const INTENT_CLASSIFIER_VERSION = 1;
490
432
  type SearchIntent = 'transactional' | 'commercial' | 'informational' | 'unknown';
491
433
  interface IntentClassification {
@@ -519,61 +461,6 @@ declare const NORMALIZER_VERSION = 2;
519
461
  * Idempotent: `normalizeQuery(normalizeQuery(q)) === normalizeQuery(q)`.
520
462
  */
521
463
  declare function normalizeQuery(query: string): string;
522
- interface FormatReportOptions {
523
- /** Cap findings rendered per section. Defaults to all (already bounded by report). */
524
- maxFindingsPerSection?: number;
525
- }
526
- declare function formatReport(report: ReportResult$1, opts?: FormatReportOptions): string;
527
- declare const REPORTS: readonly DefinedReport$1<ReportParams>[];
528
- declare const defaultReportRegistry: import("@gscdump/engine/report").ReportRegistry;
529
- interface RunReportOptions<P extends ReportParams = ReportParams> {
530
- source: AnalysisQuerySource$1;
531
- analyzers: AnalyzerRegistry$1;
532
- ctx: ReportContext$1<P>;
533
- }
534
- /**
535
- * `Result`-returning core for {@link runReport}. Models the one
536
- * caller-actionable failure of a structurally-valid report run: a required
537
- * step's analyzer threw (`required-step-failed`, with the underlying error as
538
- * `cause`). Hosts can map that to a 4xx/partial response instead of catching an
539
- * untyped `Error`.
540
- *
541
- * Steps execute in parallel via `Promise.all`. The report's `reduce` is invoked
542
- * with a results bag that only contains successful steps — sections that
543
- * depended on a failed step should set their own `coverage: 'partial'` (the
544
- * runtime additionally marks `meta.degraded` when any step errored).
545
- *
546
- * The report's own `plan()` param-validation throws (`--target` etc.) are
547
- * defects from this core's perspective and still propagate; those are modelled
548
- * at the report-definition boundary, not here.
549
- */
550
- declare function runReportResult<P extends ReportParams = ReportParams>(report: DefinedReport$1<P>, opts: RunReportOptions<P>): Promise<Result<ReportResult$1, AnalysisError>>;
551
- /**
552
- * Throwing wrapper over {@link runReportResult}, preserving the historical
553
- * call-site ergonomics (a required-step failure rejects). The thrown message is
554
- * kept verbatim (`runReport(id): required step "k" failed: ...`) so existing
555
- * assertions hold; the typed `AnalysisError` is reachable via `.analysisError`
556
- * and the original failure via `.cause`.
557
- */
558
- declare function runReport<P extends ReportParams = ReportParams>(report: DefinedReport$1<P>, opts: RunReportOptions<P>): Promise<ReportResult$1>;
559
- interface DryRunReportResult {
560
- steps: {
561
- key: string;
562
- type: string;
563
- estRowsScanned?: number;
564
- }[];
565
- windowResolved: {
566
- start: string;
567
- end: string;
568
- days: number;
569
- };
570
- }
571
- /**
572
- * Plan-only preview. v1 doesn't compute row estimates — analyzer-level
573
- * cost models don't exist yet — so `estRowsScanned` is left undefined.
574
- * Useful right now only as an "is this report wired up correctly?" check.
575
- */
576
- declare function dryRunReport<P extends ReportParams = ReportParams>(report: DefinedReport$1<P>, ctx: ReportContext$1<P>): Promise<DryRunReportResult>;
577
464
  interface SitemapHealthRow {
578
465
  path: string;
579
466
  errors: number;
@@ -607,38 +494,4 @@ interface SitemapHealthDiff {
607
494
  totals: SitemapHealthTotals;
608
495
  }
609
496
  declare function diffSitemapHealth(prev: readonly SitemapHealthRow[], curr: readonly SitemapHealthInput[]): SitemapHealthDiff;
610
- interface SyncedRange {
611
- oldestDateSynced: string | null;
612
- newestDateSynced: string | null;
613
- /**
614
- * Optional sorted list of `[start, end]` daily-key spans (`YYYY-MM-DD`,
615
- * both inclusive) that the engine actually has partitions for. When set,
616
- * `shouldRouteToLive` returns true for any requested range that overlaps
617
- * a day NOT inside one of these spans — even when the request sits inside
618
- * `oldestDateSynced..newestDateSynced`. Lets the composite catch *internal*
619
- * manifest gaps (e.g. a missing monthly tier) that the outer envelope
620
- * doesn't reveal. Spans must be sorted by `start` and non-overlapping.
621
- */
622
- coveredSpans?: ReadonlyArray<{
623
- start: string;
624
- end: string;
625
- }>;
626
- }
627
- interface CompositeSourceOptions {
628
- engine: AnalysisQuerySource$1;
629
- live: AnalysisQuerySource$1;
630
- site: SyncedRange;
631
- }
632
- declare function createCompositeSource(opts: CompositeSourceOptions): AnalysisQuerySource$1;
633
- /**
634
- * Permissive defaults: in-memory sources are usually test doubles, so they
635
- * advertise every capability unless the test explicitly narrows them.
636
- */
637
- declare const IN_MEMORY_DEFAULT_CAPABILITIES: PlannerCapabilities;
638
- interface InMemoryQuerySourceOptions {
639
- queryRows: (state: BuilderState) => Promise<QueryRow$1[]> | QueryRow$1[];
640
- capabilities?: PlannerCapabilities;
641
- }
642
- declare function createInMemoryQuerySource(options: InMemoryQuerySourceOptions): AnalysisQuerySource$1;
643
- declare const SQL_ANALYZERS: readonly Analyzer$1[];
644
497
  export { type ActionPriorityResult, type ActionPrioritySourceState, type ActionPrioritySourceStatus, type ActionSource, type AnalysisError, type AnalysisErrorKind, type AnalysisParams, type AnalysisPeriod, type AnalysisQuerySource, type AnalysisResult, type AnalysisSourceKind, type AnalysisTool, type Analyzer, AnalyzerCapabilityError, type AnalyzerRegistry, type AnalyzerRegistryInit, type AnalyzerRunner, type AnalyzerVariants, type BaseMetrics, type BrandSegmentationOptions, type BrandSegmentationResult, type BrandSegmentationRow, type BrandSummary, type BrowserAnalyzeOptions, type CannibalizationCompetitor, type CannibalizationEvent, type CannibalizationOptions, type CannibalizationPage, type CannibalizationResult, type CannibalizationSortMetric, type ClusterType, type ClusteringOptions, type ClusteringResult, type ComparisonMode, type ComparisonPeriod, 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, INTENT_CLASSIFIER_VERSION, IN_MEMORY_DEFAULT_CAPABILITIES, type InMemoryQuerySourceOptions, type IntentClassification, type KeywordCluster, type MonthlyData, type MoverData, type MoversInput, type MoversOptions, type MoversResult, type MoversSortMetric, NORMALIZER_VERSION, type OpportunityFactors, type OpportunityOptions, type OpportunityResult, type OpportunitySortMetric, type OpportunityWeights, type PadTimeseriesOptions, type PageRow, type Plan, type PriorityAction, type QueriesRow, type QueryPageRow, type QueryRow, REPORTS, ROW_ANALYZERS, type ReduceContext, type ReduceCtx, type Reducer, type ReportAction, type ReportContext, type ReportFinding, type ReportPlanStep, type ReportResult, type ReportSection, type RequiredCapability, type ResolveWindowOptions, type ResolvedWindow, type RowQueriesPlan, type RunReportOptions, SEARCH_INTENT_CODE, SQL_ANALYZERS, type SearchIntent, type SeasonalityMetric, type SeasonalityOptions, type SeasonalityResult, type SitemapDelta, type SitemapHealthDiff, type SitemapHealthInput, type SitemapHealthRow, type SitemapHealthTotals, type SortOrder, type SourceCapabilities, type SqlExtraQuery, type SqlPlan, type SqlPlanSpec, type StrikingDistanceInputRow, type StrikingDistanceOptions, type StrikingDistanceResult, type TypedRowQuery, type WindowPreset, type ZeroClickOptions, type ZeroClickResult, analysisErrorToException, analysisErrors, analyzeBrandSegmentation, analyzeCannibalization, analyzeClustering, analyzeConcentration, analyzeDecay, analyzeInBrowser, analyzeKeywordConcentration, analyzeMovers, analyzeOpportunity, analyzePageConcentration, analyzeSeasonality, analyzeStrikingDistance, analyzeZeroClick, classifyQueryIntent, comparisonOf, createAnalyzerRegistry, createCompositeSource, createEngineQuerySource, createInMemoryQuerySource, createSorter, defaultAnalyzerRegistry, defaultReportRegistry, defineAnalyzer, diffSitemapHealth, dryRunReport, encodeIntent, formatAnalysisError, formatReport, isAnalysisError, mergePriorityActions, normalizePriorityActions, normalizeQuery, num, padTimeseries, periodOf, queryRows, resolveWindow, runAnalyzerFromSource, runAnalyzerWithEngine, runReport, runReportResult, scorePriorityActions };