@gscdump/analysis 1.0.1 → 1.0.3

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.
@@ -0,0 +1,52 @@
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;
52
+ export { AnalysisError, AnalysisErrorKind, analysisErrorToException, analysisErrors, formatAnalysisError, isAnalysisError };
@@ -0,0 +1,89 @@
1
+ import { AnalysisError } from "./errors.mjs";
2
+ import { AnalyzerRegistry } from "@gscdump/engine/analyzer";
3
+ import { Result } from "gscdump/result";
4
+ import { AnalysisQuerySource } from "@gscdump/engine/source";
5
+ import { DefinedReport, ReportContext, ReportParams, ReportResult } from "@gscdump/engine/report";
6
+ interface FormatReportOptions {
7
+ /** Cap findings rendered per section. Defaults to all (already bounded by report). */
8
+ maxFindingsPerSection?: number;
9
+ }
10
+ declare function formatReport(report: ReportResult, opts?: FormatReportOptions): string;
11
+ declare const REPORTS: readonly DefinedReport<ReportParams>[];
12
+ declare const defaultReportRegistry: import("@gscdump/engine/report").ReportRegistry;
13
+ /**
14
+ * `resolveTarget()` — stub day-one resolver. Future versions can wire in
15
+ * fuzzy matching / embedding similarity / a manifest cache without
16
+ * changing the contract.
17
+ *
18
+ * Today: case-insensitive exact match, falling back to substring (LIKE %x%)
19
+ * over a caller-supplied candidate list.
20
+ */
21
+ type ResolveTargetKind = 'page' | 'query';
22
+ interface ResolveTargetInput {
23
+ kind: ResolveTargetKind;
24
+ input: string;
25
+ /**
26
+ * Pool to resolve against. Empty pool ⇒ caller trusts the input verbatim
27
+ * (resolver returns it as `exact`). Useful when the caller doesn't have
28
+ * a candidate list yet but knows the value is correct.
29
+ */
30
+ candidates?: readonly string[];
31
+ }
32
+ interface ResolveTargetResult {
33
+ /** Best exact match from `candidates` (case-insensitive), or trusted input when no candidates were supplied. */
34
+ exact: string | null;
35
+ /** All candidates that include the input as a substring (case-insensitive). Includes `exact` if matched. */
36
+ matches: string[];
37
+ /** True when no candidates matched at all. */
38
+ unresolved: boolean;
39
+ }
40
+ declare function resolveTarget(opts: ResolveTargetInput): ResolveTargetResult;
41
+ interface RunReportOptions<P extends ReportParams = ReportParams> {
42
+ source: AnalysisQuerySource;
43
+ analyzers: AnalyzerRegistry;
44
+ ctx: ReportContext<P>;
45
+ }
46
+ /**
47
+ * `Result`-returning core for {@link runReport}. Models the one
48
+ * caller-actionable failure of a structurally-valid report run: a required
49
+ * step's analyzer threw (`required-step-failed`, with the underlying error as
50
+ * `cause`). Hosts can map that to a 4xx/partial response instead of catching an
51
+ * untyped `Error`.
52
+ *
53
+ * Steps execute in parallel via `Promise.all`. The report's `reduce` is invoked
54
+ * with a results bag that only contains successful steps — sections that
55
+ * depended on a failed step should set their own `coverage: 'partial'` (the
56
+ * runtime additionally marks `meta.degraded` when any step errored).
57
+ *
58
+ * The report's own `plan()` param-validation throws (`--target` etc.) are
59
+ * defects from this core's perspective and still propagate; those are modelled
60
+ * at the report-definition boundary, not here.
61
+ */
62
+ declare function runReportResult<P extends ReportParams = ReportParams>(report: DefinedReport<P>, opts: RunReportOptions<P>): Promise<Result<ReportResult, AnalysisError>>;
63
+ /**
64
+ * Throwing wrapper over {@link runReportResult}, preserving the historical
65
+ * call-site ergonomics (a required-step failure rejects). The thrown message is
66
+ * kept verbatim (`runReport(id): required step "k" failed: ...`) so existing
67
+ * assertions hold; the typed `AnalysisError` is reachable via `.analysisError`
68
+ * and the original failure via `.cause`.
69
+ */
70
+ declare function runReport<P extends ReportParams = ReportParams>(report: DefinedReport<P>, opts: RunReportOptions<P>): Promise<ReportResult>;
71
+ interface DryRunReportResult {
72
+ steps: {
73
+ key: string;
74
+ type: string;
75
+ estRowsScanned?: number;
76
+ }[];
77
+ windowResolved: {
78
+ start: string;
79
+ end: string;
80
+ days: number;
81
+ };
82
+ }
83
+ /**
84
+ * Plan-only preview. v1 doesn't compute row estimates — analyzer-level
85
+ * cost models don't exist yet — so `estRowsScanned` is left undefined.
86
+ * Useful right now only as an "is this report wired up correctly?" check.
87
+ */
88
+ declare function dryRunReport<P extends ReportParams = ReportParams>(report: DefinedReport<P>, ctx: ReportContext<P>): Promise<DryRunReportResult>;
89
+ export { DryRunReportResult, FormatReportOptions, REPORTS, ResolveTargetInput, ResolveTargetKind, ResolveTargetResult, RunReportOptions, defaultReportRegistry, dryRunReport, formatReport, resolveTarget, runReport, runReportResult };
@@ -0,0 +1,37 @@
1
+ import { BuilderState } from "gscdump/query";
2
+ import { AnalysisQuerySource, QueryRow } from "@gscdump/engine/source";
3
+ import { PlannerCapabilities } from "gscdump/query/plan";
4
+ interface SyncedRange {
5
+ oldestDateSynced: string | null;
6
+ newestDateSynced: string | null;
7
+ /**
8
+ * Optional sorted list of `[start, end]` daily-key spans (`YYYY-MM-DD`,
9
+ * both inclusive) that the engine actually has partitions for. When set,
10
+ * `shouldRouteToLive` returns true for any requested range that overlaps
11
+ * a day NOT inside one of these spans — even when the request sits inside
12
+ * `oldestDateSynced..newestDateSynced`. Lets the composite catch *internal*
13
+ * manifest gaps (e.g. a missing monthly tier) that the outer envelope
14
+ * doesn't reveal. Spans must be sorted by `start` and non-overlapping.
15
+ */
16
+ coveredSpans?: ReadonlyArray<{
17
+ start: string;
18
+ end: string;
19
+ }>;
20
+ }
21
+ interface CompositeSourceOptions {
22
+ engine: AnalysisQuerySource;
23
+ live: AnalysisQuerySource;
24
+ site: SyncedRange;
25
+ }
26
+ declare function createCompositeSource(opts: CompositeSourceOptions): AnalysisQuerySource;
27
+ /**
28
+ * Permissive defaults: in-memory sources are usually test doubles, so they
29
+ * advertise every capability unless the test explicitly narrows them.
30
+ */
31
+ declare const IN_MEMORY_DEFAULT_CAPABILITIES: PlannerCapabilities;
32
+ interface InMemoryQuerySourceOptions {
33
+ queryRows: (state: BuilderState) => Promise<QueryRow[]> | QueryRow[];
34
+ capabilities?: PlannerCapabilities;
35
+ }
36
+ declare function createInMemoryQuerySource(options: InMemoryQuerySourceOptions): AnalysisQuerySource;
37
+ export { CompositeSourceOptions, IN_MEMORY_DEFAULT_CAPABILITIES, InMemoryQuerySourceOptions, SyncedRange, createCompositeSource, createInMemoryQuerySource };